zxl 3 هفته پیش
والد
کامیت
bb6ab01279

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

@@ -0,0 +1,137 @@
+# 自动化大冲:主界面 DB260 取批;五台压机跟批次采点;压机5冲次数量达标 → 打印结案
+# 五台与线体共用同一工位号(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: 500
+  # 压机采样周期(毫秒) / 缓冲满多少点上报一次
+  press-sample-ms: 1000
+  press-upload-max: 20
+  # 结案小票连接的系统打印机名;空=用 Windows 默认打印机
+  printer-name:
+  # 是否写 PLC MES允许运行点。false=开批/结案/清码都不写,本地仍取批盯产量
+  mes-allow-enabled: false
+
+  # 线体主站(唯一取码工位;五台压机共用此工位号)
+  stations:
+    - id: 1
+      title: 自动化大冲
+      station-sn: DC01
+      plc-ip: 192.168.17.1
+      plc-port: 102
+      # MES允许运行 BOOL(例:DB260.200.0);空则只本地开批不写 PLC
+      mes-allow-addr: DB260.141.0
+
+  # =====================================================================
+  # 五台压机过程页:不取码、不单独占工位;压机5「冲次数量」达标触发主界面打印结案
+  # 点表全称 ↔ yml 配置项(地址按 S7 写法,例 DB3.168):
+  #   冲次数量     → stroke-count-addr       (UDINT;本批进度差;压机5结案看此点)
+  #   生产高度     → die-height-addr         (REAL)
+  #   顶缸压力     → cylinder-pressure-addr  (REAL)
+  #   生产吨位     → tonnage-addr            (REAL 或 DINT,由 tonnage-dint 决定)
+  #   压机行程次数 → press-spm-addr          (REAL)
+  #   气垫风压     → air-cushion-addr        (REAL;无机型则留空)
+  #   顶杆行程     → ejector-stroke-addr     (REAL;无机型则留空)
+  #   能耗         → energy-addr             (DINT;无机型则留空)
+  # 另: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                # 气垫风压(无则留空)
+      ejector-stroke-addr: DB142.18             # 顶杆行程(无则留空)
+      energy-addr:                     # 能耗(无则留空)
+      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:                # 气垫风压(无则留空)
+      ejector-stroke-addr:             # 顶杆行程(无则留空)
+      energy-addr:                     # 能耗(无则留空)
+      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:             # 顶杆行程(无则留空)
+      energy-addr:                     # 能耗(无则留空)
+      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:             # 顶杆行程(无则留空)
+      energy-addr:                     # 能耗(无则留空)
+      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:             # 顶杆行程(无则留空)
+      energy-addr:                     # 能耗(无则留空)
+      device-run-addr: DB395.6.0                 # 设备运行 BOOL

BIN
pack/dist/mesclient-dachong.exe


+ 15 - 0
src/main/java/com/mes/config/MesClientProperties.java

