张田野 1 týždeň pred
rodič
commit
e33034301c

+ 28 - 9
src/com/mes/ui/ErrorMsg.java

@@ -8,7 +8,17 @@ public class ErrorMsg {
         try{
             String msg_type = ProtocolParam.getMsgType(mes_msg);
             String processMsgRet = MesMsgUtils.processMsg(mes_msg, msg_type);
-            String lmsg = "该工件本工位不可加工";
+            String lx = ProtocolParam.getLx(mes_msg);
+            MesClient.setMenuStatus(getErrorMsg(processMsgRet, lx), -1);
+        }catch (Exception e){
+            MesClient.setMenuStatus("未知错误",-1);
+        }
+    }
+
+    /** 与 mescloud ErrorMsg / 质量查询返回码对齐 */
+    public static String getErrorMsg(String processMsgRet, String lx){
+        String lmsg = "该工件本工位不可加工";
+        try{
             if(processMsgRet.equalsIgnoreCase("OK")||processMsgRet.equalsIgnoreCase("NG")) {
                 lmsg = "该工件本工位已加工,结果:"+processMsgRet;
             }else if(processMsgRet.equalsIgnoreCase("NE")) {
@@ -16,9 +26,9 @@ public class ErrorMsg {
             }else if(processMsgRet.equalsIgnoreCase("NN")) {
                 lmsg = "该工件跳过该工位";
             }else if(processMsgRet.equalsIgnoreCase("QN")) {
-                lmsg = "该工件OP"+ ProtocolParam.getLx(mes_msg)+"0加工NG";
+                lmsg = "该工件OP"+ lx+"0加工NG";
             }else if(processMsgRet.equalsIgnoreCase("QD")) {
-                lmsg = "该工件OP"+ ProtocolParam.getLx(mes_msg)+"0未加工";
+                lmsg = "该工件OP"+ lx+"0未加工";
             }else if(processMsgRet.equalsIgnoreCase("NF")) {
                 lmsg = "该工件已合格下线";
             }else if(processMsgRet.equalsIgnoreCase("NR")) {
@@ -31,6 +41,8 @@ public class ErrorMsg {
                 lmsg = "首件检查工件不合格停机";
             }else if(processMsgRet.equalsIgnoreCase("GN")) {
                 lmsg = "更换配件首件检查不合格停机";
+            }else if(processMsgRet.equalsIgnoreCase("CS")) {
+                lmsg = "首件检查两小时内未检查,超时停机";
             }else if(processMsgRet.equalsIgnoreCase("DJ")) {
                 lmsg = "未进行开班点检";
             }else if(processMsgRet.equalsIgnoreCase("BM")) {
@@ -38,16 +50,23 @@ public class ErrorMsg {
             }else if(processMsgRet.equalsIgnoreCase("PL")) {
                 lmsg = "配件寿命不足";
             }else if(processMsgRet.equalsIgnoreCase("QM")) {
-                lmsg = "两次气密必须间隔15分钟";
+                lmsg = "两次气密必须间隔10分钟";
+            }else if(processMsgRet.equalsIgnoreCase("MX")) {
+                lmsg = "气密重复加工次数已达上限";
             }else if(processMsgRet.equalsIgnoreCase("GS")) {
                 lmsg = "工件码格式不正确";
             }else if(processMsgRet.equalsIgnoreCase("CF")) {
                 lmsg = "工件码重复";
+            }else if(processMsgRet.equalsIgnoreCase("SB")) {
+                lmsg = "设备信息不存在";
+            }else if(processMsgRet.equalsIgnoreCase("GH")) {
+                lmsg = "固化时间不足";
+            }else if(processMsgRet.equalsIgnoreCase("PZ")) {
+                lmsg = "未拍照不能提交";
+            }else if(processMsgRet.equalsIgnoreCase("NS")) {
+                lmsg = "服务端处理失败,请重试";
             }
-
-            MesClient.setMenuStatus(lmsg,-1);
-        }catch (Exception e){
-            MesClient.setMenuStatus("未知错误",-1);
-        }
+        }catch (Exception e){ }
+        return lmsg;
     }
 }

+ 87 - 21
src/com/mes/ui/GunConfigFrame.java

@@ -9,12 +9,18 @@ import java.awt.event.ActionListener;
 import java.util.regex.Pattern;
 
 /**
- * 启动配置页:工位信息 + 两把拉铆枪 IP / 打铆颗数(无需密码)
+ * 工位 + 拉铆枪配置页。
+ * 启动时弹出一次进入登录;登录后也可从「设置」菜单再次打开修改。
  */
 public class GunConfigFrame extends JFrame {
 
     private static final Pattern IP_PATTERN = Pattern.compile(
             "^((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(25[0-5]|2[0-4]\\d|[01]?\\d\\d?)$");
+    /** 工位号:OP080 或 OP080A */
+    private static final Pattern OPRNO_PATTERN = Pattern.compile("^OP\\d{3}[A-Z]?$");
+
+    /** true=启动进入登录前;false=登录后修改配置 */
+    private final boolean startupMode;
 
     private JTextField gwTxt;
     private JTextField gwDesTxt;
@@ -25,8 +31,14 @@ public class GunConfigFrame extends JFrame {
     private JTextField gunBNumTxt;
 
     public GunConfigFrame() {
-        setTitle("启动配置 - " + nullToEmpty(MesClient.mes_gw) + " " + nullToEmpty(MesClient.mes_gw_des));
-        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+        this(true);
+    }
+
+    public GunConfigFrame(boolean startupMode) {
+        this.startupMode = startupMode;
+        setTitle((startupMode ? "启动配置" : "工位/枪配置") + " - "
+                + nullToEmpty(MesClient.mes_gw) + " " + nullToEmpty(MesClient.mes_gw_des));
+        setDefaultCloseOperation(startupMode ? JFrame.EXIT_ON_CLOSE : JFrame.DISPOSE_ON_CLOSE);
         setResizable(false);
         try {
             setIconImage(Toolkit.getDefaultToolkit().getImage(MesClient.class.getResource("/bg/logo.png")));
@@ -38,7 +50,7 @@ public class GunConfigFrame extends JFrame {
         root.setBackground(new Color(245, 247, 250));
         setContentPane(root);
 
-        JLabel title = new JLabel("启动配置", SwingConstants.CENTER);
+        JLabel title = new JLabel(startupMode ? "启动配置" : "工位 / 枪配置", SwingConstants.CENTER);
         title.setFont(new Font("微软雅黑", Font.BOLD, 28));
         title.setForeground(new Color(33, 37, 41));
         root.add(title, BorderLayout.NORTH);
@@ -60,7 +72,7 @@ public class GunConfigFrame extends JFrame {
         JPanel bottom = new JPanel(new FlowLayout(FlowLayout.CENTER, 16, 0));
         bottom.setOpaque(false);
 
-        JButton enterBtn = new JButton("保存并进入登录");
+        JButton enterBtn = new JButton(startupMode ? "保存并进入登录" : "保存配置");
         enterBtn.setFont(new Font("微软雅黑", Font.PLAIN, 18));
         enterBtn.setPreferredSize(new Dimension(200, 44));
         enterBtn.addActionListener(new ActionListener() {
@@ -69,12 +81,27 @@ public class GunConfigFrame extends JFrame {
                 onEnter();
             }
         });
+        bottom.add(enterBtn);
+
+        if (!startupMode) {
+            JButton cancelBtn = new JButton("取消");
+            cancelBtn.setFont(new Font("微软雅黑", Font.PLAIN, 18));
+            cancelBtn.setPreferredSize(new Dimension(120, 44));
+            cancelBtn.addActionListener(new ActionListener() {
+                @Override
+                public void actionPerformed(ActionEvent e) {
+                    dispose();
+                }
+            });
+            bottom.add(cancelBtn);
+        }
 
-        JLabel tip = new JLabel("工位与枪参数均可修改,保存后写入本地配置");
+        JLabel tip = new JLabel(startupMode
+                ? "工位与枪参数均可修改,保存后写入本地配置"
+                : "修改服务器IP/枪IP后会重新连接PLC;工位号变更后建议重连MES");
         tip.setFont(new Font("微软雅黑", Font.PLAIN, 13));
         tip.setForeground(new Color(108, 117, 125));
 
-        bottom.add(enterBtn);
         JPanel south = new JPanel(new BorderLayout());
         south.setOpaque(false);
         south.add(bottom, BorderLayout.CENTER);
@@ -87,6 +114,13 @@ public class GunConfigFrame extends JFrame {
         setBounds((d.width - width) / 2, (d.height - height) / 2 - 40, width, height);
     }
 
+    /** 登录后打开配置(非模态独立窗) */
+    public static void openForEdit() {
+        GunConfigFrame frame = new GunConfigFrame(false);
+        frame.setVisible(true);
+        frame.toFront();
+    }
+
     private JPanel buildStationPanel() {
         JPanel panel = new JPanel(new GridBagLayout());
         panel.setBackground(Color.WHITE);
@@ -116,7 +150,7 @@ public class GunConfigFrame extends JFrame {
         lc.gridx = 0;
         lc.gridy = row;
         lc.anchor = GridBagConstraints.EAST;
-        lc.insets = new Insets(6, 4, 6, 8);
+        lc.insets = new Insets(8, 4, 8, 8);
         JLabel label = new JLabel(labelText);
         label.setFont(new Font("微软雅黑", Font.PLAIN, 15));
         panel.add(label, lc);
@@ -126,7 +160,7 @@ public class GunConfigFrame extends JFrame {
         fc.gridy = row;
         fc.fill = GridBagConstraints.HORIZONTAL;
         fc.weightx = 1;
-        fc.insets = new Insets(6, 0, 6, 4);
+        fc.insets = new Insets(8, 0, 8, 4);
         JTextField field = new JTextField(20);
         field.setFont(new Font("微软雅黑", Font.PLAIN, 15));
         panel.add(field, fc);
@@ -136,7 +170,6 @@ public class GunConfigFrame extends JFrame {
     private JPanel buildGunPanel(String title, boolean isA) {
         JPanel panel = new JPanel(new GridBagLayout());
         panel.setBackground(Color.WHITE);
-        panel.setPreferredSize(new Dimension(320, 160));
         panel.setBorder(BorderFactory.createCompoundBorder(
                 BorderFactory.createTitledBorder(
                         BorderFactory.createLineBorder(new Color(206, 212, 218)),
@@ -145,14 +178,14 @@ public class GunConfigFrame extends JFrame {
                         TitledBorder.TOP,
                         new Font("微软雅黑", Font.BOLD, 16),
                         new Color(52, 58, 64)),
-                new EmptyBorder(12, 16, 12, 16)));
+                new EmptyBorder(8, 12, 8, 12)));
 
         GridBagConstraints lc = new GridBagConstraints();
         lc.gridx = 0;
         lc.gridy = 0;
         lc.anchor = GridBagConstraints.EAST;
         lc.insets = new Insets(8, 4, 8, 8);
-        JLabel ipLabel = new JLabel("IP地址:");
+        JLabel ipLabel = new JLabel("IP:");
         ipLabel.setFont(new Font("微软雅黑", Font.PLAIN, 15));
         panel.add(ipLabel, lc);
 
@@ -162,19 +195,28 @@ public class GunConfigFrame extends JFrame {
         fc.fill = GridBagConstraints.HORIZONTAL;
         fc.weightx = 1;
         fc.insets = new Insets(8, 0, 8, 4);
-        JTextField ipTxt = new JTextField(16);
+        JTextField ipTxt = new JTextField(14);
         ipTxt.setFont(new Font("微软雅黑", Font.PLAIN, 15));
         panel.add(ipTxt, fc);
 
-        lc.gridy = 1;
-        JLabel numLabel = new JLabel("打铆颗数:");
+        GridBagConstraints lc2 = new GridBagConstraints();
+        lc2.gridx = 0;
+        lc2.gridy = 1;
+        lc2.anchor = GridBagConstraints.EAST;
+        lc2.insets = new Insets(8, 4, 8, 8);
+        JLabel numLabel = new JLabel("颗数:");
         numLabel.setFont(new Font("微软雅黑", Font.PLAIN, 15));
-        panel.add(numLabel, lc);
+        panel.add(numLabel, lc2);
 
-        fc.gridy = 1;
-        JTextField numTxt = new JTextField(16);
+        GridBagConstraints fc2 = new GridBagConstraints();
+        fc2.gridx = 1;
+        fc2.gridy = 1;
+        fc2.fill = GridBagConstraints.HORIZONTAL;
+        fc2.weightx = 1;
+        fc2.insets = new Insets(8, 0, 8, 4);
+        JTextField numTxt = new JTextField(14);
         numTxt.setFont(new Font("微软雅黑", Font.PLAIN, 15));
-        panel.add(numTxt, fc);
+        panel.add(numTxt, fc2);
 
         if (isA) {
             gunAIpTxt = ipTxt;
@@ -191,7 +233,7 @@ public class GunConfigFrame extends JFrame {
     }
 
     private void onEnter() {
-        String gw = gwTxt.getText().trim();
+        String gw = gwTxt.getText().trim().toUpperCase();
         String gwDes = gwDesTxt.getText().trim();
         String serverIp = serverIpTxt.getText().trim();
         String aIp = gunAIpTxt.getText().trim();
@@ -203,6 +245,10 @@ public class GunConfigFrame extends JFrame {
             JOptionPane.showMessageDialog(this, "请输入工位号", "提示", JOptionPane.WARNING_MESSAGE);
             return;
         }
+        if (!OPRNO_PATTERN.matcher(gw).matches()) {
+            JOptionPane.showMessageDialog(this, "工位号格式不正确,应为 OP080 或 OP080A", "提示", JOptionPane.WARNING_MESSAGE);
+            return;
+        }
         if (gwDes.isEmpty()) {
             JOptionPane.showMessageDialog(this, "请输入工位名称", "提示", JOptionPane.WARNING_MESSAGE);
             return;
@@ -233,6 +279,8 @@ public class GunConfigFrame extends JFrame {
             return;
         }
 
+        boolean gunIpChanged = !aIp.equals(MesClient.plcAIp) || !bIp.equals(MesClient.plcBIp);
+
         MesClient.mes_gw = gw;
         MesClient.mes_gw_des = gwDes;
         MesClient.mes_server_ip = serverIp;
@@ -248,7 +296,25 @@ public class GunConfigFrame extends JFrame {
 
         setVisible(false);
         dispose();
-        MesClient.enterAfterGunConfig();
+
+        if (startupMode) {
+            MesClient.enterAfterGunConfig();
+        } else {
+            // 登录后修改:刷新标题,枪IP变了则重连PLC
+            if (MesClient.mesClientFrame != null) {
+                MesClient.mesClientFrame.setTitle("MES系统客户端:" + MesClient.mes_gw + "- " + MesClient.mes_gw_des);
+            }
+            if (gunIpChanged) {
+                try {
+                    MesClient.initPlc();
+                    MesClient.setMenuStatus("枪IP已更新并重连PLC", 0);
+                } catch (Exception e) {
+                    MesClient.setMenuStatus("PLC重连失败:" + e.getMessage(), -1);
+                }
+            } else {
+                MesClient.setMenuStatus("配置已保存", 0);
+            }
+        }
     }
 
     private static String nullToEmpty(String value) {

+ 6 - 0
src/com/mes/ui/InitStationFrame.java

@@ -14,6 +14,8 @@ public class InitStationFrame extends JFrame {
 
     private static final Pattern IP_PATTERN = Pattern.compile(
             "^((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(25[0-5]|2[0-4]\\d|[01]?\\d\\d?)$");
+    /** 工位号:OP080 或 OP080A */
+    private static final Pattern OPRNO_PATTERN = Pattern.compile("^OP\\d{3}[A-Z]?$");
 
     private JTextField gwTxt;
     private JTextField gwDesTxt;
@@ -125,6 +127,10 @@ public class InitStationFrame extends JFrame {
             JOptionPane.showMessageDialog(this, "请输入工位号", "提示", JOptionPane.WARNING_MESSAGE);
             return;
         }
+        if (!OPRNO_PATTERN.matcher(gw).matches()) {
+            JOptionPane.showMessageDialog(this, "工位号格式不正确,应为 OP080 或 OP080A", "提示", JOptionPane.WARNING_MESSAGE);
+            return;
+        }
         if (gwDes.isEmpty()) {
             JOptionPane.showMessageDialog(this, "请输入工位名称", "提示", JOptionPane.WARNING_MESSAGE);
             return;

+ 18 - 1
src/com/mes/ui/MesClient.java

@@ -727,9 +727,14 @@ public class MesClient extends JFrame {
         //弹窗扫工件码
         String scanBarcode = product_sn.getText().trim();
         if(scanBarcode!=null&&!scanBarcode.equalsIgnoreCase("")) {
+            // Modena-1B 工件码固定 33 位(与 mescloud checkProductSn/-1BXT 一致)
+            if(scanBarcode.length() != 33) {
+                setMenuStatus("工件码长度必须为33位", -1);
+                return;
+            }
             //获取用户
             getUser();
-            //获取扫码内容36位
+            //获取扫码内容36位(协议字段宽36,右侧补空格)
             String barcode36 = getBarcode(scanBarcode);//处理36为码
             //刷新界面
             mesClientFrame.repaint();
@@ -875,6 +880,18 @@ public class MesClient extends JFrame {
         });
         settingMenu.add(resetTcpMenu_1);
 
+        JMenuItem gunConfigMenu = new JMenuItem("工位/枪配置");
+        gunConfigMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/menu_setting.png")));
+        gunConfigMenu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
+        gunConfigMenu.addMouseListener(new MouseAdapter() {
+            @Override
+            public void mousePressed(MouseEvent e) {
+                super.mouseClicked(e);
+                GunConfigFrame.openForEdit();
+            }
+        });
+        settingMenu.add(gunConfigMenu);
+
         contentPane = new JPanel();
         contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
         setContentPane(contentPane);

+ 2 - 2
src/resources/config/config.properties

@@ -1,7 +1,7 @@
 mes.gw=OP200
-mes.gw_des=总成正面拉铆
+mes.gw_des=OP250
 #mes.server_ip=127.0.0.1
-mes.server_ip=192.168.19.99
+mes.server_ip=192.168.12.99
 mes.tcp_port=3000
 mes.heart_beat_cycle=60
 mes.line_sn=XT