zxl 36 минут назад
Родитель
Сommit
f9ca4ff904

+ 0 - 136
pack/dist/application.yml.example

@@ -1,136 +0,0 @@
-# 自动化大冲:主界面 DB260 取批;五台压机跟批次采点(不因冲次达标结案)
-# 五台与线体共用同一工位号(stations.station-sn),机台靠 press-no 区分
-# 结案 completeBatch 落 mes_flex_dc;压机采样 uploadPressParam 落 mes_flex_dc_press_param
-# 结案入口:清码 / 手动中断 / 换批自动切段
-spring:
-  main:
-    web-application-type: none
-    banner-mode: off
-  application:
-    name: mesclient-dachong
-
-logging:
-  level:
-    root: INFO
-    com.mes: INFO
-
-mes:
-  app-title: MES 自动化大冲
-  server-ip: 192.168.9.19
-  tick-ms: 1000
-  # 压机采样周期(毫秒) / 缓冲满多少点上报一次
-  press-sample-ms: 1000
-  press-upload-max: 20
-  # 是否写 PLC MES允许运行点。false=开批/结案/清码都不写,本地仍取批盯产量
-  mes-allow-enabled: false
-
-  # 线体主站(唯一取码工位;五台压机共用此工位号)
-  stations:
-    - id: 1
-      title: 自动化大冲
-      station-sn: DC-WIRE
-      plc-ip: 192.168.17.1
-      plc-port: 102
-      # MES允许运行 BOOL(点表 DB260.141.0;屏蔽为 141.1 只读不写);空则只本地开批不写 PLC
-      mes-allow-addr: DB260.141.0
-
-  # =====================================================================
-  # 五台压机过程页:不取码、不单独占工位、不触发线体结案
-  # 点表全称 ↔ yml 配置项(地址按 S7 写法,例 DB3.168):
-  #   冲次数量     → stroke-count-addr       (UDINT;本批进度差)
-  #   生产高度     → die-height-addr         (REAL)
-  #   顶缸压力     → cylinder-pressure-addr  (REAL)
-  #   生产吨位     → tonnage-addr            (REAL 或 DINT,由 tonnage-dint 决定)
-  #   压机行程次数 → press-spm-addr          (REAL)
-  #   气垫风压     → air-cushion-addr        (REAL;仅压机1配,其它留空)
-  #   顶杆行程     → ejector-stroke-addr     (REAL;仅压机1配,其它留空)
-  #   额定功率kW   → rated-power-kw          (能耗=额定功率×本批运行小时;不读 PLC、不做能耗曲线)
-  # 另:device-run-addr = 设备运行 BOOL;空则界面不亮运行灯
-  #     tonnage-dint=true 按 DINT 读生产吨位,false 按 REAL 读
-  # plc-ip 空:本机不连 PLC,不影响其它压机
-  # =====================================================================
-  presses:
-    # ---------- 压机1 LS4-1300R(气垫风压/顶杆行程仅本台) ----------
-    - press-no: 1
-      title: 压机1 LS4-1300R
-      press-model: LS4-1300R
-      plc-ip: 192.168.17.150
-      plc-port: 102
-      stroke-count-addr: DB3.168              # 冲次数量
-      die-height-addr: DB3.100                 # 生产高度
-      cylinder-pressure-addr: DB91.2         # 顶缸压力
-      tonnage-addr: DB900.360                   # 生产吨位
-      tonnage-dint: true              # 生产吨位数据类型:false=REAL,true=DINT
-      press-spm-addr: DB63.6                  # 压机行程次数
-      air-cushion-addr: DB141.2                # 气垫风压(仅压机1)
-      ejector-stroke-addr: DB142.18             # 顶杆行程(仅压机1)
-      rated-power-kw: 250                        # 额定功率 kW(按铭牌填;0=不估算能耗)
-      device-run-addr: DB395.6.0                 # 设备运行 BOOL
-
-    # ---------- 压机2 JD36-800R ----------
-    - press-no: 2
-      title: 压机2 JD36-800R
-      press-model: JD36-800R
-      plc-ip: 192.168.17.170
-      plc-port: 102
-      stroke-count-addr: DB3.168               # 冲次数量
-      die-height-addr: DB3.100                # 生产高度
-      cylinder-pressure-addr: DB91.2         # 顶缸压力
-      tonnage-addr: DB900.360                   # 生产吨位
-      tonnage-dint: true
-      press-spm-addr: DB63.6                  # 压机行程次数
-      air-cushion-addr:                # 气垫风压:非压机1不配
-      ejector-stroke-addr:             # 顶杆行程:非压机1不配
-      rated-power-kw: 132                        # 额定功率 kW
-      device-run-addr: DB395.6.0                 # 设备运行 BOOL
-
-    # ---------- 压机3 JD36-500R ----------
-    - press-no: 3
-      title: 压机3 JD36-500R
-      press-model: JD36-500R
-      plc-ip: 192.168.17.190
-      plc-port: 102
-      stroke-count-addr: DB3.168               # 冲次数量
-      die-height-addr: DB3.100                # 生产高度
-      cylinder-pressure-addr: DB91.2         # 顶缸压力
-      tonnage-addr: DB900.360                   # 生产吨位
-      tonnage-dint: true
-      press-spm-addr: DB63.6                  # 压机行程次数
-      air-cushion-addr:
-      ejector-stroke-addr:
-      rated-power-kw: 90
-      device-run-addr: DB395.6.0                 # 设备运行 BOOL
-
-    # ---------- 压机4 JD36-500R ----------
-    - press-no: 4
-      title: 压机4 JD36-500R
-      press-model: JD36-500R
-      plc-ip: 192.168.17.210
-      plc-port: 102
-      stroke-count-addr: DB3.168               # 冲次数量
-      die-height-addr: DB3.100                # 生产高度
-      cylinder-pressure-addr: DB91.2         # 顶缸压力
-      tonnage-addr: DB900.360                   # 生产吨位
-      tonnage-dint: true
-      press-spm-addr: DB63.6                  # 压机行程次数
-      air-cushion-addr:
-      ejector-stroke-addr:
-      rated-power-kw: 90
-      device-run-addr: DB395.6.0                 # 设备运行 BOOL
-
-    # ---------- 压机5 JD36-500R ----------
-    - press-no: 5
-      title: 压机5 JD36-500R
-      press-model: JD36-500R
-      plc-ip: 192.168.17.230
-      plc-port: 102
-      stroke-count-addr: DB3.168               # 冲次数量
-      die-height-addr: DB3.100                # 生产高度
-      cylinder-pressure-addr: DB91.2         # 顶缸压力
-      tonnage-addr: DB900.360                   # 生产吨位
-      tonnage-dint: true
-      press-spm-addr: DB63.6                  # 压机行程次数
-      air-cushion-addr:
-      ejector-stroke-addr:
-      rated-power-kw: 90
-      device-run-addr: DB395.6.0                 # 设备运行 BOOL

BIN
pack/dist/mesclient-dachong.exe


+ 10 - 0
src/main/java/com/mes/service/DcPlcClient.java

@@ -12,22 +12,32 @@ import org.slf4j.LoggerFactory;
  */
 public class DcPlcClient {
 
+	/** 日志 */
 	private static final Logger log = LoggerFactory.getLogger(DcPlcClient.class);
 
+	/** 断线后首次重连等待(毫秒) */
 	private static final long RETRY_INITIAL_MS = 2L * 1000L;
+	/** 断线重连最长等待(毫秒),退避上限 */
 	private static final long RETRY_MAX_MS = 30L * 1000L;
 
+	/** 工位编码 */
 	private final String stationSn;
+	/** PLC IP */
 	private final String plcIp;
+	/** S7 端口 */
 	private final int plcPort;
 	/** MES 允许运行 BOOL,空则只打日志不写 PLC */
 	private final String mesAllowAddr;
 	/** 总开关:false 时 setMesAllow 直接跳过,不发开/关 */
 	private final boolean mesAllowEnabled;
 
+	/** S7 客户端实例 */
 	private S7PLC plc;
+	/** 当前是否已连接 */
 	private volatile boolean connected;
+	/** 下次允许重连的时刻(epoch ms) */
 	private volatile long nextRetryAtMs;
+	/** 当前退避间隔(毫秒),连上后复位为初始值 */
 	private volatile long currentRetryDelayMs = RETRY_INITIAL_MS;
 
 	public DcPlcClient(String stationSn, String plcIp, int plcPort, String mesAllowAddr) {

+ 45 - 18
src/main/java/com/mes/ui/PressPanel.java

@@ -40,13 +40,19 @@ public class PressPanel extends JPanel {
 	private final int uploadMax;
 	private final DcPressPlcClient plc;
 
-	/** 本批冲次起点;中途复位后按已产重定 */
+	/** 本批冲次起点(PLC 累计值);中途复位后按已产重定 */
 	private volatile long baseStrokeCount;
+	/** 上一拍冲次累计,用于检测复位 */
 	private volatile long lastStrokeCount;
+	/** 本批已产冲次差(当前批次数量,非 PLC 总冲次) */
 	private volatile int producedQty;
+	/** 本批冲次起点是否已标定;未标定前不算本批进度,避免把总冲次当本批 */
+	private volatile boolean baseStrokeReady;
 	/** 当前已绑定的共享批次码;变化时重定冲次起点 */
 	private volatile String boundBatchCode = "";
+	/** 上次采样时刻 */
 	private volatile long lastSampleAtMs;
+	/** 最近一拍压机快照 */
 	private volatile DcPressSnapshot lastSnap = new DcPressSnapshot();
 	/** 待落库采样点(内存缓冲,满则写入 SQLite;按节拍统一上传) */
 	private final List<Map<String, String>> sampleBuf = new ArrayList<Map<String, String>>();
@@ -148,7 +154,7 @@ public class PressPanel extends JPanel {
 		txtBatch = roField();
 		txtProduced = roField();
 		batchGrid.add(UiTheme.paramTile("批次码", txtBatch, UiTheme.STRIPE_SIDE));
-		batchGrid.add(UiTheme.paramTile("本机已产", txtProduced, UiTheme.STRIPE_SIDE));
+		batchGrid.add(UiTheme.paramTile("本批冲次", txtProduced, UiTheme.STRIPE_SIDE));
 		UiTheme.markTileValueBase(txtProduced, UiTheme.FONT_SN.getSize2D());
 		batchCard.add(batchGrid, BorderLayout.CENTER);
 
@@ -171,7 +177,8 @@ public class PressPanel extends JPanel {
 		txtAir = showAirCushion ? roField() : null;
 		txtEjector = showEjectorStroke ? roField() : null;
 		txtEnergy = roField();
-		grid.add(UiTheme.paramTile("冲次数量", txtStroke, UiTheme.STRIPE_SIDE));
+		// PLC 累计冲次(示值);本批数量见上方「本机已产」
+		grid.add(UiTheme.paramTile("PLC累计冲次", txtStroke, UiTheme.STRIPE_SIDE));
 		grid.add(UiTheme.paramTile("生产高度", txtDieHeight, UiTheme.STRIPE_SIDE));
 		grid.add(UiTheme.paramTile("顶缸压力", txtCylinder, UiTheme.STRIPE_SIDE));
 		grid.add(UiTheme.paramTile("生产吨位", txtTonnage, UiTheme.STRIPE_SIDE));
@@ -250,9 +257,10 @@ public class PressPanel extends JPanel {
 				return;
 			}
 
-			// 批次变化:空→有=认领(保留冲次);有→有且不同=换批冲刷;其它重定起点
+			// 批次变化:已有本批进度的空→有=认领保留;其余(含开会话跟随)重定冲次起点
 			if (!batch.equalsIgnoreCase(boundBatchCode)) {
-				boolean claimOnly = boundBatchCode.isEmpty() && !batch.isEmpty();
+				boolean claimOnly = boundBatchCode.isEmpty() && !batch.isEmpty()
+						&& (baseStrokeReady || producedQty > 0);
 				boolean realSwitch = !boundBatchCode.isEmpty() && !batch.isEmpty();
 				if (realSwitch) {
 					// 短等刷旧批,降低能耗汇总点因异步失败被丢的概率
@@ -267,26 +275,21 @@ public class PressPanel extends JPanel {
 					producedQty = 0;
 					baseStrokeCount = 0L;
 					lastStrokeCount = 0L;
+					baseStrokeReady = false;
 					resetEnergyAccum();
-					if (plc.isConnected() && snap != null && !nvl(snap.strokeCountText).isEmpty()) {
-						baseStrokeCount = snap.strokeCount;
-						lastStrokeCount = snap.strokeCount;
-						log.info("压机[{}] 跟随开会话 batch={} baseStroke={}",
-								Integer.valueOf(cfg.getPressNo()), batch, Long.valueOf(baseStrokeCount));
-					}
+					armBaseStrokeFromSnap(snap);
 				}
-			} else if (baseStrokeCount == 0L && lastStrokeCount == 0L
-					&& plc.isConnected() && snap != null && !nvl(snap.strokeCountText).isEmpty()) {
-				// 开会话时 PLC 未连上,稍后补记起点
-				baseStrokeCount = snap.strokeCount;
-				lastStrokeCount = snap.strokeCount;
+			} else if (!baseStrokeReady) {
+				// 开会话时 PLC 未连上 / 未读到冲次,稍后补记起点
+				armBaseStrokeFromSnap(snap);
 			}
 
 			// 本批运行中:按设备运行 BOOL 累计时间并估算能耗
 			updateEnergyByRunState(snap, true);
 			refreshSnapshotUi(snap);
 
-			if (plc.isConnected() && snap != null && !nvl(snap.strokeCountText).isEmpty()) {
+			if (baseStrokeReady && plc.isConnected() && snap != null
+					&& !nvl(snap.strokeCountText).isEmpty()) {
 				updateProducedAgainstStroke(snap.strokeCount);
 			}
 			DcLineBatchContext.setPressProduced(cfg.getPressNo(), producedQty);
@@ -362,12 +365,33 @@ public class PressPanel extends JPanel {
 		baseStrokeCount = 0L;
 		lastStrokeCount = 0L;
 		producedQty = 0;
+		baseStrokeReady = false;
 		boundBatchCode = "";
 		clearSampleBuf();
 		resetEnergyAccum();
 		DcLineBatchContext.setPressProduced(cfg.getPressNo(), 0);
 	}
 
+	/**
+	 * 用当前快照标定本批冲次起点;成功后才累计「本批数量」。
+	 *
+	 * @return 是否已标定
+	 */
+	private boolean armBaseStrokeFromSnap(DcPressSnapshot snap) {
+		if (baseStrokeReady) {
+			return true;
+		}
+		if (!plc.isConnected() || snap == null || nvl(snap.strokeCountText).isEmpty()) {
+			return false;
+		}
+		baseStrokeCount = snap.strokeCount;
+		lastStrokeCount = snap.strokeCount;
+		baseStrokeReady = true;
+		log.info("压机[{}] 标定本批冲次起点 batch={} baseStroke={}",
+				Integer.valueOf(cfg.getPressNo()), boundBatchCode, Long.valueOf(baseStrokeCount));
+		return true;
+	}
+
 	/** 清空内存采样缓冲 */
 	private void clearSampleBuf() {
 		synchronized (sampleBuf) {
@@ -634,8 +658,11 @@ public class PressPanel extends JPanel {
 		}
 	}
 
-	/** 按冲次累计本批已产;冲次变小则保留已产并重定起点 */
+	/** 按冲次累计本批已产(冲次差);未标定起点不累计;冲次变小则保留已产并重定起点 */
 	private void updateProducedAgainstStroke(long strokeCount) {
+		if (!baseStrokeReady) {
+			return;
+		}
 		if (strokeCount < lastStrokeCount) {
 			int kept = producedQty;
 			baseStrokeCount = strokeCount - kept;

+ 2 - 2
src/main/java/com/mes/ui/StationPanel.java

@@ -268,7 +268,7 @@ public class StationPanel extends JPanel {
 		grid.add(UiTheme.paramTile("产线状态", txtLineState, UiTheme.STRIPE_SIDE));
 		grid.add(UiTheme.paramTile("本批已产", txtProduced, UiTheme.STRIPE_SIDE));
 		UiTheme.markTileValueBase(txtProduced, UiTheme.FONT_SN.getSize2D());
-		grid.add(UiTheme.paramTile("五台冲次数量进度", txtPressProgress, UiTheme.STRIPE_SIDE));
+		grid.add(UiTheme.paramTile("五台本批冲次进度", txtPressProgress, UiTheme.STRIPE_SIDE));
 		UiTheme.markTileValueBase(txtPressProgress, UiTheme.FONT_BODY.getSize2D());
 		runCard.add(grid, BorderLayout.CENTER);
 
@@ -1737,7 +1737,7 @@ public class StationPanel extends JPanel {
 		refreshMesAllowLampFromPlc();
 	}
 
-	/** 刷新主界面「五台冲次进度」汇总 */
+	/** 刷新主界面「五台本批冲次进度」(各台本批冲次差,非 PLC 总冲次) */
 	private void refreshPressProgressUi() {
 		if (phase != Phase.RUN) {
 			return;