@@ -30,6 +30,12 @@ public class MesClientProperties {
 	 * 结案小票连接的系统打印机名称;空则用 Windows 默认打印机。
 	 */
 	private String printerName = "";
+	/**
+	 * 是否写 PLC MES 允许运行点。
+	 * false:开批/结案/清码都不写允许信号,本地仍可取批盯产量。
+	 * yml:{@code mes-allow-enabled}
+	 */
+	private boolean mesAllowEnabled = true;
 	/** 线体工位列表(一般一条:DB260 主界面) */
 	private List<StationConfig> stations = new ArrayList<StationConfig>();
 	/** 五台压机过程采集配置(IP/点位后补) */
@@ -321,6 +327,15 @@ public class MesClientProperties {
 		this.printerName = printerName;
 	}
 
+	/** 是否写 PLC MES 允许运行点 */
+	public boolean isMesAllowEnabled() {
+		return mesAllowEnabled;
+	}
+
+	public void setMesAllowEnabled(boolean mesAllowEnabled) {
+		this.mesAllowEnabled = mesAllowEnabled;
+	}
+
 	public List<StationConfig> getStations() {
 		return stations;
 	}

+ 40 - 0
src/main/java/com/mes/service/DcBatchPrinter.java

@@ -28,16 +28,32 @@ import java.util.Map;
 /**
  * 批次结案小票:上方居中批次码二维码,下方居中批次码文字。
  * 打印机名由 yml {@code mes.printer-name} 指定;空则用系统默认打印机。
+ * 界面「设置 → 打印」开关控制是否真正送打;勾选状态本地记住。
  */
 public final class DcBatchPrinter {
 
 	private static final Logger log = LoggerFactory.getLogger(DcBatchPrinter.class);
 
+	/** Preferences 节点:记住「打印」开关 */
+	private static final String PREF_NODE = "com.mes.dachong";
+	private static final String PREF_PRINT_ENABLED = "printEnabled";
+
 	/** 二维码边长(像素,按可打印宽度再裁) */
 	private static final int QR_PREF_PX = 200;
 
 	/** 目标打印机名称(空=默认打印机) */
 	private static volatile String printerName = "";
+	/** 界面「打印」开关;默认开 */
+	private static volatile boolean printEnabled = true;
+
+	static {
+		try {
+			printEnabled = java.util.prefs.Preferences.userRoot()
+					.node(PREF_NODE).getBoolean(PREF_PRINT_ENABLED, true);
+		} catch (Exception ignored) {
+			printEnabled = true;
+		}
+	}
 
 	private DcBatchPrinter() {
 	}
@@ -47,8 +63,28 @@ public final class DcBatchPrinter {
 		printerName = name == null ? "" : name.trim();
 	}
 
+	/** 当前是否允许结案打印(设置菜单「打印」) */
+	public static boolean isPrintEnabled() {
+		return printEnabled;
+	}
+
+	/**
+	 * 设置是否打印,并写入本机 Preferences(重启仍有效)。
+	 */
+	public static void setPrintEnabled(boolean enabled) {
+		printEnabled = enabled;
+		try {
+			java.util.prefs.Preferences.userRoot().node(PREF_NODE)
+					.putBoolean(PREF_PRINT_ENABLED, enabled);
+		} catch (Exception e) {
+			log.warn("保存打印开关失败: {}", e.getMessage());
+		}
+		log.info("打印开关={}", Boolean.valueOf(enabled));
+	}
+
 	/**
 	 * 连接打印机并送打批次码小票(上二维码、下批次码,均居中)。
+	 * 开关关闭时直接跳过并返回 false。
 	 *
 	 * @param batchCode 批次码(二维码内容与下方文字)
 	 * @param produceTime 保留入参兼容调用方(本版小票不印)
@@ -56,6 +92,10 @@ public final class DcBatchPrinter {
 	 * @return 是否送打印成功
 	 */
 	public static boolean printBatch(final String batchCode, final String produceTime, final int qty) {
+		if (!printEnabled) {
+			log.info("打印开关已关,跳过送打 batch={}", batchCode == null ? "" : batchCode.trim());
+			return false;
+		}
 		final String code = batchCode == null ? "" : batchCode.trim();
 		if (code.isEmpty()) {
 			log.warn("批次码为空,跳过打印");

+ 23 - 1
src/main/java/com/mes/service/DcPlcClient.java

@@ -22,6 +22,8 @@ public class DcPlcClient {
 	private final int plcPort;
 	/** MES 允许运行 BOOL,空则只打日志不写 PLC */
 	private final String mesAllowAddr;
+	/** 总开关:false 时 setMesAllow 直接跳过,不发开/关 */
+	private final boolean mesAllowEnabled;
 
 	private S7PLC plc;
 	private volatile boolean connected;
@@ -29,10 +31,24 @@ public class DcPlcClient {
 	private volatile long currentRetryDelayMs = RETRY_INITIAL_MS;
 
 	public DcPlcClient(String stationSn, String plcIp, int plcPort, String mesAllowAddr) {
+		this(stationSn, plcIp, plcPort, mesAllowAddr, true);
+	}
+
+	/**
+	 * @param mesAllowEnabled false=完全不写 MES 允许点(开批/结案/清码都跳过)
+	 */
+	public DcPlcClient(String stationSn, String plcIp, int plcPort, String mesAllowAddr,
+			boolean mesAllowEnabled) {
 		this.stationSn = stationSn == null ? "" : stationSn.trim();
 		this.plcIp = plcIp == null ? "" : plcIp.trim();
 		this.plcPort = plcPort <= 0 ? 102 : plcPort;
 		this.mesAllowAddr = mesAllowAddr == null ? "" : mesAllowAddr.trim();
+		this.mesAllowEnabled = mesAllowEnabled;
+	}
+
+	/** 是否允许写 MES 允许点(yml mes-allow-enabled) */
+	public boolean isMesAllowEnabled() {
+		return mesAllowEnabled;
 	}
 
 	public String getStationSn() {
@@ -100,9 +116,15 @@ public class DcPlcClient {
 	}
 
 	/**
-	 * 写 MES 允许运行。点未配置时返回 false(业务仍可本地走完,便于联调)。
+	 * 写 MES 允许运行。
+	 * 开关关闭或点未配置时返回 false(业务仍可本地走完,便于联调)。
 	 */
 	public boolean setMesAllow(boolean allow) {
+		if (!mesAllowEnabled) {
+			log.debug("工位[{}] mes-allow-enabled=false,跳过写 PLC allow={}",
+					stationSn, Boolean.valueOf(allow));
+			return false;
+		}
 		if (mesAllowAddr.isEmpty()) {
 			log.warn("工位[{}] mes-allow-addr 未配置,跳过写 PLC allow={}", stationSn, Boolean.valueOf(allow));
 			return false;

+ 40 - 2
src/main/java/com/mes/service/DcPressPlcClient.java

@@ -102,7 +102,8 @@ public class DcPressPlcClient {
 				s.strokeCountText = String.valueOf(stroke);
 			}
 			s.dieHeight = readFloatText(cfg.getDieHeightAddr());
-			s.cylinderPressure = readFloatText(cfg.getCylinderPressureAddr());
+			// 顶缸压力:界面/上报保留两位小数
+			s.cylinderPressure = readFloatText(cfg.getCylinderPressureAddr(), 2);
 			String tonAddr = nvl(cfg.getTonnageAddr());
 			if (!tonAddr.isEmpty()) {
 				if (cfg.isTonnageDint()) {
@@ -111,7 +112,8 @@ public class DcPressPlcClient {
 					s.tonnage = fmtFloat(plc.readFloat32(tonAddr));
 				}
 			}
-			s.pressSpm = readFloatText(cfg.getPressSpmAddr());
+			// 压机行程次数:REAL 读后四舍五入成整数
+			s.pressSpm = readFloatAsInt(cfg.getPressSpmAddr());
 			s.airCushion = readFloatText(cfg.getAirCushionAddr());
 			s.ejectorStroke = readFloatText(cfg.getEjectorStrokeAddr());
 			// 能耗 DINT
@@ -152,6 +154,23 @@ public class DcPressPlcClient {
 		return fmtFloat(plc.readFloat32(addr.trim()));
 	}
 
+	/** 读 REAL 并按小数位格式化;scale&lt;0 走去尾零 */
+	private String readFloatText(String addr, int scale) {
+		if (isBlank(addr) || plc == null) {
+			return "";
+		}
+		float v = plc.readFloat32(addr.trim());
+		return scale >= 0 ? fmtFloatScale(v, scale) : fmtFloat(v);
+	}
+
+	/** 读 REAL 后四舍五入为整数串 */
+	private String readFloatAsInt(String addr) {
+		if (isBlank(addr) || plc == null) {
+			return "";
+		}
+		return fmtInt(plc.readFloat32(addr.trim()));
+	}
+
 	private boolean ensurePlc() {
 		if (isConnected()) {
 			return true;
@@ -209,4 +228,23 @@ public class DcPressPlcClient {
 		}
 		return s;
 	}
+
+	/** 固定小数位(如顶缸压力 2 位) */
+	private static String fmtFloatScale(float v, int scale) {
+		if (Float.isNaN(v) || Float.isInfinite(v)) {
+			return "";
+		}
+		if (scale < 0) {
+			return fmtFloat(v);
+		}
+		return String.format(java.util.Locale.US, "%." + scale + "f", Float.valueOf(v));
+	}
+
+	/** REAL → 四舍五入整数 */
+	private static String fmtInt(float v) {
+		if (Float.isNaN(v) || Float.isInfinite(v)) {
+			return "";
+		}
+		return String.valueOf(Math.round(v));
+	}
 }

+ 17 - 0
src/main/java/com/mes/ui/MainFrame.java

@@ -33,6 +33,8 @@ public class MainFrame extends JFrame {
 
 	public static String mes_server_ip = "";
 	public static String mes_app_title = "MES 自动化大冲";
+	/** 是否写 PLC MES 允许运行点;false=跳过开/关允许 */
+	public static boolean mes_allow_enabled = true;
 
 	private static MesClientProperties props;
 	private static final List<StationPanel> stationPanels = new ArrayList<StationPanel>();
@@ -115,7 +117,9 @@ public class MainFrame extends JFrame {
 			mes_app_title = "MES 自动化大冲";
 		}
 		DcBatchPrinter.setPrinterName(p.getPrinterName());
+		mes_allow_enabled = p.isMesAllowEnabled();
 		log.info("打印机配置 name={}", trim(p.getPrinterName()).isEmpty() ? "(系统默认)" : trim(p.getPrinterName()));
+		log.info("MES允许开关 mes-allow-enabled={}", Boolean.valueOf(mes_allow_enabled));
 		List<MesClientProperties.StationConfig> list = p.getStations();
 		if (list == null || list.isEmpty()) {
 			log.warn("mes.stations 为空");
@@ -341,9 +345,22 @@ public class MainFrame extends JFrame {
 		});
 		settingsMenu.add(miNext);
 		settingsMenu.add(miManual);
+		settingsMenu.addSeparator();
+		// 设置 → 打印:勾选=结案送打,取消=不打印;状态本机记住
+		final JCheckBoxMenuItem miPrint = new JCheckBoxMenuItem("打印");
+		miPrint.setFont(new Font("微软雅黑", Font.PLAIN, 14));
+		miPrint.setSelected(DcBatchPrinter.isPrintEnabled());
+		miPrint.addActionListener(new ActionListener() {
+			@Override
+			public void actionPerformed(ActionEvent e) {
+				DcBatchPrinter.setPrintEnabled(miPrint.isSelected());
+			}
+		});
+		settingsMenu.add(miPrint);
 		btnSettings.addActionListener(new ActionListener() {
 			@Override
 			public void actionPerformed(ActionEvent e) {
+				miPrint.setSelected(DcBatchPrinter.isPrintEnabled());
 				settingsMenu.show(btnSettings, 0, btnSettings.getHeight());
 			}
 		});

+ 28 - 6
src/main/java/com/mes/ui/StationPanel.java

@@ -48,6 +48,8 @@ public class StationPanel extends JPanel {
 
 	private volatile Phase phase = Phase.IDLE;
 	private volatile String batchCode = "";
+	/** 本件结案工号:优先 nextBatch 带回的入队 userCode */
+	private volatile String currentUserCode = "";
 	private volatile int targetQty;
 	/** 开批时 PLC 实际产量起点;中途复位后会按已产重定 */
 	private volatile int baseActualQty;
@@ -106,8 +108,9 @@ public class StationPanel extends JPanel {
 	public StationPanel(MesClientProperties.StationConfig cfg, String serverIp) {
 		this.cfg = cfg;
 		this.serverIp = serverIp == null ? "" : serverIp.trim();
+		// mes-allow-enabled=false 时开批/结案/清码都不写 PLC 允许点
 		this.plc = new DcPlcClient(cfg.getStationSn(), cfg.getPlcIp(), cfg.getPlcPort(),
-				cfg.getMesAllowAddr());
+				cfg.getMesAllowAddr(), MainFrame.mes_allow_enabled);
 
 		setLayout(new BorderLayout(0, 0));
 		setBackground(UiTheme.BG);
@@ -430,9 +433,13 @@ public class StationPanel extends JPanel {
 						log.warn("工位[{}] nextBatch 成功但缺 batchCode/targetQty: {}", cfg.getStationSn(), ret);
 						return;
 					}
-					log.info("工位[{}] nextBatch 成功 batch={} target={}",
-							cfg.getStationSn(), code, Integer.valueOf(target));
-					startBatchFromPda(code, target);
+					String queueUser = MesDcApiClient.dataStr(ret, "userCode");
+					if (queueUser.isEmpty()) {
+						queueUser = MesDcApiClient.dataStr(ret, "ucode");
+					}
+					log.info("工位[{}] nextBatch 成功 batch={} target={} userCode={}",
+							cfg.getStationSn(), code, Integer.valueOf(target), queueUser);
+					startBatchFromPda(code, target, queueUser);
 				} finally {
 					nextBusy.set(false);
 				}
@@ -442,8 +449,10 @@ public class StationPanel extends JPanel {
 
 	/**
 	 * 批次到位:记起点产量 → MES允许=true → 进入 RUN;本批做完再写 false。
+	 *
+	 * @param queueUserCode PDA 入队工号(可空)
 	 */
-	private void startBatchFromPda(String code, int target) {
+	private void startBatchFromPda(String code, int target, String queueUserCode) {
 		// DONE 挂起续传中禁止再开批,避免冲掉待上传结案
 		if (phase == Phase.RUN || phase == Phase.DONE) {
 			return;
@@ -465,6 +474,7 @@ public class StationPanel extends JPanel {
 				baseQty = base.intValue();
 			}
 			batchCode = code;
+			currentUserCode = queueUserCode == null ? "" : queueUserCode.trim();
 			targetQty = target;
 			baseActualQty = baseQty;
 			lastActualQty = baseActualQty;
@@ -479,7 +489,15 @@ public class StationPanel extends JPanel {
 			setText(txtTarget, String.valueOf(targetQty));
 			setText(txtProduced, "0");
 			setMesAllowLamp(wrote);
-			String tip = wrote ? "批次已开,MES允许已写" : "批次已开(允许点未配/写失败)";
+			// 开批提示:区分开关关 / 点未配或写失败
+			String tip;
+			if (wrote) {
+				tip = "批次已开,MES允许已写";
+			} else if (!plc.isMesAllowEnabled()) {
+				tip = "批次已开(MES允许开关已关,未写PLC)";
+			} else {
+				tip = "批次已开(允许点未配/写失败)";
+			}
 			if (base == null) {
 				tip = tip + "  PLC产量未读到,起点=0";
 			} else {
@@ -657,6 +675,9 @@ public class StationPanel extends JPanel {
 					fields.put("aborted", aborted ? "1" : "0");
 					fields.put("manual", manual ? "1" : "0");
 					fields.put("result", passResult);
+					// 结案工号:取批时队列带回的入队工号;空则 system
+					String jobUser = currentUserCode == null ? "" : currentUserCode.trim();
+					fields.put("userCode", jobUser.isEmpty() ? "system" : jobUser);
 					fields.put("currentPart", nvl(snap.currentPart));
 					fields.put("nextPart", nvl(snap.nextPart));
 					fields.put("actualQty", String.valueOf(snap.actualQty));
@@ -800,6 +821,7 @@ public class StationPanel extends JPanel {
 	private void resetToIdle(String msg) {
 		phase = Phase.IDLE;
 		batchCode = "";
+		currentUserCode = "";
 		targetQty = 0;
 		baseActualQty = 0;
 		producedQty = 0;

+ 3 - 1
src/main/resources/config/application.yml

@@ -15,13 +15,15 @@ logging:
 
 mes:
   app-title: MES 自动化大冲
-  server-ip: 127.0.0.1
+  server-ip: 192.168.9.19
   tick-ms: 500
   # 压机采样周期(毫秒) / 缓冲满多少点上报一次
   press-sample-ms: 1000
   press-upload-max: 20
   # 结案小票连接的系统打印机名;空=用 Windows 默认打印机
   printer-name:
+  # 是否写 PLC MES允许运行点。false=开批/结案/清码都不写,本地仍取批盯产量
+  mes-allow-enabled: false
 
   # 线体主站(唯一取码工位;五台压机共用此工位号)
   stations: