|
|
@@ -0,0 +1,162 @@
|
|
|
+package com.jeesite.modules.scheduling;
|
|
|
+
|
|
|
+import com.github.xingshuangs.iot.protocol.s7.enums.EPlcType;
|
|
|
+import com.github.xingshuangs.iot.protocol.s7.service.S7PLC;
|
|
|
+import com.jeesite.common.config.Global;
|
|
|
+import com.jeesite.common.lang.StringUtils;
|
|
|
+import com.jeesite.modules.mes.entity.MesSaw;
|
|
|
+import com.jeesite.modules.mes.service.MesSawService;
|
|
|
+import com.jeesite.modules.mes.service.MesDeviceAlarmService;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.context.annotation.Configuration;
|
|
|
+import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 半自动锯切站数据采集定时任务(S7 协议,DB28)
|
|
|
+ * @author system
|
|
|
+ * @version 2026-06-11
|
|
|
+ */
|
|
|
+@Configuration
|
|
|
+@EnableScheduling
|
|
|
+public class SawScheduling {
|
|
|
+
|
|
|
+ private static final Logger logger = LoggerFactory.getLogger(SawScheduling.class);
|
|
|
+
|
|
|
+ private static final String DEFAULT_PLC_IP = "10.0.20.120";
|
|
|
+ private static final String DEVICE_SN = "JQ_OP140_01";
|
|
|
+ private static final String STATE_PENDING = "0"; // 待处理
|
|
|
+ private static final String STATE_HANDLED = "1"; // 已处理
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MesSawService mesSawService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MesDeviceAlarmService mesDeviceAlarmService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 每 30 秒采集一次
|
|
|
+ */
|
|
|
+// @Scheduled(fixedRate = 30000)
|
|
|
+ public void collect() {
|
|
|
+ String enabled = Global.getConfig("mes.saw.enabled");
|
|
|
+ if (StringUtils.isNotBlank(enabled) && !"true".equalsIgnoreCase(enabled.trim())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String ip = Global.getConfig("mes.saw.plc.ip");
|
|
|
+ if (StringUtils.isBlank(ip)) {
|
|
|
+ ip = DEFAULT_PLC_IP;
|
|
|
+ }
|
|
|
+
|
|
|
+ S7PLC s7PLC = null;
|
|
|
+ try {
|
|
|
+ s7PLC = new S7PLC(EPlcType.S1200, ip);
|
|
|
+
|
|
|
+ MesSaw e = new MesSaw();
|
|
|
+ // ===== UINT(DB28.0/2/4/6)=====
|
|
|
+ e.setSeq1Takt(String.valueOf(s7PLC.readUInt16("DB28.0")));
|
|
|
+ e.setSeq2Takt(String.valueOf(s7PLC.readUInt16("DB28.2")));
|
|
|
+ e.setSawSpeed(String.valueOf(s7PLC.readUInt16("DB28.4")));
|
|
|
+ e.setMillSpeed(String.valueOf(s7PLC.readUInt16("DB28.6")));
|
|
|
+
|
|
|
+ // ===== BOOL(DB28.8.x / 9.x / 10.x)=====
|
|
|
+ boolean servoAlarm = s7PLC.readBoolean("DB28.8.0");
|
|
|
+ boolean inverterFault = s7PLC.readBoolean("DB28.8.1");
|
|
|
+ boolean inverterOverload = s7PLC.readBoolean("DB28.8.2");
|
|
|
+ boolean oilMistLow = s7PLC.readBoolean("DB28.8.3");
|
|
|
+ boolean chipConveyorTrip = s7PLC.readBoolean("DB28.8.4");
|
|
|
+ boolean hydraulicTrip = s7PLC.readBoolean("DB28.8.5");
|
|
|
+ boolean waterCoolerStop = s7PLC.readBoolean("DB28.8.6");
|
|
|
+ boolean manualCameraAlarm = s7PLC.readBoolean("DB28.8.7");
|
|
|
+ boolean sawCameraAlarm = s7PLC.readBoolean("DB28.9.0");
|
|
|
+ boolean cyl1Retract = s7PLC.readBoolean("DB28.9.1");
|
|
|
+ boolean cyl1Extend = s7PLC.readBoolean("DB28.9.2");
|
|
|
+ boolean cyl2Retract = s7PLC.readBoolean("DB28.9.3");
|
|
|
+ boolean cyl2Extend = s7PLC.readBoolean("DB28.9.4");
|
|
|
+ boolean cyl3Retract = s7PLC.readBoolean("DB28.9.5");
|
|
|
+ boolean cyl3Extend = s7PLC.readBoolean("DB28.9.6");
|
|
|
+ boolean cyl4Retract = s7PLC.readBoolean("DB28.9.7");
|
|
|
+ boolean cyl4Extend = s7PLC.readBoolean("DB28.10.0");
|
|
|
+ boolean estopCabinet = s7PLC.readBoolean("DB28.10.1");
|
|
|
+ boolean estopManual = s7PLC.readBoolean("DB28.10.2");
|
|
|
+ boolean spindleSpeedAlarm = s7PLC.readBoolean("DB28.10.3");
|
|
|
+
|
|
|
+// e.setServoAlarm(bs(servoAlarm));
|
|
|
+// e.setInverterFault(bs(inverterFault));
|
|
|
+// e.setInverterOverload(bs(inverterOverload));
|
|
|
+// e.setOilMistLow(bs(oilMistLow));
|
|
|
+// e.setChipConveyorTrip(bs(chipConveyorTrip));
|
|
|
+// e.setHydraulicTrip(bs(hydraulicTrip));
|
|
|
+// e.setWaterCoolerStop(bs(waterCoolerStop));
|
|
|
+// e.setManualCameraAlarm(bs(manualCameraAlarm));
|
|
|
+// e.setSawCameraAlarm(bs(sawCameraAlarm));
|
|
|
+// e.setCyl1RetractFault(bs(cyl1Retract));
|
|
|
+// e.setCyl1ExtendFault(bs(cyl1Extend));
|
|
|
+// e.setCyl2RetractFault(bs(cyl2Retract));
|
|
|
+// e.setCyl2ExtendFault(bs(cyl2Extend));
|
|
|
+// e.setCyl3RetractFault(bs(cyl3Retract));
|
|
|
+// e.setCyl3ExtendFault(bs(cyl3Extend));
|
|
|
+// e.setCyl4RetractFault(bs(cyl4Retract));
|
|
|
+// e.setCyl4ExtendFault(bs(cyl4Extend));
|
|
|
+// e.setEstopCabinet(bs(estopCabinet));
|
|
|
+// e.setEstopManual(bs(estopManual));
|
|
|
+// e.setSpindleSpeedAlarm(bs(spindleSpeedAlarm));
|
|
|
+//
|
|
|
+ mesSawService.save(e);
|
|
|
+
|
|
|
+ // ===== 报警联动:True->待处理(0),False->已处理(1) =====
|
|
|
+ // 报警类型名称需与 mes_device_alarm 表中 type 一致
|
|
|
+ updateAlarm("伺服报警", servoAlarm);
|
|
|
+ updateAlarm("变频器异常(A1/C1)", inverterFault);
|
|
|
+ updateAlarm("变频器过负载OL", inverterOverload);
|
|
|
+ updateAlarm("油雾器液位低", oilMistLow);
|
|
|
+ updateAlarm("排屑机跳匝", chipConveyorTrip);
|
|
|
+ updateAlarm("液压站跳匝", hydraulicTrip);
|
|
|
+ updateAlarm("水冷机停止中", waterCoolerStop);
|
|
|
+ updateAlarm("人工位安全相机检测报警", manualCameraAlarm);
|
|
|
+ updateAlarm("锯切站内安全相机检测报警", sawCameraAlarm);
|
|
|
+ updateAlarm("转台定位气缸1缩回检测故障", cyl1Retract);
|
|
|
+ updateAlarm("转台定位气缸1伸出检测故障", cyl1Extend);
|
|
|
+ updateAlarm("转台定位气缸2缩回检测故障", cyl2Retract);
|
|
|
+ updateAlarm("转台定位气缸2伸出检测故障", cyl2Extend);
|
|
|
+ updateAlarm("转台定位气缸3缩回检测故障", cyl3Retract);
|
|
|
+ updateAlarm("转台定位气缸3伸出检测故障", cyl3Extend);
|
|
|
+ updateAlarm("转台定位气缸4缩回检测故障", cyl4Retract);
|
|
|
+ updateAlarm("转台定位气缸4伸出检测故障", cyl4Extend);
|
|
|
+ updateAlarm("急停(电柜上)", estopCabinet);
|
|
|
+ updateAlarm("人工位急停", estopManual);
|
|
|
+ updateAlarm("主轴转速未达到报警", spindleSpeedAlarm);
|
|
|
+
|
|
|
+ logger.info("锯切数据采集成功[{}] 一序节拍:{} 二序节拍:{} 锯切转速:{} 铣削转速:{}",
|
|
|
+ ip, e.getSeq1Takt(), e.getSeq2Takt(), e.getSawSpeed(), e.getMillSpeed());
|
|
|
+ } catch (Exception ex) {
|
|
|
+ logger.error("锯切数据采集失败[{}]:{}", ip, ex.getMessage());
|
|
|
+ } finally {
|
|
|
+ if (s7PLC != null) {
|
|
|
+ try {
|
|
|
+ s7PLC.close();
|
|
|
+ } catch (Exception ignore) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /** boolean 转存储字符串:true->1,false->0 */
|
|
|
+ private String bs(boolean b) {
|
|
|
+ return b ? "1" : "0";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 报警联动:信号为 true 时置待处理(0),false 时置已处理(1)
|
|
|
+ */
|
|
|
+ private void updateAlarm(String type, boolean alarmOn) {
|
|
|
+ try {
|
|
|
+ mesDeviceAlarmService.updateStateByDeviceSnAndType(
|
|
|
+ DEVICE_SN, type, alarmOn ? STATE_PENDING : STATE_HANDLED);
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.warn("更新报警[{}-{}]状态失败:{}", DEVICE_SN, type, e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|