ソースを参照

V3协议+参数为空不采集

wangxichen 3 日 前
コミット
35470665af

+ 18 - 3
src/com/mes/netty/MesMsgUtils.java

@@ -3,14 +3,15 @@ package com.mes.netty;
 public class MesMsgUtils {
 
     // 协议 v2(2026-06-29):oprno 字段从 6 字符扩到 8 字符,所有长度 +2
+    // 协议 v3(2026-07-13):LX 字段从 2 字符扩到 3 字符(支持 INSPXXX),AQDW/MQDW 长度 +1
     public static int SYNR_LEN = 48;
     public static int AXTW_LEN = 48;
     public static int ACLW_LEN = 48;
     public static int MCJW_LEN = 98;
-    public static int AQDW_LEN = 98;
+    public static int AQDW_LEN = 99;
     public static int MBDW_LEN = 98;
     public static int MJBW_LEN = 98;
-    public static int MQDW_LEN = 98;
+    public static int MQDW_LEN = 99;
     public static int MKSW_LEN = 96;
     public static int MSBW_LEN = 96;
     public static int MCSW_LEN = 96;
@@ -51,13 +52,27 @@ public class MesMsgUtils {
                     ret = 2;
                 }
                 break;
-            default:
+            case "AQDW":
                 if(len==AQDW_LEN) {
                     ret = 0;
                 }else {
                     ret = 2;
                 }
                 break;
+            case "MQDW":
+                if(len==MQDW_LEN) {
+                    ret = 0;
+                }else {
+                    ret = 2;
+                }
+                break;
+            default:
+                if(len==MCJW_LEN) {
+                    ret = 0;
+                }else {
+                    ret = 2;
+                }
+                break;
         }
         return ret;
     }

+ 10 - 9
src/com/mes/netty/ProtocolParam.java

@@ -3,9 +3,10 @@ package com.mes.netty;
 
 // 固定格式报文各参数获取方法
 // 协议 v2(2026-06-29 修订):oprno 字段从 6 字符扩到 8 字符,后续字段偏移整体 +2
+// 协议 v3(2026-07-13 修订):LX 字段从 2 字符扩到 3 字符(支持 INSPXXX),后续字段偏移整体 +1
 public class ProtocolParam {
     // bbbbfffffARWAQDWGWOP100   GY100000ID151245P00000106200123062900001      RSOKDA2023-09-07ZT10:16:58
-    public static Integer fixedLength = 98;
+    public static Integer fixedLength = 99;
 
     public static String getMsgType(String msg){
         System.out.print(msg);
@@ -37,31 +38,31 @@ public class ProtocolParam {
     }
 
     public static String getLx(String msg){
-        if(msg.length() < 74){
+        if(msg.length() < 75){
             return "";
         }
-        return msg.substring(72,74);
+        return msg.substring(72,75).trim();
     }
 
     public static String getResult(String msg){
-        if(msg.length() < 76){
+        if(msg.length() < 77){
             return "";
         }
-        return msg.substring(74,76);
+        return msg.substring(75,77);
     }
 
     public static String getDay(String msg){
-        if(msg.length() < 88){
+        if(msg.length() < 89){
             return "";
         }
-        return msg.substring(78,88);
+        return msg.substring(79,89);
     }
 
     public static String getTime(String msg){
-        if(msg.length() < 98){
+        if(msg.length() < 99){
             return "";
         }
-        return msg.substring(90,98);
+        return msg.substring(91,99);
     }
 
 }

+ 13 - 5
src/com/mes/netty/XDecoder.java

@@ -135,18 +135,26 @@ public class XDecoder extends ByteToMessageDecoder {
                     tpsize = MesMsgUtils.ACLW_LEN;
                 }
                 break;
-            case "MCJW":
             case "AQDW":
+                if(str.length() >= MesMsgUtils.AQDW_LEN){
+                    tpsize = MesMsgUtils.AQDW_LEN;
+                }
+                break;
+            case "MQDW":
+                if(str.length() >= MesMsgUtils.MQDW_LEN){
+                    tpsize = MesMsgUtils.MQDW_LEN;
+                }
+                break;
+            case "MCJW":
             case "MBDW":
             case "MJBW":
-            case "MQDW":
             case "MKSW":
             case "MSBW":
             case "MCSW":
             case "AQRW":
-            default: // 默认新报文
-                if(str.length() >= ProtocolParam.fixedLength){ // 大于固定长度
-                    tpsize = ProtocolParam.fixedLength;
+            default: // default new packet
+                if(str.length() >= MesMsgUtils.MCJW_LEN){
+                    tpsize = MesMsgUtils.MCJW_LEN;
                 }
                 break;
         }

+ 36 - 0
src/com/mes/test/PlcSignalTest.java

@@ -0,0 +1,36 @@
+package com.mes.test;
+
+import com.mes.ui.PlcSignalPanel;
+
+import javax.swing.*;
+
+/**
+ * OP50 PLC 信号监控测试工具
+ * 独立运行,不依赖 MES 服务器,直连 S7-1200 查看和控制 DB200 点位
+ *
+ * 使用方法:
+ * 1. 直接运行 main 方法(默认 IP: 192.168.1.1)
+ * 2. 命令行指定 IP: java PlcSignalTest 192.168.1.100
+ */
+public class PlcSignalTest {
+
+    public static void main(String[] args) {
+        // 设置系统外观
+        try {
+            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
+        } catch (Exception e) {
+            System.err.println("设置外观失败: " + e.getMessage());
+        }
+
+        // 默认 IP,命令行参数可覆盖
+        final String defaultIp = (args.length > 0 && !args[0].trim().isEmpty())
+                ? args[0].trim()
+                : "192.168.1.1";
+
+        SwingUtilities.invokeLater(() -> {
+            PlcSignalPanel panel = new PlcSignalPanel(defaultIp);
+            panel.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // 独立运行时真正退出
+            panel.setVisible(true);
+        });
+    }
+}

+ 7 - 2
src/com/mes/ui/PlcUtil.java

@@ -105,9 +105,14 @@ public class PlcUtil {
                 sn = MesClient.curSnb;
             }
 
+            // 检查工件码和参数列表都不为空
             if (sn != null && !sn.trim().isEmpty()) {
-                JdbcUtils.insertCmtData(oprno, MesClient.mes_line_sn, sn, JSON.toJSONString(MesClient.hjparams));
-                System.out.println("cmt:" + MesClient.curFlag + " sn:" + sn);
+                if (MesClient.hjparams != null && !MesClient.hjparams.isEmpty()) {
+                    JdbcUtils.insertCmtData(oprno, MesClient.mes_line_sn, sn, JSON.toJSONString(MesClient.hjparams));
+                    System.out.println("cmt:" + MesClient.curFlag + " sn:" + sn + " params_count:" + MesClient.hjparams.size());
+                } else {
+                    System.out.println("weld params is empty, skip save (sn:" + sn + ")");
+                }
             } else {
                 System.out.println("workpiece sn is empty, skip cmt params save");
             }

+ 18 - 2
src/com/mes/util/ErrorMsg.java

@@ -11,9 +11,9 @@ public class ErrorMsg {
             }else if(processMsgRet.equalsIgnoreCase("NN")) {
                 lmsg = "该工件跳过该工位";
             }else if(processMsgRet.equalsIgnoreCase("QN")) {
-                lmsg = "该工件OP"+ lx+"0加工NG";
+                lmsg = "该工件"+ getOprnoName(lx)+"加工NG";
             }else if(processMsgRet.equalsIgnoreCase("QD")) {
-                lmsg = "该工件OP"+ lx+"0未加工";
+                lmsg = "该工件"+ getOprnoName(lx)+"未加工";
             }else if(processMsgRet.equalsIgnoreCase("NF")) {
                 lmsg = "该工件已合格下线";
             }else if(processMsgRet.equalsIgnoreCase("NR")) {
@@ -46,4 +46,20 @@ public class ErrorMsg {
         }catch (Exception e){ }
         return lmsg;
     }
+
+    private static String getOprnoName(String lx) {
+        if (lx == null) {
+            return "OP";
+        }
+        lx = lx.trim();
+        if (lx.startsWith("I")) {
+            try {
+                int num = Integer.parseInt(lx.substring(1)) * 10;
+                return String.format("INSP%03d", num);
+            } catch (Exception e) {
+                return "INSP" + lx.substring(1);
+            }
+        }
+        return "OP" + lx + "0";
+    }
 }