dzc 3 tygodni temu
rodzic
commit
2a3c862e30

+ 4 - 4
pom.xml

@@ -23,7 +23,7 @@
         <maven.compiler.target>1.8</maven.compiler.target>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
         <fastjson2.version>2.0.16</fastjson2.version>
-        <jSerialComm.version>2.6.2</jSerialComm.version>
+        <iot.communication.version>1.4.4</iot.communication.version>
     </properties>
 
     <dependencies>
@@ -37,9 +37,9 @@
             <version>${fastjson2.version}</version>
         </dependency>
         <dependency>
-            <groupId>com.fazecast</groupId>
-            <artifactId>jSerialComm</artifactId>
-            <version>${jSerialComm.version}</version>
+            <groupId>com.github.xingshuangs</groupId>
+            <artifactId>iot-communication</artifactId>
+            <version>${iot.communication.version}</version>
         </dependency>
     </dependencies>
 

+ 25 - 65
src/main/java/com/mes/config/MesClientProperties.java

@@ -28,7 +28,7 @@ public class MesClientProperties {
 	/** 本机工位列表(一拖多) */
 	private List<StationConfig> stations = new ArrayList<StationConfig>();
 
-	/** 单工位:编码 + Modbus 串口 */
+	/** 单工位:编码 + S7 PLC */
 	public static class StationConfig {
 		/** 工位序号(界面/日志用) */
 		private int id;
@@ -36,22 +36,14 @@ public class MesClientProperties {
 		private String stationSn = "";
 		/** Tab/面板显示标题 */
 		private String title = "";
-		/** 是否启用焊机串口通讯 */
-		private boolean welderEnabled = true;
-		/** 焊机串口名,如 COM3 */
-		private String welderPort = "COM3";
-		/** 波特率 */
-		private int welderBaud = 9600;
-		/** 数据位 */
-		private int welderDatabits = 8;
-		/** 停止位 */
-		private int welderStopbits = 1;
-		/** 校验位:EVEN/ODD/NONE */
-		private String welderParity = "EVEN";
-		/** Modbus 从站号 */
-		private int welderSlaveId = 1;
-		/** 串口读写超时(毫秒) */
-		private int welderTimeoutMs = 1000;
+		/** 是否启用 PLC 通讯 */
+		private boolean plcEnabled = true;
+		/** PLC IP,如 192.168.0.10 */
+		private String plcIp = "192.168.0.10";
+		/** PLC 型号:S1200 / S1500 / S200_SMART 等 */
+		private String plcType = "S1200";
+		/** PLC 读写超时(毫秒) */
+		private int plcTimeoutMs = 3000;
 
 		public int getId() {
 			return id;
@@ -77,68 +69,36 @@ public class MesClientProperties {
 			this.title = title;
 		}
 
-		public boolean isWelderEnabled() {
-			return welderEnabled;
+		public boolean isPlcEnabled() {
+			return plcEnabled;
 		}
 
-		public void setWelderEnabled(boolean welderEnabled) {
-			this.welderEnabled = welderEnabled;
+		public void setPlcEnabled(boolean plcEnabled) {
+			this.plcEnabled = plcEnabled;
 		}
 
-		public String getWelderPort() {
-			return welderPort;
+		public String getPlcIp() {
+			return plcIp;
 		}
 
-		public void setWelderPort(String welderPort) {
-			this.welderPort = welderPort;
+		public void setPlcIp(String plcIp) {
+			this.plcIp = plcIp;
 		}
 
-		public int getWelderBaud() {
-			return welderBaud;
+		public String getPlcType() {
+			return plcType;
 		}
 
-		public void setWelderBaud(int welderBaud) {
-			this.welderBaud = welderBaud;
+		public void setPlcType(String plcType) {
+			this.plcType = plcType;
 		}
 
-		public int getWelderDatabits() {
-			return welderDatabits;
+		public int getPlcTimeoutMs() {
+			return plcTimeoutMs;
 		}
 
-		public void setWelderDatabits(int welderDatabits) {
-			this.welderDatabits = welderDatabits;
-		}
-
-		public int getWelderStopbits() {
-			return welderStopbits;
-		}
-
-		public void setWelderStopbits(int welderStopbits) {
-			this.welderStopbits = welderStopbits;
-		}
-
-		public String getWelderParity() {
-			return welderParity;
-		}
-
-		public void setWelderParity(String welderParity) {
-			this.welderParity = welderParity;
-		}
-
-		public int getWelderSlaveId() {
-			return welderSlaveId;
-		}
-
-		public void setWelderSlaveId(int welderSlaveId) {
-			this.welderSlaveId = welderSlaveId;
-		}
-
-		public int getWelderTimeoutMs() {
-			return welderTimeoutMs;
-		}
-
-		public void setWelderTimeoutMs(int welderTimeoutMs) {
-			this.welderTimeoutMs = welderTimeoutMs;
+		public void setPlcTimeoutMs(int plcTimeoutMs) {
+			this.plcTimeoutMs = plcTimeoutMs;
 		}
 	}
 

+ 31 - 6
src/main/java/com/mes/entity/WeldParams.java

@@ -1,23 +1,48 @@
 package com.mes.entity;
 
 /**
- * 凸焊过程参数采样点(对齐 mesFlexHg upload 字段名)。
+ * 凸焊过程参数采样点(对齐 mesFlexHg upload 字段名 + DB37 扩展回显)。
  */
 public class WeldParams {
 	/** 采样时刻 yyyy-MM-dd HH:mm:ss */
 	public String sampleTime = "";
-	/** 焊接电压 */
+	/** 兼容字段:焊1电流 */
 	public String voltage = "";
-	/** 焊接电流 */
+	/** 兼容字段:焊1/2/3电流 */
 	public String currentVal = "";
-	/** 映射加压时间 */
+	/** 兼容字段:焊1/2/3时间 */
 	public String wireSpeed = "";
-	/** 映射修模状态 */
+	/** 兼容字段:电极修模/更换摘要 */
 	public String side = "";
-	/** 规范号 / 程序号 */
+	/** 兼容字段:生产量 */
 	public String jobNo = "";
 	/** 报警或通讯错误文案 */
 	public String errorCode = "";
 	/** 设备类型,如「凸焊」 */
 	public String deviceType = "";
+
+	/** 设备状态正常 */
+	public boolean deviceOk;
+	/** MES允许运行 */
+	public boolean mesAllowRun;
+	/** MES屏蔽 */
+	public boolean mesShield;
+	/** 运行开始 */
+	public boolean runStart;
+	/** 运行结束 */
+	public boolean runEnd;
+
+	public int upperElectrodeDressCount;
+	public int lowerElectrodeDressCount;
+	public int upperElectrodeReplaceCount;
+	public int lowerElectrodeReplaceCount;
+	public int productionCount;
+	public int finishedCount;
+
+	public int weld1Current;
+	public int weld1Time;
+	public int weld2Current;
+	public int weld2Time;
+	public int weld3Current;
+	public int weld3Time;
 }

+ 0 - 151
src/main/java/com/mes/service/TuHanModbusClient.java

@@ -1,151 +0,0 @@
-package com.mes.service;
-
-import com.mes.config.MesClientProperties;
-import com.mes.entity.WeldParams;
-import com.mes.util.DateTimeUtils;
-import com.mes.util.ModbusRtuClient;
-import com.mes.util.TuHanModbusConfig;
-import com.mes.util.TuHanParamData;
-import com.mes.util.TuHanParamReader;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * 凸焊(TuHan)站设备层:FCN 焊机 Modbus RTU。
- * <p>
- * 对外:连接、是否运行、读过程参数快照。无 L180 进站位,
- * {@link #setMesAllowEntry} 为空操作。
- * </p>
- */
-public class TuHanModbusClient {
-
-	/** 日志 */
-	private static final Logger log = LoggerFactory.getLogger(TuHanModbusClient.class);
-
-	/** 本工位编码 */
-	private final String stationSn;
-	/** 串口/从站等 Modbus 配置 */
-	private final TuHanModbusConfig config;
-	/** RTU 串口客户端 */
-	private ModbusRtuClient client;
-	/** 寄存器读参器 */
-	private TuHanParamReader reader;
-	/** 串口是否已连通并可读参 */
-	private volatile boolean connected;
-	/** 最近一次读到的参数快照 */
-	private volatile TuHanParamData lastData;
-
-	public TuHanModbusClient(MesClientProperties.StationConfig station) {
-		this.stationSn = station == null || station.getStationSn() == null
-				? "" : station.getStationSn().trim();
-		this.config = TuHanModbusConfig.fromStation(station);
-	}
-
-	public String getStationSn() {
-		return stationSn;
-	}
-
-	public String getPortDesc() {
-		return config.port + " / 站号" + config.slaveId;
-	}
-
-	public boolean isConnected() {
-		return connected && client != null && client.isOpen();
-	}
-
-	/** 打开串口并就绪读参 */
-	public synchronized void connect() {
-		if (!config.enabled) {
-			connected = false;
-			log.warn("工位[{}] 凸焊通讯未启用(welder-enabled=false)", stationSn);
-			return;
-		}
-		try {
-			if (client != null) {
-				client.close();
-			}
-			client = new ModbusRtuClient();
-			reader = new TuHanParamReader(client);
-			if (!client.open(config)) {
-				connected = false;
-				log.warn("工位[{}] 打开串口失败 {}", stationSn, config.port);
-				return;
-			}
-			TuHanParamData probe = reader.read();
-			lastData = probe;
-			connected = probe != null && probe.connected;
-			if (connected) {
-				log.info("工位[{}] TuHan Modbus 已连接 {}", stationSn, getPortDesc());
-			} else {
-				log.warn("工位[{}] TuHan Modbus 已开串口但读参失败: {}", stationSn,
-						probe == null ? "" : probe.errorMessage);
-			}
-		} catch (Exception e) {
-			connected = false;
-			log.warn("工位[{}] TuHan Modbus 连接异常: {}", stationSn, e.getMessage());
-		}
-	}
-
-	public synchronized void close() {
-		if (client != null) {
-			client.close();
-		}
-		client = null;
-		reader = null;
-		connected = false;
-	}
-
-	/** 凸焊无 PLC 进站位,保留接口避免面板分支 */
-	public boolean setMesAllowEntry(boolean allow) {
-		return true;
-	}
-
-	/** 焊机运行中(状态字「运行」) */
-	public boolean isDeviceRunning() {
-		TuHanParamData d = readRaw();
-		return d != null && d.connected && "运行".equals(nvl(d.runState));
-	}
-
-	public boolean isRunning() {
-		return isDeviceRunning();
-	}
-
-	public TuHanParamData readRaw() {
-		if (reader == null) {
-			return TuHanParamData.disconnected("未连接");
-		}
-		TuHanParamData d = reader.read();
-		lastData = d;
-		connected = d != null && d.connected;
-		return d;
-	}
-
-	public TuHanParamData getLastData() {
-		return lastData;
-	}
-
-	/**
-	 * 映射为柔性 upload 过程参数;凸焊量写入 voltage/current/wireSpeed(加压时间)/side(修模) 等。
-	 */
-	public WeldParams readWeldParams() {
-		TuHanParamData d = readRaw();
-		WeldParams wp = new WeldParams();
-		wp.sampleTime = DateTimeUtils.getCurrentTime();
-		if (d == null || !d.connected) {
-			wp.errorCode = d == null ? "未连接" : nvl(d.errorMessage);
-			return wp;
-		}
-		wp.voltage = String.valueOf(d.weldVoltage);
-		wp.currentVal = nvl(d.weldPeakCurrent).replace(" KA", "").trim();
-		wp.wireSpeed = String.valueOf(d.pressTime);
-		wp.side = nvl(d.toolingState);
-		wp.jobNo = String.valueOf(d.specNo);
-		wp.errorCode = nvl(d.alarmText);
-		wp.deviceType = "凸焊";
-		return wp;
-	}
-
-	private static String nvl(String s) {
-		return s == null ? "" : s.trim();
-	}
-}

+ 210 - 0
src/main/java/com/mes/service/TuHanPlcClient.java

@@ -0,0 +1,210 @@
+package com.mes.service;
+
+import com.github.xingshuangs.iot.protocol.s7.enums.EPlcType;
+import com.github.xingshuangs.iot.protocol.s7.service.S7PLC;
+import com.mes.config.MesClientProperties;
+import com.mes.entity.WeldParams;
+import com.mes.util.DateTimeUtils;
+import com.mes.util.TuHanParamData;
+import com.mes.util.TuHanPlcConfig;
+import com.mes.util.TuHanPlcReader;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * 凸焊(TuHan)站设备层:S7 读 DB37 点位,写 MES允许运行。
+ */
+public class TuHanPlcClient {
+
+	private static final Logger log = LoggerFactory.getLogger(TuHanPlcClient.class);
+
+	private final String stationSn;
+	private final TuHanPlcConfig config;
+	private S7PLC plc;
+	private TuHanPlcReader reader;
+	private volatile boolean connected;
+	private volatile TuHanParamData lastData;
+
+	public TuHanPlcClient(MesClientProperties.StationConfig station) {
+		this.stationSn = station == null || station.getStationSn() == null
+				? "" : station.getStationSn().trim();
+		this.config = TuHanPlcConfig.fromStation(station);
+	}
+
+	public String getStationSn() {
+		return stationSn;
+	}
+
+	public String getPortDesc() {
+		return config.ip + " / " + config.plcType;
+	}
+
+	public boolean isConnected() {
+		return connected && plc != null && reader != null;
+	}
+
+	public synchronized void connect() {
+		if (!config.enabled) {
+			connected = false;
+			log.warn("工位[{}] PLC 通讯未启用(plc-enabled=false)", stationSn);
+			return;
+		}
+		try {
+			closeQuietly();
+			EPlcType type = resolvePlcType(config.plcType);
+			plc = new S7PLC(type, config.ip);
+			reader = new TuHanPlcReader(plc);
+			TuHanParamData probe = reader.read();
+			lastData = probe;
+			connected = probe != null && probe.connected;
+			if (connected) {
+				log.info("工位[{}] TuHan S7 已连接 {}", stationSn, getPortDesc());
+			} else {
+				log.warn("工位[{}] TuHan S7 已建连但读参失败: {}", stationSn,
+						probe == null ? "" : probe.errorMessage);
+			}
+		} catch (Exception e) {
+			connected = false;
+			log.warn("工位[{}] TuHan S7 连接异常: {}", stationSn, e.getMessage());
+		}
+	}
+
+	public synchronized void close() {
+		closeQuietly();
+		connected = false;
+	}
+
+	private void closeQuietly() {
+		try {
+			if (plc != null) {
+				plc.close();
+			}
+		} catch (Exception ignore) {
+			// ignore
+		}
+		plc = null;
+		reader = null;
+	}
+
+	/**
+	 * 写 MES允许运行(DB37.DBX0.0)。
+	 * 取码成功后置 true,进入运行/清码/过站后置 false。
+	 */
+	public boolean setMesAllowEntry(boolean allow) {
+		if (reader == null) {
+			return false;
+		}
+		boolean ok = reader.writeMesAllow(allow);
+		if (ok) {
+			log.info("工位[{}] MES允许运行={}", stationSn, allow);
+		}
+		return ok;
+	}
+
+	/** 运行开始状态(DB37.DBX0.2) */
+	public boolean isDeviceRunning() {
+		TuHanParamData d = readRaw();
+		return d != null && d.connected && d.runStart;
+	}
+
+	public boolean isRunning() {
+		return isDeviceRunning();
+	}
+
+	/** 运行结束状态(DB37.DBX0.3) */
+	public boolean isRunEnded() {
+		TuHanParamData d = lastData;
+		if (d == null || !d.connected) {
+			d = readRaw();
+		}
+		return d != null && d.connected && d.runEnd;
+	}
+
+	public boolean isMesShield() {
+		TuHanParamData d = lastData;
+		return d != null && d.connected && d.mesShield;
+	}
+
+	public TuHanParamData readRaw() {
+		if (reader == null) {
+			return TuHanParamData.disconnected("未连接");
+		}
+		TuHanParamData d = reader.read();
+		lastData = d;
+		connected = d != null && d.connected;
+		return d;
+	}
+
+	public TuHanParamData getLastData() {
+		return lastData;
+	}
+
+	/**
+	 * 映射为柔性 upload 过程参数;焊接量写入 voltage/current/wireSpeed,电极计数写入 side/jobNo。
+	 */
+	public WeldParams readWeldParams() {
+		TuHanParamData d = readRaw();
+		WeldParams wp = new WeldParams();
+		wp.sampleTime = DateTimeUtils.getCurrentTime();
+		if (d == null || !d.connected) {
+			wp.errorCode = d == null ? "未连接" : nvl(d.errorMessage);
+			return wp;
+		}
+		wp.deviceOk = d.deviceOk;
+		wp.mesAllowRun = d.mesAllowRun;
+		wp.mesShield = d.mesShield;
+		wp.runStart = d.runStart;
+		wp.runEnd = d.runEnd;
+		wp.upperElectrodeDressCount = d.upperElectrodeDressCount;
+		wp.lowerElectrodeDressCount = d.lowerElectrodeDressCount;
+		wp.upperElectrodeReplaceCount = d.upperElectrodeReplaceCount;
+		wp.lowerElectrodeReplaceCount = d.lowerElectrodeReplaceCount;
+		wp.productionCount = d.productionCount;
+		wp.finishedCount = d.finishedCount;
+		wp.weld1Current = d.weld1Current;
+		wp.weld1Time = d.weld1Time;
+		wp.weld2Current = d.weld2Current;
+		wp.weld2Time = d.weld2Time;
+		wp.weld3Current = d.weld3Current;
+		wp.weld3Time = d.weld3Time;
+
+		// 兼容 mesFlexHg 既有字段:电流/时间用焊1为主,附加焊2/3 拼到 wireSpeed
+		wp.voltage = String.valueOf(d.weld1Current);
+		wp.currentVal = d.weld1Current + "/" + d.weld2Current + "/" + d.weld3Current;
+		wp.wireSpeed = d.weld1Time + "/" + d.weld2Time + "/" + d.weld3Time;
+		wp.side = "上修" + d.upperElectrodeDressCount + "/下修" + d.lowerElectrodeDressCount
+				+ "/上换" + d.upperElectrodeReplaceCount + "/下换" + d.lowerElectrodeReplaceCount;
+		wp.jobNo = String.valueOf(d.productionCount);
+		wp.errorCode = d.deviceOk ? (d.mesShield ? "MES屏蔽" : "") : "设备报警";
+		wp.deviceType = "凸焊";
+		return wp;
+	}
+
+	private static EPlcType resolvePlcType(String name) {
+		if (name == null || name.trim().isEmpty()) {
+			return EPlcType.S1200;
+		}
+		String n = name.trim().toUpperCase().replace('-', '_');
+		try {
+			return EPlcType.valueOf(n);
+		} catch (Exception e) {
+			if (n.contains("1500")) {
+				return EPlcType.S1500;
+			}
+			if (n.contains("300")) {
+				return EPlcType.S300;
+			}
+			if (n.contains("400")) {
+				return EPlcType.S400;
+			}
+			if (n.contains("200")) {
+				return EPlcType.S200_SMART;
+			}
+			return EPlcType.S1200;
+		}
+	}
+
+	private static String nvl(String s) {
+		return s == null ? "" : s.trim();
+	}
+}

+ 3 - 3
src/main/java/com/mes/ui/MainFrame.java

@@ -112,7 +112,7 @@ public class MainFrame extends JFrame {
 								}
 							}
 						}
-					}, "tuhan-modbus-init").start();
+					}, "tuhan-plc-init").start();
 				} catch (Exception e) {
 					log.error("启动主界面失败", e);
 					e.printStackTrace();
@@ -156,8 +156,8 @@ public class MainFrame extends JFrame {
 		} else {
 			log.info("加载工位数={} upload={} profile={}", list.size(), mes_upload_path, mes_param_profile);
 			for (MesClientProperties.StationConfig s : list) {
-				log.info("工位 id={} sn={} port={} slave={}", s.getId(), s.getStationSn(),
-					s.getWelderPort(), s.getWelderSlaveId());
+				log.info("工位 id={} sn={} plc={}/{}", s.getId(), s.getStationSn(),
+					s.getPlcIp(), s.getPlcType());
 			}
 		}
 	}

+ 105 - 124
src/main/java/com/mes/ui/StationPanel.java

@@ -4,8 +4,9 @@ import com.alibaba.fastjson2.JSONArray;
 import com.alibaba.fastjson2.JSONObject;
 import com.mes.config.MesClientProperties;
 import com.mes.entity.WeldParams;
-import com.mes.service.TuHanModbusClient;
 import com.mes.service.MesFlexApiClient;
+import com.mes.service.TuHanPlcClient;
+import com.mes.util.TuHanParamData;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -22,95 +23,61 @@ import java.util.Map;
 import java.util.concurrent.atomic.AtomicBoolean;
 
 /**
- * 凸焊工位面板:柔性取码队列 + Modbus 读参。
+ * 凸焊工位面板:柔性取码队列 + S7 DB37。
  * <p>
- * 取码 → 等焊机「运行」→ 每秒采参 → 运行结束 → uploadAndSubmit。
+ * 对齐 RealHuHan:MES允许/屏蔽/开始/结束仅作握手逻辑,页面只回显生产过程参数。
+ * 取码 → 写允许运行 → 等运行开始 → 每秒采参 → 运行结束 → uploadAndSubmit。
  * </p>
  */
 public class StationPanel extends JPanel {
 
-	/** 日志 */
 	private static final Logger log = LoggerFactory.getLogger(StationPanel.class);
 
-	/** 运行中采参最小间隔(毫秒),默认 1 秒一条 */
 	private static final long SAMPLE_INTERVAL_MS = 1000L;
 
-	/**
-	 * 本工位业务阶段:
-	 * IDLE=空闲可取码;HOLD=已取码等焊机运行;RUN=焊接中采参;UPLOAD=正在上传过站。
-	 */
 	public enum Phase {
 		IDLE, HOLD, RUN, UPLOAD
 	}
 
-	/** 本工位 yml 配置(工位编码、串口、标题等) */
 	private final MesClientProperties.StationConfig cfg;
-	/** 凸焊 Modbus 客户端:连串口、读运行状态与过程参数 */
-	private final TuHanModbusClient device;
-	/** MES 服务 IP(拼 HTTP 地址用) */
+	private final TuHanPlcClient device;
 	private final String serverIp;
-	/** 报工人工号;空则用 system(部分校验放行,过站仍按服务端规则) */
 	private final String userCode;
 
-	/** 当前业务阶段(多线程可见,故 volatile) */
 	private volatile Phase phase = Phase.IDLE;
-	/** 当前加工工件码;空表示本机还没有码 */
 	private volatile String currentSn = "";
-	/** 本件焊接面标识(凸焊现固定/写入 TUHAN 一类值,历史上来自 A/B 面) */
 	private volatile String activeSide = "";
-	/** 本件是否已经进入过「运行中」;用来判断「曾运行过又停下=焊接结束」 */
 	private volatile boolean seenRunning;
-	/** 上次采参时间戳(毫秒),配合 SAMPLE_INTERVAL_MS 做节流 */
 	private volatile long lastSampleAtMs;
-	/**
-	 * 运行中采到的参数列表;焊完后一次性 uploadAndSubmit,不在循环里逐条打库。
-	 * 主要由 tick / 上传线程访问。
-	 */
 	private final List<WeldParams> sampleBuffer = new ArrayList<WeldParams>();
-	/**
-	 * 异步忙锁:取码/清码/上传进行中为 true。
-	 * true 时 tick 直接跳过,并挡住重复点击。
-	 */
 	private final AtomicBoolean busy = new AtomicBoolean(false);
 
-	/** 顶栏:工位名称 */
 	private final JLabel lblStation;
-	/** 顶栏:焊机串口连接状态文案 */
 	private final JLabel lblPlc;
-	/** 顶栏:与 MES 的 SSE 心跳灯(绿=已连,红=断开) */
 	private final BreathingLight serverHeartbeat;
-	/** 当前工件码显示框(只读) */
 	private final JTextField txtSn;
-	/** 状态提示条(空闲/运行中/失败原因等) */
 	private final JLabel lblStatus;
-	/** 过程参数:焊接电压 */
-	private final JTextField txtVoltage;
-	/** 过程参数:电流 */
-	private final JTextField txtCurrent;
-	/** 过程参数:加压时间(字段名沿用 wire,映射凸焊量) */
-	private final JTextField txtWire;
-	/** 过程参数:修模状态等(字段名沿用 side) */
-	private final JTextField txtSide;
-	/** 过程参数:JOB 号 */
-	private final JTextField txtJobNo;
-	/** 过程参数:错误码 */
-	private final JTextField txtErrorCode;
-	/** 过程参数:设备类型展示 */
-	private final JTextField txtDeviceType;
-	/** 按钮:向 MES 取下一个工件码 */
+
+	/** 生产过程参数回显(对齐 RealHuHan:只展示采参量,不展示握手点位) */
+	private final JTextField txtWeld1Current;
+	private final JTextField txtWeld1Time;
+	private final JTextField txtWeld2Current;
+	private final JTextField txtWeld2Time;
+	private final JTextField txtWeld3Current;
+	private final JTextField txtWeld3Time;
+	private final JTextField txtProduction;
+	private final JTextField txtFinished;
+
 	private final JButton btnNext;
-	/** 按钮:调服务端清码并复位本机 */
 	private final JButton btnClear;
-	/** 按钮:仅复位本机界面,不调服务端清码 */
 	private final JButton btnReset;
-	/** 按钮:异常时强制把已采集合上传并过站 */
 	private final JButton btnForceUpload;
 
 	public StationPanel(MesClientProperties.StationConfig cfg, String serverIp, String userCode) {
 		this.cfg = cfg;
 		this.serverIp = serverIp == null ? "" : serverIp.trim();
 		this.userCode = (userCode == null || userCode.trim().isEmpty()) ? "system" : userCode.trim();
-		this.device = new TuHanModbusClient(cfg);
+		this.device = new TuHanPlcClient(cfg);
 
 		setLayout(new BorderLayout(0, 0));
 		setBackground(UiTheme.BG);
@@ -135,7 +102,7 @@ public class StationPanel extends JPanel {
 		titleCol.add(lblStation);
 		titleCol.add(Box.createVerticalStrut(3));
 		titleCol.add(lblCode);
-		lblPlc = new JLabel("焊机 " + device.getPortDesc() + "  ·  未连接");
+		lblPlc = new JLabel("PLC " + device.getPortDesc() + "  ·  未连接");
 		lblPlc.setFont(UiTheme.FONT_BODY);
 		UiTheme.stylePlcPill(lblPlc, false);
 		serverHeartbeat = new BreathingLight();
@@ -188,26 +155,27 @@ public class StationPanel extends JPanel {
 
 		JPanel paramCard = UiTheme.card();
 		paramCard.setLayout(new BorderLayout(0, 12));
-		paramCard.add(UiTheme.sectionTitle("凸焊过程参数(运行中每秒刷新,结束后集合上传)"), BorderLayout.NORTH);
+		paramCard.add(UiTheme.sectionTitle("过程参数(运行中每秒刷新,结束后集合上传)"), BorderLayout.NORTH);
 		JPanel paramGrid = new JPanel(new GridLayout(4, 2, 12, 12));
 		paramGrid.setOpaque(false);
-		txtVoltage = UiTheme.valueField();
-		txtCurrent = UiTheme.valueField();
-		txtWire = UiTheme.valueField();
-		txtSide = UiTheme.valueField();
-		txtJobNo = UiTheme.valueField();
-		txtErrorCode = UiTheme.valueField();
-		txtDeviceType = UiTheme.valueField();
-		paramGrid.add(UiTheme.paramTile("焊接电压", txtVoltage, UiTheme.STRIPE_VOLT));
-		paramGrid.add(UiTheme.paramTile("电流", txtCurrent, UiTheme.STRIPE_AMP));
-		paramGrid.add(UiTheme.paramTile("加压时间", txtWire, UiTheme.STRIPE_WIRE));
-		paramGrid.add(UiTheme.paramTile("修模状态", txtSide, UiTheme.STRIPE_SIDE));
-		paramGrid.add(UiTheme.paramTile("JOB号", txtJobNo, UiTheme.STRIPE_JOB));
-		paramGrid.add(UiTheme.paramTile("错误代码", txtErrorCode, UiTheme.STRIPE_ERR));
-		paramGrid.add(UiTheme.paramTile("设备", txtDeviceType, UiTheme.STRIPE_DEV));
-		JPanel filler = new JPanel();
-		filler.setOpaque(false);
-		paramGrid.add(filler);
+
+		txtWeld1Current = UiTheme.valueField();
+		txtWeld1Time = UiTheme.valueField();
+		txtWeld2Current = UiTheme.valueField();
+		txtWeld2Time = UiTheme.valueField();
+		txtWeld3Current = UiTheme.valueField();
+		txtWeld3Time = UiTheme.valueField();
+		txtProduction = UiTheme.valueField();
+		txtFinished = UiTheme.valueField();
+
+		paramGrid.add(UiTheme.paramTile("焊1电流", txtWeld1Current, UiTheme.STRIPE_AMP));
+		paramGrid.add(UiTheme.paramTile("焊1时间", txtWeld1Time, UiTheme.STRIPE_WIRE));
+		paramGrid.add(UiTheme.paramTile("焊2电流", txtWeld2Current, UiTheme.STRIPE_AMP));
+		paramGrid.add(UiTheme.paramTile("焊2时间", txtWeld2Time, UiTheme.STRIPE_WIRE));
+		paramGrid.add(UiTheme.paramTile("焊3电流", txtWeld3Current, UiTheme.STRIPE_AMP));
+		paramGrid.add(UiTheme.paramTile("焊3时间", txtWeld3Time, UiTheme.STRIPE_WIRE));
+		paramGrid.add(UiTheme.paramTile("生产量计数", txtProduction, UiTheme.STRIPE_JOB));
+		paramGrid.add(UiTheme.paramTile("成品产量计数", txtFinished, UiTheme.STRIPE_VOLT));
 		paramGrid.setPreferredSize(new Dimension(680, 320));
 		paramCard.add(paramGrid, BorderLayout.CENTER);
 
@@ -229,7 +197,7 @@ public class StationPanel extends JPanel {
 		actions.setBorder(BorderFactory.createCompoundBorder(
 				BorderFactory.createMatteBorder(3, 0, 0, 0, UiTheme.ACCENT),
 				new EmptyBorder(12, 16, 14, 16)));
-		JLabel tip = UiTheme.mutedLabel("取码后等焊机运行 → 运行中每秒采参 → 结束 uploadAndSubmit;扫错可清码");
+		JLabel tip = UiTheme.mutedLabel("取码写允许运行 → 等运行开始采参 → 运行结束 uploadAndSubmit;扫错可清码");
 		JPanel btns = new JPanel(new FlowLayout(FlowLayout.RIGHT, 10, 0));
 		btns.setOpaque(false);
 		btnReset = UiTheme.ghostBtn("复位");
@@ -237,6 +205,7 @@ public class StationPanel extends JPanel {
 		btnReset.addActionListener(new ActionListener() {
 			@Override
 			public void actionPerformed(ActionEvent e) {
+				device.setMesAllowEntry(false);
 				resetToIdle("已手动复位");
 			}
 		});
@@ -296,7 +265,6 @@ public class StationPanel extends JPanel {
 		return phase;
 	}
 
-	/** SSE / 兜底:空闲则取码(工位级,不分 A/B) */
 	public void tryAutoNextFromPush() {
 		if (phase != Phase.IDLE) {
 			log.debug("工位[{}] phase={} 忽略推送取码", cfg.getStationSn(), phase);
@@ -305,7 +273,6 @@ public class StationPanel extends JPanel {
 		requestNextAsync();
 	}
 
-	/** 兼容带工位参数的门铃(忽略面,只认本工位) */
 	public void tryAutoNextFromPush(String enqueueStationSn) {
 		if (!ownsStationSn(enqueueStationSn)) {
 			return;
@@ -313,10 +280,6 @@ public class StationPanel extends JPanel {
 		tryAutoNextFromPush();
 	}
 
-	/**
-	 * SSE 清码门铃:若本机正占用同一工件码,复位界面并关 L180。
-	 * 不匹配则忽略(本工位其它码或空闲)。
-	 */
 	public void applyClearedFromPush(String clearedSn) {
 		String local = nvl(currentSn);
 		String remote = nvl(clearedSn);
@@ -345,35 +308,42 @@ public class StationPanel extends JPanel {
 	}
 
 	/**
-	 * HOLD:等焊机进入「运行」;
-	 * RUN:运行中每秒采参;回到非运行则集合一次性上传。
-	 * 凸焊无 A/B 面,activeSide 固定 TW。
+	 * HOLD:读握手位等运行开始;
+	 * RUN:每秒采生产参数回显;运行结束则上传。
 	 */
 	public void tick() {
 		if (busy.get()) {
+			uiPlcLabel();
+			uiServerHeartbeat();
 			return;
 		}
 		try {
 			if (phase == Phase.HOLD) {
-				if (device.isRunning()) {
+				TuHanParamData d = device.readRaw();
+				if (d != null && d.connected && d.runStart) {
 					activeSide = "TUHAN";
 					seenRunning = false;
 					lastSampleAtMs = 0L;
 					sampleBuffer.clear();
-					device.setMesAllowEntry(false);
 					phase = Phase.RUN;
-					setStatusUi("焊机运行中,每秒采参...");
+					setStatusUi(d.mesShield ? "MES已屏蔽,设备已开始,每秒采参..." : "设备运行中,每秒采参...");
 					collectSampleIfDue(true);
+				} else if (d != null && d.connected && d.mesShield) {
+					setStatusUi("已取码,MES已屏蔽(设备可不经允许运行)");
 				}
 			} else if (phase == Phase.RUN) {
-				boolean running = device.isRunning();
+				TuHanParamData d = device.readRaw();
+				boolean running = d != null && d.connected && d.runStart;
+				boolean ended = d != null && d.connected && d.runEnd;
 				if (running) {
 					seenRunning = true;
 					collectSampleIfDue(false);
-					setStatusUi("焊机运行中,已采 " + sampleBuffer.size() + " 点");
-				} else if (seenRunning) {
+					setStatusUi("设备运行中,已采 " + sampleBuffer.size() + " 点"
+							+ (d.mesShield ? "(MES屏蔽)" : ""));
+				}
+				if (ended || (seenRunning && !running)) {
 					collectSampleIfDue(true);
-					setStatusUi("焊接结束,上传 " + sampleBuffer.size() + " 点...");
+					setStatusUi("运行结束,上传 " + sampleBuffer.size() + " 点...");
 					uploadAndSubmitAsync();
 				}
 			}
@@ -384,9 +354,6 @@ public class StationPanel extends JPanel {
 		}
 	}
 
-	/**
-	 * 运行中采参:默认每秒一条;force=true 时忽略间隔(进入 RUN / 结束前补采)。
-	 */
 	private void collectSampleIfDue(boolean force) {
 		long now = System.currentTimeMillis();
 		if (!force && lastSampleAtMs > 0L && (now - lastSampleAtMs) < SAMPLE_INTERVAL_MS) {
@@ -411,12 +378,9 @@ public class StationPanel extends JPanel {
 					busy.set(false);
 				}
 			}
-		}, "hg-next-" + cfg.getStationSn()).start();
+		}, "tuhan-next-" + cfg.getStationSn()).start();
 	}
 
-	/**
-	 * 清码前确认:必须有当前工件码;确认后调服务端 clear(sn+stationSn)。
-	 */
 	private void requestClearWithConfirm() {
 		final String sn = nvl(currentSn);
 		if (sn.isEmpty()) {
@@ -439,7 +403,6 @@ public class StationPanel extends JPanel {
 		requestClearAsync(sn);
 	}
 
-	/** 异步清码:调 mesFlexQueue/clear,成功后复位 */
 	private void requestClearAsync(final String sn) {
 		if (!busy.compareAndSet(false, true)) {
 			return;
@@ -454,7 +417,7 @@ public class StationPanel extends JPanel {
 					busy.set(false);
 				}
 			}
-		}, "hg-clear-" + cfg.getStationSn()).start();
+		}, "tuhan-clear-" + cfg.getStationSn()).start();
 	}
 
 	private void doClear(String sn) {
@@ -496,11 +459,14 @@ public class StationPanel extends JPanel {
 			@Override
 			public void run() {
 				txtSn.setText(sn);
-				txtSide.setText("");
 			}
 		});
-		device.setMesAllowEntry(true);
-		setStatusUi("已取码,等待焊机进入运行");
+		boolean allowOk = device.setMesAllowEntry(true);
+		if (!allowOk) {
+			setStatusUi("已取码,但写 MES允许运行 失败,请检查 PLC");
+		} else {
+			setStatusUi("已取码,已写允许运行,等待运行开始");
+		}
 		MainFrame.setMenuStatus(cfg.getStationSn() + " 取码成功 " + sn, 0);
 	}
 
@@ -535,10 +501,6 @@ public class StationPanel extends JPanel {
 		}, "tuhan-upload-" + cfg.getStationSn()).start();
 	}
 
-	/**
-	 * 把运行中采样集合一次性 uploadAndSubmit。
-	 * 字段对齐 mesFlexHg;凸焊过程量映射到 voltage/current/wireSpeed(加压时间)/side(修模状态)。
-	 */
 	private void doUploadAndSubmit() {
 		final String sn = currentSn;
 		if (sn == null || sn.trim().isEmpty()) {
@@ -583,7 +545,6 @@ public class StationPanel extends JPanel {
 		MainFrame.setMenuStatus(cfg.getStationSn() + " 完成 " + sn, 0);
 	}
 
-	/** 采样集合 → JSON 数组字符串(服务端 samples / samplesJson) */
 	private static String toSamplesJson(List<WeldParams> samples) {
 		JSONArray arr = new JSONArray();
 		if (samples != null) {
@@ -599,6 +560,18 @@ public class StationPanel extends JPanel {
 				o.put("jobNo", nvl(wp.jobNo));
 				o.put("errorCode", nvl(wp.errorCode));
 				o.put("side", nvl(wp.side));
+				o.put("production", wp.productionCount);
+				o.put("finished", wp.finishedCount);
+				o.put("weld1Current", wp.weld1Current);
+				o.put("weld1Time", wp.weld1Time);
+				o.put("weld2Current", wp.weld2Current);
+				o.put("weld2Time", wp.weld2Time);
+				o.put("weld3Current", wp.weld3Current);
+				o.put("weld3Time", wp.weld3Time);
+				o.put("upperDress", wp.upperElectrodeDressCount);
+				o.put("lowerDress", wp.lowerElectrodeDressCount);
+				o.put("upperReplace", wp.upperElectrodeReplaceCount);
+				o.put("lowerReplace", wp.lowerElectrodeReplaceCount);
 				arr.add(o);
 			}
 		}
@@ -616,13 +589,14 @@ public class StationPanel extends JPanel {
 			@Override
 			public void run() {
 				txtSn.setText("");
-				txtVoltage.setText("");
-				txtCurrent.setText("");
-				txtWire.setText("");
-				txtSide.setText("");
-				txtJobNo.setText("");
-				txtErrorCode.setText("");
-				txtDeviceType.setText("");
+				txtWeld1Current.setText("");
+				txtWeld1Time.setText("");
+				txtWeld2Current.setText("");
+				txtWeld2Time.setText("");
+				txtWeld3Current.setText("");
+				txtWeld3Time.setText("");
+				txtProduction.setText("");
+				txtFinished.setText("");
 				lblStatus.setText(msg);
 			}
 		});
@@ -634,11 +608,11 @@ public class StationPanel extends JPanel {
 			public void run() {
 				lblStatus.setText(text == null ? "" : text);
 				String t = text == null ? "" : text;
-				if (t.contains("失败") || t.contains("异常")) {
+				if (t.contains("失败") || t.contains("异常") || t.contains("报警")) {
 					lblStatus.setBackground(UiTheme.ERR_BG);
 					lblStatus.setForeground(UiTheme.ERR_FG);
-				} else if (t.contains("运行") || t.contains("上传") || t.contains("过站") || t.contains("取码")
-						|| t.contains("等待") || t.contains("识别") || t.contains("采")) {
+				} else if (t.contains("屏蔽") || t.contains("运行") || t.contains("上传") || t.contains("过站")
+						|| t.contains("取码") || t.contains("等待") || t.contains("采")) {
 					lblStatus.setBackground(UiTheme.RUN_BG);
 					lblStatus.setForeground(UiTheme.RUN_FG);
 				} else {
@@ -656,13 +630,14 @@ public class StationPanel extends JPanel {
 		SwingUtilities.invokeLater(new Runnable() {
 			@Override
 			public void run() {
-				txtVoltage.setText(nvl(wp.voltage));
-				txtCurrent.setText(nvl(wp.currentVal));
-				txtWire.setText(nvl(wp.wireSpeed));
-				txtSide.setText(nvl(wp.side));
-				txtJobNo.setText(nvl(wp.jobNo));
-				txtErrorCode.setText(nvl(wp.errorCode));
-				txtDeviceType.setText(nvl(wp.deviceType));
+				txtWeld1Current.setText(String.valueOf(wp.weld1Current));
+				txtWeld1Time.setText(String.valueOf(wp.weld1Time));
+				txtWeld2Current.setText(String.valueOf(wp.weld2Current));
+				txtWeld2Time.setText(String.valueOf(wp.weld2Time));
+				txtWeld3Current.setText(String.valueOf(wp.weld3Current));
+				txtWeld3Time.setText(String.valueOf(wp.weld3Time));
+				txtProduction.setText(String.valueOf(wp.productionCount));
+				txtFinished.setText(String.valueOf(wp.finishedCount));
 			}
 		});
 	}
@@ -670,21 +645,27 @@ public class StationPanel extends JPanel {
 	private void uiPlcLabel() {
 		final boolean ok = device.isConnected();
 		final boolean run = ok && device.isDeviceRunning();
+		final boolean shield = ok && device.isMesShield();
 		SwingUtilities.invokeLater(new Runnable() {
 			@Override
 			public void run() {
 				if (ok) {
-					lblPlc.setText("焊机 " + device.getPortDesc() + "  ·  已连接" + (run ? " · 设备运行" : ""));
+					String extra = "";
+					if (shield) {
+						extra = " · MES屏蔽";
+					} else if (run) {
+						extra = " · 设备运行";
+					}
+					lblPlc.setText("PLC " + device.getPortDesc() + "  ·  已连接" + extra);
 					UiTheme.stylePlcPill(lblPlc, true);
 				} else {
-					lblPlc.setText("焊机 " + device.getPortDesc() + "  ·  未连接");
+					lblPlc.setText("PLC " + device.getPortDesc() + "  ·  未连接");
 					UiTheme.stylePlcPill(lblPlc, false);
 				}
 			}
 		});
 	}
 
-	/** 按 MainFrame SSE 连接状态刷新呼吸灯 */
 	private void uiServerHeartbeat() {
 		final boolean online = MainFrame.isMesServerOnline();
 		SwingUtilities.invokeLater(new Runnable() {

+ 0 - 205
src/main/java/com/mes/util/ModbusRtuClient.java

@@ -1,205 +0,0 @@
-package com.mes.util;
-
-import com.fazecast.jSerialComm.SerialPort;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.IOException;
-import java.util.Arrays;
-
-/**
- * Modbus RTU 主站客户端(RS485 串口)
- */
-public class ModbusRtuClient {
-
-    /** 日志 */
-    private static final Logger log = LoggerFactory.getLogger(ModbusRtuClient.class);
-
-    /** 当前打开的串口 */
-    private SerialPort serialPort;
-    /** Modbus 从站号 */
-    private int slaveId;
-    /** 读写超时(毫秒) */
-    private int timeoutMs;
-    /** 串口收发互斥锁 */
-    private final Object ioLock = new Object();
-
-    public boolean open(TuHanModbusConfig config) {
-        close();
-        slaveId = config.slaveId;
-        timeoutMs = config.timeoutMs;
-
-        serialPort = SerialPort.getCommPort(config.port);
-        serialPort.setBaudRate(config.baud);
-        serialPort.setNumDataBits(config.dataBits);
-        serialPort.setNumStopBits(config.stopBits);
-        serialPort.setParity(parseParity(config.parity));
-        serialPort.setComPortTimeouts(SerialPort.TIMEOUT_READ_SEMI_BLOCKING, timeoutMs, 0);
-
-        if (!serialPort.openPort()) {
-            log.error("打开串口失败: {}", config.port);
-            serialPort = null;
-            return false;
-        }
-        log.info("焊机串口已打开: {}, {}bps, 校验={}", config.port, config.baud, config.parity);
-        return true;
-    }
-
-    public void close() {
-        if (serialPort != null && serialPort.isOpen()) {
-            serialPort.closePort();
-        }
-        serialPort = null;
-    }
-
-    public boolean isOpen() {
-        return serialPort != null && serialPort.isOpen();
-    }
-
-    /**
-     * 读保持寄存器(功能码 03H)
-     */
-    public int[] readHoldingRegisters(int startAddress, int count) throws IOException {
-        if (!isOpen()) {
-            throw new IOException("串口未打开");
-        }
-        if (count <= 0 || count > 20) {
-            throw new IOException("读取字数须在 1~20 之间");
-        }
-
-            synchronized (ioLock) {
-            clearInputBuffer();
-
-            byte[] request = new byte[8];
-            request[0] = (byte) slaveId;
-            request[1] = 0x03;
-            request[2] = (byte) ((startAddress >> 8) & 0xFF);
-            request[3] = (byte) (startAddress & 0xFF);
-            request[4] = (byte) ((count >> 8) & 0xFF);
-            request[5] = (byte) (count & 0xFF);
-            appendCrc(request, 6);
-
-            int written = serialPort.writeBytes(request, request.length);
-            if (written != request.length) {
-                throw new IOException("发送 Modbus 指令失败");
-            }
-
-            byte[] response = readResponse(5 + count * 2);
-
-            validateResponse(response, (byte) 0x03, count * 2);
-
-            int[] values = new int[count];
-            for (int i = 0; i < count; i++) {
-                int hi = response[3 + i * 2] & 0xFF;
-                int lo = response[4 + i * 2] & 0xFF;
-                values[i] = (hi << 8) | lo;
-            }
-            return values;
-        }
-    }
-    //清空串口输入缓冲区,避免读取到残留数据,读操作就能充当清空作用
-    private void clearInputBuffer() {
-        byte[] trash = new byte[256];
-        while (serialPort.bytesAvailable() > 0) {
-            serialPort.readBytes(trash, Math.min(trash.length, serialPort.bytesAvailable()));
-        }
-    }
-
-    private byte[] readResponse(int expectedDataBytes) throws IOException {
-        // 地址(1) + 功能码(1) + 字节数(1) + 数据(N) + CRC(2)
-        int frameLen = 3 + expectedDataBytes + 2;
-        byte[] buffer = new byte[frameLen];
-        int total = 0;
-        long deadline = System.currentTimeMillis() + timeoutMs;
-
-        while (total < 3 && System.currentTimeMillis() < deadline) {
-            int n = serialPort.readBytes(buffer, 3 - total, total);
-            if (n > 0) {
-                total += n;
-            }
-        }
-        if (total < 3) {
-            throw new IOException("读取 Modbus 响应超时");
-        }
-
-        if ((buffer[1] & 0x80) != 0) {
-            readRemain(buffer, 3, 2);
-            throw new IOException("Modbus 异常应答, 故障码=0x" + Integer.toHexString(buffer[2] & 0xFF));
-        }
-
-        int dataBytes = buffer[2] & 0xFF;//记录第三索引的数据长度
-        readRemain(buffer, 3, dataBytes + 2);
-        return Arrays.copyOf(buffer, 3 + dataBytes + 2);
-    }
-
-    private void readRemain(byte[] buffer, int offset, int length) throws IOException {
-        int total = 0;
-        long deadline = System.currentTimeMillis() + timeoutMs;
-        while (total < length && System.currentTimeMillis() < deadline) {
-            int n = serialPort.readBytes(buffer, length - total, offset + total);
-            if (n > 0) {
-                total += n;
-            }
-        }
-        if (total < length) {
-            throw new IOException("读取 Modbus 数据区超时");
-        }
-    }
-
-    private void validateResponse(byte[] response, byte functionCode, int dataBytes) throws IOException {
-        if (response.length < 5) {
-            throw new IOException("Modbus 响应长度不足");
-        }
-        if ((response[0] & 0xFF) != (slaveId & 0xFF)) {
-            throw new IOException("Modbus 站号不匹配");
-        }
-        if (response[1] != functionCode) {
-            throw new IOException("Modbus 功能码不匹配");
-        }
-        if ((response[2] & 0xFF) != dataBytes) {
-            throw new IOException("Modbus 数据长度不匹配");
-        }
-        if (!verifyCrc(response)) {
-            throw new IOException("Modbus CRC 校验失败");
-        }
-    }
-
-    private static int parseParity(String parity) {
-        if ("NONE".equalsIgnoreCase(parity)) {
-            return SerialPort.NO_PARITY;
-        }
-        if ("ODD".equalsIgnoreCase(parity)) {
-            return SerialPort.ODD_PARITY;
-        }
-        return SerialPort.EVEN_PARITY;
-    }
-
-    private static void appendCrc(byte[] data, int length) {
-        int crc = calcCrc16(data, 0, length);
-        data[length] = (byte) (crc & 0xFF);
-        data[length + 1] = (byte) ((crc >> 8) & 0xFF);
-    }
-
-    private static boolean verifyCrc(byte[] data) {
-        int len = data.length - 2;
-        int crc = calcCrc16(data, 0, len);
-        int lo = data[len] & 0xFF;
-        int hi = data[len + 1] & 0xFF;
-        return crc == ((hi << 8) | lo);
-    }
-
-    private static int calcCrc16(byte[] data, int offset, int length) {
-        int crc = 0xFFFF;
-        for (int i = offset; i < offset + length; i++) {
-            crc ^= (data[i] & 0xFF);
-            for (int j = 0; j < 8; j++) {
-                if ((crc & 0x0001) != 0) {
-                    crc = (crc >> 1) ^ 0xA001;
-                } else {
-                    crc >>= 1;
-                }
-            }
-        }
-        return crc;
-    }
-}

+ 0 - 58
src/main/java/com/mes/util/TuHanModbusConfig.java

@@ -1,58 +0,0 @@
-package com.mes.util;
-
-import com.mes.config.MesClientProperties;
-
-/**
- * 凸焊 Modbus RTU 通讯配置(由工位 yml 注入)。
- */
-public class TuHanModbusConfig {
-
-	/** 是否启用焊机串口 */
-	public boolean enabled = true;
-	/** 串口名,如 COM3 */
-	public String port = "COM3";
-	/** 波特率 */
-	public int baud = 9600;
-	/** 数据位 */
-	public int dataBits = 8;
-	/** 停止位 */
-	public int stopBits = 1;
-	/** 校验:EVEN/ODD/NONE */
-	public String parity = "EVEN";
-	/** Modbus 从站号 */
-	public int slaveId = 1;
-	/** 轮询间隔(毫秒,预留) */
-	public int pollIntervalMs = 500;
-	/** 读写超时(毫秒) */
-	public int timeoutMs = 1000;
-
-	public static TuHanModbusConfig fromStation(MesClientProperties.StationConfig station) {
-		TuHanModbusConfig config = new TuHanModbusConfig();
-		if (station == null) {
-			return config;
-		}
-		config.enabled = station.isWelderEnabled();
-		if (station.getWelderPort() != null && !station.getWelderPort().trim().isEmpty()) {
-			config.port = station.getWelderPort().trim();
-		}
-		if (station.getWelderBaud() > 0) {
-			config.baud = station.getWelderBaud();
-		}
-		if (station.getWelderDatabits() > 0) {
-			config.dataBits = station.getWelderDatabits();
-		}
-		if (station.getWelderStopbits() > 0) {
-			config.stopBits = station.getWelderStopbits();
-		}
-		if (station.getWelderParity() != null && !station.getWelderParity().trim().isEmpty()) {
-			config.parity = station.getWelderParity().trim().toUpperCase();
-		}
-		if (station.getWelderSlaveId() >= 0) {
-			config.slaveId = station.getWelderSlaveId();
-		}
-		if (station.getWelderTimeoutMs() > 0) {
-			config.timeoutMs = station.getWelderTimeoutMs();
-		}
-		return config;
-	}
-}

+ 46 - 49
src/main/java/com/mes/util/TuHanParamData.java

@@ -1,7 +1,7 @@
 package com.mes.util;
 
 /**
- * 凸焊(TuHan)加工参数快照(Modbus 读出)。
+ * 凸焊(TuHan)加工参数快照(S7 DB37 读出)。
  */
 public class TuHanParamData {
 
@@ -10,56 +10,42 @@ public class TuHanParamData {
 	/** 失败原因或空串 */
 	public String errorMessage;
 
-	/** 工作模式:焊接/调整 */
-	public String workMode;
-	/** 运行状态:运行/待机 */
-	public String runState;
-	/** 修模状态:修模/正常 */
-	public String toolingState;
-	/** 报警文案(无报警或 Erxx) */
-	public String alarmText;
-	/** 焊接计数 */
-	public int weldCount;
-	/** 当前规范号 */
-	public int specNo;
+	/** 设备状态:true=正常,false=报警(DB37.DBX38.0) */
+	public boolean deviceOk;
+	/** MES 允许运行(DB37.DBX0.0,可读回显) */
+	public boolean mesAllowRun;
+	/** MES 屏蔽按钮(DB37.DBX0.1) */
+	public boolean mesShield;
+	/** 运行开始状态(DB37.DBX0.2) */
+	public boolean runStart;
+	/** 运行结束状态(DB37.DBX0.3) */
+	public boolean runEnd;
 
-	/** 电容电压 */
-	public int capVoltage;
-	/** 预热电压实测 */
-	public int preheatVoltage;
-	/** 焊接电压实测 */
-	public int weldVoltage;
-	/** 回火电压实测 */
-	public int temperVoltage;
-	/** 预热峰值电流(带 KA) */
-	public String preheatPeakCurrent;
-	/** 焊接峰值电流(带 KA) */
-	public String weldPeakCurrent;
-	/** 回火峰值电流(带 KA) */
-	public String temperPeakCurrent;
+	/** 上电极修模计数 */
+	public int upperElectrodeDressCount;
+	/** 下电极修模计数 */
+	public int lowerElectrodeDressCount;
+	/** 上电极更换计数 */
+	public int upperElectrodeReplaceCount;
+	/** 下电极更换计数 */
+	public int lowerElectrodeReplaceCount;
+	/** 生产量计数 */
+	public int productionCount;
+	/** 成品产量计数 */
+	public int finishedCount;
 
-	/** 规范:预压时间 */
-	public int prePressTime;
-	/** 规范:加压时间 */
-	public int pressTime;
-	/** 规范:预热电压设定 */
-	public int specPreheatVoltage;
-	/** 规范:预热电流设定 */
-	public int specPreheatCurrent;
-	/** 规范:预热时间 */
-	public int specPreheatTime;
-	/** 规范:焊接电压设定 */
-	public int specWeldVoltage;
-	/** 规范:焊接电流设定 */
-	public int specWeldCurrent;
-	/** 规范:焊接时间 */
-	public int specWeldTime;
-	/** 规范:回火电压设定 */
-	public int specTemperVoltage;
-	/** 规范:回火电流设定 */
-	public int specTemperCurrent;
-	/** 规范:回火时间 */
-	public int specTemperTime;
+	/** 焊1电流 */
+	public int weld1Current;
+	/** 焊1时间 */
+	public int weld1Time;
+	/** 焊2电流 */
+	public int weld2Current;
+	/** 焊2时间 */
+	public int weld2Time;
+	/** 焊3电流 */
+	public int weld3Current;
+	/** 焊3时间 */
+	public int weld3Time;
 
 	public static TuHanParamData disconnected(String message) {
 		TuHanParamData data = new TuHanParamData();
@@ -67,4 +53,15 @@ public class TuHanParamData {
 		data.errorMessage = message;
 		return data;
 	}
+
+	public String deviceStatusText() {
+		if (!connected) {
+			return "";
+		}
+		return deviceOk ? "正常" : "报警";
+	}
+
+	public String yesNo(boolean v) {
+		return v ? "是" : "否";
+	}
 }

+ 0 - 114
src/main/java/com/mes/util/TuHanParamReader.java

@@ -1,114 +0,0 @@
-package com.mes.util;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * 凸焊(TuHan):从 FCN 焊机 Modbus 读取加工参数。
- */
-public class TuHanParamReader {
-
-	/** 日志 */
-	private static final Logger log = LoggerFactory.getLogger(TuHanParamReader.class);
-
-	/** 状态字寄存器地址 */
-	private static final int ADDR_STATUS = 0x21;
-	/** 报警字寄存器地址 */
-	private static final int ADDR_ALARM = 0x22;
-	/** 焊接计数寄存器地址 */
-	private static final int ADDR_WELD_COUNT = 0x23;
-	/** 规范号寄存器地址 */
-	private static final int ADDR_SPEC_NO = 0x24;
-	/** 电流小数点寄存器地址 */
-	private static final int ADDR_DECIMAL = 0x62;
-	/** 电容电压寄存器地址 */
-	private static final int ADDR_CAP_VOLTAGE = 0x96;
-	/** 预热电压起址(后续连续读实测块) */
-	private static final int ADDR_PREHEAT_VOLTAGE = 0xA5;
-	/** 规范参数区基址 */
-	private static final int ADDR_SPEC_BASE = 0x0100;
-	/** 每条规范占用字数 */
-	private static final int WORDS_PER_SPEC = 0x1E;
-
-	/** Modbus RTU 客户端 */
-	private final ModbusRtuClient client;
-
-	public TuHanParamReader(ModbusRtuClient client) {
-		this.client = client;
-	}
-
-	public TuHanParamData read() {
-		if (!client.isOpen()) {
-			return TuHanParamData.disconnected("串口未连接");
-		}
-		try {
-			TuHanParamData data = new TuHanParamData();
-			data.connected = true;
-
-			int[] statusBlock = client.readHoldingRegisters(ADDR_STATUS, 4);
-			parseStatus(statusBlock[0], data);
-			data.alarmText = parseAlarm(statusBlock[1]);
-			data.weldCount = statusBlock[2];
-			data.specNo = statusBlock[3];
-
-			int decimalPoint = client.readHoldingRegisters(ADDR_DECIMAL, 1)[0];
-			data.capVoltage = client.readHoldingRegisters(ADDR_CAP_VOLTAGE, 1)[0];
-
-			int[] resultBlock = client.readHoldingRegisters(ADDR_PREHEAT_VOLTAGE, 6);
-			data.preheatVoltage = resultBlock[0];
-			data.weldVoltage = resultBlock[1];
-			data.temperVoltage = resultBlock[2];
-			data.preheatPeakCurrent = formatCurrent(resultBlock[3], decimalPoint);
-			data.weldPeakCurrent = formatCurrent(resultBlock[4], decimalPoint);
-			data.temperPeakCurrent = formatCurrent(resultBlock[5], decimalPoint);
-
-			if (data.specNo >= 1 && data.specNo <= 100) {
-				int specBase = ADDR_SPEC_BASE + (data.specNo - 1) * WORDS_PER_SPEC;
-				int[] specBlock = client.readHoldingRegisters(specBase, 13);
-				data.prePressTime = specBlock[0];
-				data.pressTime = specBlock[1];
-				data.specPreheatVoltage = specBlock[2];
-				data.specPreheatCurrent = specBlock[3];
-				data.specPreheatTime = specBlock[4];
-				data.specWeldVoltage = specBlock[6];
-				data.specWeldCurrent = specBlock[7];
-				data.specWeldTime = specBlock[8];
-				data.specTemperVoltage = specBlock[10];
-				data.specTemperCurrent = specBlock[11];
-				data.specTemperTime = specBlock[12];
-			}
-
-			data.errorMessage = "";
-			return data;
-		} catch (Exception e) {
-			log.warn("读取凸焊参数失败: {}", e.getMessage());
-			return TuHanParamData.disconnected(e.getMessage());
-		}
-	}
-
-	private static void parseStatus(int statusWord, TuHanParamData data) {
-		int low = statusWord & 0xFF;
-		data.workMode = ((low >> 1) & 0x01) == 1 ? "焊接" : "调整";
-		data.runState = ((low >> 4) & 0x01) == 1 ? "运行" : "待机";
-		data.toolingState = ((low >> 5) & 0x01) == 1 ? "修模" : "正常";
-	}
-
-	private static String parseAlarm(int alarmWord) {
-		int code = alarmWord & 0xFF;
-		if (code == 0) {
-			return "无报警";
-		}
-		return "Er" + String.format("%02d", code);
-	}
-
-	private static String formatCurrent(int raw, int decimalPoint) {
-		switch (decimalPoint) {
-			case 1:
-				return String.format("%.1f KA", raw / 10.0);
-			case 2:
-				return String.format("%.2f KA", raw / 100.0);
-			default:
-				return raw + " KA";
-		}
-	}
-}

+ 36 - 0
src/main/java/com/mes/util/TuHanPlcConfig.java

@@ -0,0 +1,36 @@
+package com.mes.util;
+
+import com.mes.config.MesClientProperties;
+
+/**
+ * 凸焊 S7 通讯配置(由工位 yml 注入)。
+ */
+public class TuHanPlcConfig {
+
+	/** 是否启用 PLC 通讯 */
+	public boolean enabled = true;
+	/** PLC IP,如 192.168.0.10 */
+	public String ip = "192.168.0.10";
+	/** PLC 型号:S1200 / S1500 / S200_SMART 等,对应 EPlcType */
+	public String plcType = "S1200";
+	/** 读写超时(毫秒) */
+	public int timeoutMs = 3000;
+
+	public static TuHanPlcConfig fromStation(MesClientProperties.StationConfig station) {
+		TuHanPlcConfig config = new TuHanPlcConfig();
+		if (station == null) {
+			return config;
+		}
+		config.enabled = station.isPlcEnabled();
+		if (station.getPlcIp() != null && !station.getPlcIp().trim().isEmpty()) {
+			config.ip = station.getPlcIp().trim();
+		}
+		if (station.getPlcType() != null && !station.getPlcType().trim().isEmpty()) {
+			config.plcType = station.getPlcType().trim().toUpperCase();
+		}
+		if (station.getPlcTimeoutMs() > 0) {
+			config.timeoutMs = station.getPlcTimeoutMs();
+		}
+		return config;
+	}
+}

+ 106 - 0
src/main/java/com/mes/util/TuHanPlcReader.java

@@ -0,0 +1,106 @@
+package com.mes.util;
+
+import com.github.xingshuangs.iot.protocol.s7.service.S7PLC;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * 凸焊(TuHan):按点位表从 S7 DB37 读取状态与过程参数。
+ * <p>
+ * 地址格式与 iot-communication 一致:{@code DBn.byte.bit} / 字偏移用 byte.0。
+ * </p>
+ */
+public class TuHanPlcReader {
+
+	private static final Logger log = LoggerFactory.getLogger(TuHanPlcReader.class);
+
+	/** 设备状态 1=正常 0=报警 */
+	public static final String ADDR_DEVICE_STATUS = "DB37.38.0";
+	/** MES 允许运行(客户端写、可读回显) */
+	public static final String ADDR_MES_ALLOW = "DB37.0.0";
+	/** MES 屏蔽按钮 */
+	public static final String ADDR_MES_SHIELD = "DB37.0.1";
+	/** 运行开始状态 */
+	public static final String ADDR_RUN_START = "DB37.0.2";
+	/** 运行结束状态 */
+	public static final String ADDR_RUN_END = "DB37.0.3";
+
+	public static final String ADDR_UPPER_DRESS = "DB37.2.0";
+	public static final String ADDR_LOWER_DRESS = "DB37.6.0";
+	public static final String ADDR_UPPER_REPLACE = "DB37.10.0";
+	public static final String ADDR_LOWER_REPLACE = "DB37.14.0";
+	public static final String ADDR_PRODUCTION = "DB37.18.0";
+	public static final String ADDR_FINISHED = "DB37.22.0";
+
+	public static final String ADDR_WELD1_CURRENT = "DB37.26.0";
+	public static final String ADDR_WELD1_TIME = "DB37.28.0";
+	public static final String ADDR_WELD2_CURRENT = "DB37.30.0";
+	public static final String ADDR_WELD2_TIME = "DB37.32.0";
+	public static final String ADDR_WELD3_CURRENT = "DB37.34.0";
+	public static final String ADDR_WELD3_TIME = "DB37.36.0";
+
+	private final S7PLC plc;
+
+	public TuHanPlcReader(S7PLC plc) {
+		this.plc = plc;
+	}
+
+	public TuHanParamData read() {
+		if (plc == null) {
+			return TuHanParamData.disconnected("PLC 未连接");
+		}
+		try {
+			TuHanParamData data = new TuHanParamData();
+			data.connected = true;
+
+			data.deviceOk = plc.readBoolean(ADDR_DEVICE_STATUS);
+			data.mesAllowRun = plc.readBoolean(ADDR_MES_ALLOW);
+			data.mesShield = plc.readBoolean(ADDR_MES_SHIELD);
+			data.runStart = plc.readBoolean(ADDR_RUN_START);
+			data.runEnd = plc.readBoolean(ADDR_RUN_END);
+
+			data.upperElectrodeDressCount = safeInt32(ADDR_UPPER_DRESS);
+			data.lowerElectrodeDressCount = safeInt32(ADDR_LOWER_DRESS);
+			data.upperElectrodeReplaceCount = safeInt32(ADDR_UPPER_REPLACE);
+			data.lowerElectrodeReplaceCount = safeInt32(ADDR_LOWER_REPLACE);
+			data.productionCount = safeInt32(ADDR_PRODUCTION);
+			data.finishedCount = safeInt32(ADDR_FINISHED);
+
+			data.weld1Current = safeInt16(ADDR_WELD1_CURRENT);
+			data.weld1Time = safeInt16(ADDR_WELD1_TIME);
+			data.weld2Current = safeInt16(ADDR_WELD2_CURRENT);
+			data.weld2Time = safeInt16(ADDR_WELD2_TIME);
+			data.weld3Current = safeInt16(ADDR_WELD3_CURRENT);
+			data.weld3Time = safeInt16(ADDR_WELD3_TIME);
+
+			data.errorMessage = data.deviceOk ? "" : "设备报警";
+			return data;
+		} catch (Exception e) {
+			log.warn("读取凸焊 PLC 参数失败: {}", e.getMessage());
+			return TuHanParamData.disconnected(e.getMessage());
+		}
+	}
+
+	public boolean writeMesAllow(boolean allow) {
+		if (plc == null) {
+			return false;
+		}
+		try {
+			plc.writeBoolean(ADDR_MES_ALLOW, allow);
+			return true;
+		} catch (Exception e) {
+			log.warn("写 MES允许运行 失败: {}", e.getMessage());
+			return false;
+		}
+	}
+
+	private int safeInt32(String addr) {
+		Integer v = plc.readInt32(addr);
+		return v == null ? 0 : v;
+	}
+
+	private int safeInt16(String addr) {
+		Short v = plc.readInt16(addr);
+		return v == null ? 0 : v.intValue();
+	}
+}

+ 4 - 8
src/main/resources/config/application.yml

@@ -22,11 +22,7 @@ mes:
     - id: 1
       title: 凸焊1#
       station-sn: TUHAN01
-      welder-enabled: true
-      welder-port: COM3
-      welder-baud: 9600
-      welder-databits: 8
-      welder-stopbits: 1
-      welder-parity: EVEN
-      welder-slave-id: 1
-      welder-timeout-ms: 1000
+      plc-enabled: true
+      plc-ip: 192.168.0.10
+      plc-type: S1200
+      plc-timeout-ms: 3000