Bladeren bron

单枪改为双枪

张田野 1 week geleden
bovenliggende
commit
24d3466411
4 gewijzigde bestanden met toevoegingen van 274 en 135 verwijderingen
  1. 214 52
      src/com/mes/ui/MesClient.java
  2. 6 15
      src/com/mes/ui/MesRevice.java
  3. 52 66
      src/com/mes/ui/ModbusUtil.java
  4. 2 2
      src/resources/config/config.properties

+ 214 - 52
src/com/mes/ui/MesClient.java

@@ -97,8 +97,8 @@ public class MesClient extends JFrame {
     public static JTextField param3;
     public static JTextField param4;
 
-    public static ModbusTcp plcA = new ModbusTcp(1, "192.168.1.7");
-//    public static ModbusTcp plcB = new ModbusTcp(1, "192.168.1.8");
+    public static ModbusTcp plcA = new ModbusTcp(1, "192.168.1.27");
+    public static ModbusTcp plcB = new ModbusTcp(1, "192.168.1.28");
 
     public static Timer cjTimer;
 
@@ -106,14 +106,15 @@ public class MesClient extends JFrame {
 
     public static Timer cjTimer3;
 
-    public static Short aSetNum = 48;
+    public static Short aSetNum = 24;
     public static Short sortA = 0;
     public static Short aMax = 0;
     public static Short aFinish = 0; //合格数量
     public static List<Map> alist = new ArrayList<>();
-    public static Short bSetNum = 10;
+    public static Short bSetNum = 24;
     public static Short sortB = 0;
     public static Short bMax = 0;
+    public static Short bFinish = 0; //合格数量
     public static List<Map> blist = new ArrayList<>();
     public static Short deviceControl = 0; // 0=本地 1=远程
     public static Integer tjStatus = 0; // 1=提交失败
@@ -123,6 +124,7 @@ public class MesClient extends JFrame {
     public static String curSn = "";
 
     public static Integer zdStatusA = 0;
+    public static Integer zdStatusB = 0;
     public static String foutA = "";
     public static String fmaxA = "";
     public static String fminA = "";
@@ -130,9 +132,19 @@ public class MesClient extends JFrame {
     public static String smaxA = "";
     public static String sminA = "";
     public static String curA = "";
+    public static String foutB = "";
+    public static String fmaxB = "";
+    public static String fminB = "";
+    public static String soutB = "";
+    public static String smaxB = "";
+    public static String sminB = "";
+    public static String curB = "";
     public static JButton resetResultA;
     public static JButton okResultA;
     public static JButton ngResultA;
+    public static JButton resetResultB;
+    public static JButton okResultB;
+    public static JButton ngResultB;
 
 
     public static JTable table;
@@ -169,15 +181,15 @@ public class MesClient extends JFrame {
                     welcomeWin = new LoginFarme();
                     welcomeWin.setVisible(true);
 
-//                    getPlcParam();
+                    getPlcParam();
 
-//                    upParams();
-//
-//                    setDeviceStart();
+                    upParams();
+
+                    setDeviceStart();
 
                     getMaterailData();
 
-//                    deviceOnline();
+                    deviceOnline();
                 }catch (Exception e){
                     log.error("系统初始化异常: ", e);
                     e.printStackTrace();
@@ -195,10 +207,17 @@ public class MesClient extends JFrame {
         cjTimer4.schedule(new TimerTask() {
             public void run() {
                 try{
+                    // NG中断锁枪期间不自动开机,避免冲掉锁枪
                     if(work_status == 1 && zdStatusA == 0){
                         List<Boolean> yxstatus = plcA.readCoil(456,1);
                         if(yxstatus.size() >= 1 && !yxstatus.get(0)){
-                            ModbusUtil.setPowerOn(MesClient.plcA); // 远程关机
+                            ModbusUtil.setPowerOn(MesClient.plcA);
+                        }
+                    }
+                    if(work_status == 1 && zdStatusB == 0){
+                        List<Boolean> yxstatusb = plcB.readCoil(456,1);
+                        if(yxstatusb.size() >= 1 && !yxstatusb.get(0)){
+                            ModbusUtil.setPowerOn(MesClient.plcB);
                         }
                     }
                 }catch (Exception e){
@@ -238,16 +257,20 @@ public class MesClient extends JFrame {
         cjTimer.schedule(new TimerTask() {
             public void run() {
                 try{
-                    ModbusUtil.getDataA(plcA);
+                    if(work_status == 1){
+                        ModbusUtil.getDataA(plcA);
+                    }
                 }catch (Exception e){
                     e.printStackTrace();
                 }
 
-//                try{
-//                    ModbusUtil.getDataB(plcB);
-//                }catch (Exception e){
-//                    e.printStackTrace();
-//                }
+                try{
+                    if(work_status == 1){
+                        ModbusUtil.getDataB(plcB);
+                    }
+                }catch (Exception e){
+                    e.printStackTrace();
+                }
             }
         }, 1000,500);
     }
@@ -262,29 +285,50 @@ public class MesClient extends JFrame {
             public void run() {
                 try{
 
-                    boolean lamaoret = ModbusUtil.getOnOff(plcA);
-                    if(lamaoret){
-                        lblNewLabel.setText("A枪:在线");
+                    boolean lamaoretA = ModbusUtil.getOnOff(plcA);
+                    boolean lamaoretB = ModbusUtil.getOnOff(plcB);
+                    if(lamaoretA && lamaoretB){
+                        lblNewLabel.setText("A/B枪:在线");
                         lblNewLabel.setForeground(Color.GREEN);
+                    }else if(lamaoretA){
+                        lblNewLabel.setText("A在线/B离线");
+                        lblNewLabel.setForeground(Color.ORANGE);
+                    }else if(lamaoretB){
+                        lblNewLabel.setText("A离线/B在线");
+                        lblNewLabel.setForeground(Color.ORANGE);
                     }else{
-                        lblNewLabel.setText("A枪:离线");
+                        lblNewLabel.setText("A/B枪:离线");
                         lblNewLabel.setForeground(Color.RED);
                     }
 
                     if(work_status == 1){
+                        // A枪:任务未完成且无NG中断时保持开机;完成或NG中断则锁枪
                         List<Boolean> yxstatus = plcA.readCoil(3128,1);
                         if(yxstatus.size() >= 1 && !yxstatus.get(0)){
-                            if(!MesClient.curSn.isEmpty() && MesClient.aMax > 0 && MesClient.aMax == MesClient.sortA){
+                            if(zdStatusA != 0 || (!MesClient.curSn.isEmpty() && MesClient.aMax > 0 && MesClient.aMax == MesClient.sortA)){
                                 ModbusUtil.setPowerOff(plcA);
                             }else{
                                 ModbusUtil.setPowerOn(plcA);
                             }
                         }
+                        // B枪
+                        List<Boolean> yxstatusb = plcB.readCoil(3128,1);
+                        if(yxstatusb.size() >= 1 && !yxstatusb.get(0)){
+                            if(zdStatusB != 0 || (!MesClient.curSn.isEmpty() && MesClient.bMax > 0 && MesClient.bMax == MesClient.sortB)){
+                                ModbusUtil.setPowerOff(plcB);
+                            }else{
+                                ModbusUtil.setPowerOn(plcB);
+                            }
+                        }
                     }else{
                         List<Boolean> yxstatus = plcA.readCoil(3128,1);
                         if(yxstatus.size() >= 1 && yxstatus.get(0)){
                             ModbusUtil.setPowerOff(plcA);
                         }
+                        List<Boolean> yxstatusb = plcB.readCoil(3128,1);
+                        if(yxstatusb.size() >= 1 && yxstatusb.get(0)){
+                            ModbusUtil.setPowerOff(plcB);
+                        }
                     }
 
 
@@ -441,6 +485,7 @@ public class MesClient extends JFrame {
         MesClient.aMax = 0;
         MesClient.aFinish = 0;
         MesClient.bMax = 0;
+        MesClient.bFinish = 0;
         MesClient.alist = new ArrayList<>();
         MesClient.blist = new ArrayList<>();
         MesClient.sortB = 0;
@@ -450,9 +495,6 @@ public class MesClient extends JFrame {
         MesClient.param3.setText("");
         MesClient.param4.setText("");
 
-        MesClient.param3.setVisible(false);
-        MesClient.param4.setVisible(false);
-
         fxModeVal = false;
         fxMaxNum.setEditable(false);
         fxMaxNum.setText("");
@@ -460,16 +502,21 @@ public class MesClient extends JFrame {
         fxMode.setBackground(null);
         fxMode.setForeground(null);
 
-        ModbusUtil.setPowerOff(MesClient.plcA); // 远程关机
-//        ModbusUtil.setMesUnAllow(MesClient.plcA, MesClient.deviceHeartTimer);
+        ModbusUtil.setPowerOff(MesClient.plcA); // 远程关机锁枪
+        ModbusUtil.setPowerOff(MesClient.plcB); // 远程关机锁枪
         ModbusUtil.setTask(MesClient.plcA,aSetNum);
+        ModbusUtil.setTask(MesClient.plcB,bSetNum);
 
         updateMaterailData();
 
         zdStatusA = 0;
+        zdStatusB = 0;
         resetResultA.setEnabled(false);
         okResultA.setEnabled(false);
         ngResultA.setEnabled(false);
+        resetResultB.setEnabled(false);
+        okResultB.setEnabled(false);
+        ngResultB.setEnabled(false);
 
 //        shiftUserCheck();
 
@@ -842,8 +889,7 @@ public class MesClient extends JFrame {
         });
         finish_ok_bt.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ok_bg.png")));
         finish_ok_bt.setFont(new Font("微软雅黑", Font.PLAIN, 32));
-//        finish_ok_bt.setBounds(185, 291, 240, 80);
-        finish_ok_bt.setBounds(185, 371, 240, 80);
+        finish_ok_bt.setBounds(185, 395, 240, 80);
         finish_ok_bt.setEnabled(false);
         indexPanelA.add(finish_ok_bt);
 
@@ -862,7 +908,6 @@ public class MesClient extends JFrame {
                     log.info("【判定上传】发送结果: {}", sendret);
                     if(!sendret){
                         MesClient.setMenuStatus("消息发送失败,请重试",-1);
-//                        JOptionPane.showMessageDialog(mesClientFrame,"消息发送失败,请重试","提示窗口", JOptionPane.INFORMATION_MESSAGE);
                         return;
                     }
                 }
@@ -870,21 +915,19 @@ public class MesClient extends JFrame {
         });
         finish_ng_bt.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ng_bg.png")));
         finish_ng_bt.setFont(new Font("微软雅黑", Font.PLAIN, 32));
-        finish_ng_bt.setBounds(508, 371, 240, 80);
+        finish_ng_bt.setBounds(508, 395, 240, 80);
         finish_ng_bt.setEnabled(false);
         indexPanelA.add(finish_ng_bt);
 
         lblNewLabel = new JLabel("A枪");
         lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
         lblNewLabel.setFont(new Font("微软雅黑", Font.PLAIN, 20));
-//        lblNewLabel.setBounds(204, 186, 166, 28);
-        lblNewLabel.setBounds(304, 186, 166, 28);
+        lblNewLabel.setBounds(204, 186, 166, 28);
         indexPanelA.add(lblNewLabel);
 
         JLabel lblNewLabel_1 = new JLabel("\u9884\u8BBE\u6570\u91CF");
         lblNewLabel_1.setFont(new Font("微软雅黑", Font.PLAIN, 18));
-//        lblNewLabel_1.setBounds(204, 241, 83, 34);
-        lblNewLabel_1.setBounds(185, 241, 83, 34);
+        lblNewLabel_1.setBounds(204, 241, 83, 34);
         indexPanelA.add(lblNewLabel_1);
 
         param1 = new JTextField();
@@ -892,15 +935,13 @@ public class MesClient extends JFrame {
         param1.setFont(new Font("微软雅黑", Font.PLAIN, 18));
         param1.setText("0");
         param1.setEditable(false);
-//        param1.setBounds(288, 241, 83, 34);
-        param1.setBounds(269, 241, 83, 34);
+        param1.setBounds(288, 241, 83, 34);
         indexPanelA.add(param1);
         param1.setColumns(10);
 
         JLabel lblNewLabel_1_1 = new JLabel("\u5B8C\u6210\u6570\u91CF");
         lblNewLabel_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 18));
-//        lblNewLabel_1_1.setBounds(204, 285, 83, 34);
-        lblNewLabel_1_1.setBounds(185, 285, 83, 34);
+        lblNewLabel_1_1.setBounds(204, 285, 83, 34);
         indexPanelA.add(lblNewLabel_1_1);
 
         param2 = new JTextField();
@@ -909,20 +950,19 @@ public class MesClient extends JFrame {
         param2.setText("0");
         param2.setEditable(false);
         param2.setColumns(10);
-//        param2.setBounds(288, 285, 83, 34);
-        param2.setBounds(269, 285, 83, 34);
+        param2.setBounds(288, 285, 83, 34);
         indexPanelA.add(param2);
 
         JLabel lblB = new JLabel("B\u67AA");
         lblB.setHorizontalAlignment(SwingConstants.CENTER);
         lblB.setFont(new Font("微软雅黑", Font.PLAIN, 20));
         lblB.setBounds(525, 186, 166, 28);
-//        indexPanelA.add(lblB);
+        indexPanelA.add(lblB);
 
         JLabel lblNewLabel_1_2 = new JLabel("\u9884\u8BBE\u6570\u91CF");
         lblNewLabel_1_2.setFont(new Font("微软雅黑", Font.PLAIN, 18));
         lblNewLabel_1_2.setBounds(525, 241, 83, 34);
-//        indexPanelA.add(lblNewLabel_1_2);
+        indexPanelA.add(lblNewLabel_1_2);
 
         param3 = new JTextField();
         param3.setText("0");
@@ -932,13 +972,11 @@ public class MesClient extends JFrame {
         param3.setColumns(10);
         param3.setBounds(608, 241, 83, 34);
         indexPanelA.add(param3);
-        MesClient.param3.setVisible(false);
-
 
         JLabel lblNewLabel_1_1_1 = new JLabel("\u5B8C\u6210\u6570\u91CF");
         lblNewLabel_1_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 18));
         lblNewLabel_1_1_1.setBounds(525, 285, 83, 34);
-//        indexPanelA.add(lblNewLabel_1_1_1);
+        indexPanelA.add(lblNewLabel_1_1_1);
 
         param4 = new JTextField();
         param4.setText("0");
@@ -948,8 +986,16 @@ public class MesClient extends JFrame {
         param4.setColumns(10);
         param4.setBounds(608, 285, 83, 34);
         indexPanelA.add(param4);
-        MesClient.param4.setVisible(false);
 
+        JLabel lblNgJudgeA = new JLabel("NG\u590d\u5224");
+        lblNgJudgeA.setFont(new Font("微软雅黑", Font.PLAIN, 14));
+        lblNgJudgeA.setBounds(204, 322, 167, 22);
+        indexPanelA.add(lblNgJudgeA);
+
+        JLabel lblNgJudgeB = new JLabel("NG\u590d\u5224");
+        lblNgJudgeB.setFont(new Font("微软雅黑", Font.PLAIN, 14));
+        lblNgJudgeB.setBounds(525, 322, 167, 22);
+        indexPanelA.add(lblNgJudgeB);
 
         resetResultA = new JButton("重拉");
         resetResultA.addActionListener(new ActionListener() {
@@ -984,8 +1030,8 @@ public class MesClient extends JFrame {
             }
         });
         resetResultA.setEnabled(false);
-        resetResultA.setFont(new Font("微软雅黑", Font.PLAIN, 16));
-        resetResultA.setBounds(508, 285, 100, 40);
+        resetResultA.setFont(new Font("微软雅黑", Font.PLAIN, 14));
+        resetResultA.setBounds(204, 348, 70, 36);
         indexPanelA.add(resetResultA);
 
         okResultA = new JButton("OK");
@@ -1024,8 +1070,8 @@ public class MesClient extends JFrame {
         });
         okResultA.setEnabled(false);
         okResultA.setForeground(new Color(0, 128, 0));
-        okResultA.setFont(new Font("微软雅黑", Font.PLAIN, 16));
-        okResultA.setBounds(632, 285, 100, 40);
+        okResultA.setFont(new Font("微软雅黑", Font.PLAIN, 14));
+        okResultA.setBounds(281, 348, 70, 36);
         indexPanelA.add(okResultA);
 
         ngResultA = new JButton("NG");
@@ -1064,9 +1110,124 @@ public class MesClient extends JFrame {
 
         ngResultA.setEnabled(false);
         ngResultA.setForeground(new Color(255, 0, 0));
-        ngResultA.setFont(new Font("微软雅黑", Font.PLAIN, 16));
-        ngResultA.setBounds(759, 285, 100, 40);
+        ngResultA.setFont(new Font("微软雅黑", Font.PLAIN, 14));
+        ngResultA.setBounds(358, 348, 70, 36);
         indexPanelA.add(ngResultA);
+
+        resetResultB = new JButton("重拉");
+        resetResultB.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+                log.info("【B枪操作】点击了 [重拉] 按钮,当前产品SN: {}", product_sn.getText());
+                if(zdStatusB == 1){
+                    log.info("【NG审核检查】准备校验 B枪 NG中断数据, SN: {}", product_sn.getText());
+                    JSONObject retObj = DataUtil.checkNgData(product_sn.getText(),"B");
+                    log.info("【NG审核检查】校验返回结果: {}", retObj != null ? retObj.toJSONString() : "null");
+
+                    if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
+                        MesClient.zdStatusB = 0;
+                        MesClient.resetResultB.setEnabled(false);
+                        MesClient.okResultB.setEnabled(false);
+                        MesClient.ngResultB.setEnabled(false);
+                        MesClient.sortB = (short) (MesClient.sortB - 1);
+                        MesClient.param4.setText(MesClient.sortB+"");
+                        plcB.writeInt16(1136,MesClient.sortB);
+                        MesClient.foutB = "";
+                        MesClient.soutB = "";
+                        MesClient.fmaxB = "";
+                        MesClient.fminB = "";
+                        MesClient.smaxB = "";
+                        MesClient.sminB = "";
+                        MesClient.curB = "";
+                        ModbusUtil.setPowerOn(plcB);
+                    }else{
+                        MesClient.setMenuStatus("NG中断未审核",-1);
+                    }
+                }
+            }
+        });
+        resetResultB.setEnabled(false);
+        resetResultB.setFont(new Font("微软雅黑", Font.PLAIN, 14));
+        resetResultB.setBounds(525, 348, 70, 36);
+        indexPanelA.add(resetResultB);
+
+        okResultB = new JButton("OK");
+        okResultB.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+                log.info("【B枪操作】点击了 [OK] 按钮,当前产品SN: {}", product_sn.getText());
+                if(zdStatusB == 1){
+                    log.info("【NG审核检查】准备校验 B枪 NG中断数据, SN: {}", product_sn.getText());
+                    JSONObject retObj = DataUtil.checkNgData(product_sn.getText(),"B");
+                    log.info("【NG审核检查】校验返回结果: {}", retObj != null ? retObj.toJSONString() : "null");
+
+                    if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
+                        if(!MesClient.product_sn.getText().isEmpty()){
+                            MesClient.bFinish++;
+                            JdbcUtils.insertProdData(MesClient.mes_gw, MesClient.mes_line_sn, MesClient.product_sn.getText(),"B",foutB,soutB,fminB,sminB,fmaxB,smaxB,"1",curB+"", MesClient.user_menu.getText());
+                        }
+                        MesClient.zdStatusB = 0;
+                        MesClient.resetResultB.setEnabled(false);
+                        MesClient.okResultB.setEnabled(false);
+                        MesClient.ngResultB.setEnabled(false);
+                        MesClient.foutB = "";
+                        MesClient.soutB = "";
+                        MesClient.fmaxB = "";
+                        MesClient.fminB = "";
+                        MesClient.smaxB = "";
+                        MesClient.sminB = "";
+                        MesClient.curB = "";
+
+                        ModbusUtil.upResult();
+                        ModbusUtil.setPowerOn(plcB);
+                    }else{
+                        MesClient.setMenuStatus("NG中断未审核",-1);
+                    }
+                }
+            }
+        });
+        okResultB.setEnabled(false);
+        okResultB.setForeground(new Color(0, 128, 0));
+        okResultB.setFont(new Font("微软雅黑", Font.PLAIN, 14));
+        okResultB.setBounds(602, 348, 70, 36);
+        indexPanelA.add(okResultB);
+
+        ngResultB = new JButton("NG");
+        ngResultB.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+                log.info("【B枪操作】点击了 [NG] 按钮,当前产品SN: {}", product_sn.getText());
+                if(zdStatusB == 1){
+                    log.info("【NG审核检查】准备校验 B枪 NG中断数据, SN: {}", product_sn.getText());
+                    JSONObject retObj = DataUtil.checkNgData(product_sn.getText(),"B");
+                    log.info("【NG审核检查】校验返回结果: {}", retObj != null ? retObj.toJSONString() : "null");
+
+                    if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
+                        if(!MesClient.product_sn.getText().isEmpty()){
+                            JdbcUtils.insertProdData(MesClient.mes_gw, MesClient.mes_line_sn, MesClient.product_sn.getText(),"B",foutB,soutB,fminB,sminB,fmaxB,smaxB,"0",curB+"", MesClient.user_menu.getText());
+                        }
+                        MesClient.zdStatusB = 0;
+                        MesClient.resetResultB.setEnabled(false);
+                        MesClient.okResultB.setEnabled(false);
+                        MesClient.ngResultB.setEnabled(false);
+                        MesClient.foutB = "";
+                        MesClient.soutB = "";
+                        MesClient.fmaxB = "";
+                        MesClient.fminB = "";
+                        MesClient.smaxB = "";
+                        MesClient.sminB = "";
+                        MesClient.curB = "";
+                        ModbusUtil.upResult();
+                        ModbusUtil.setPowerOn(plcB);
+
+                    }else{
+                        MesClient.setMenuStatus("NG中断未审核",-1);
+                    }
+                }
+            }
+        });
+        ngResultB.setEnabled(false);
+        ngResultB.setForeground(new Color(255, 0, 0));
+        ngResultB.setFont(new Font("微软雅黑", Font.PLAIN, 14));
+        ngResultB.setBounds(679, 348, 70, 36);
+        indexPanelA.add(ngResultB);
         
         fxMode = new JButton("返修模式");
         fxMode.setFont(new Font("微软雅黑", Font.PLAIN, 16));
@@ -1105,6 +1266,7 @@ public class MesClient extends JFrame {
                 int maxNum = Integer.parseInt(fxMaxNum.getText());
                 if(maxNum > 0){
                     ModbusUtil.setTask(MesClient.plcA,(short)maxNum);
+                    ModbusUtil.setTask(MesClient.plcB,(short)maxNum);
                 }
             }
         });

+ 6 - 15
src/com/mes/ui/MesRevice.java

@@ -1,12 +1,6 @@
 package com.mes.ui;
 
-import com.github.xingshuangs.iot.protocol.modbus.service.ModbusTcp;
-import com.mes.netty.ProtocolParam;
-import com.mes.component.MyDialog;
-
-import javax.swing.*;
 import java.awt.*;
-import java.util.Timer;
 
 public class MesRevice {
 
@@ -26,8 +20,8 @@ public class MesRevice {
             }else {
                 MesClient.check_quality_result = false;
                 ErrorMsg.setErrorMsg(mes_msg);
-                ModbusUtil.setPowerOff(MesClient.plcA); // 远程关机
-//                ModbusUtil.setMesUnAllow(MesClient.plcA, MesClient.deviceHeartTimer);
+                ModbusUtil.setPowerOff(MesClient.plcA); // 远程关机锁枪
+                ModbusUtil.setPowerOff(MesClient.plcB); // 远程关机锁枪
             }
         }catch (Exception e){
             e.printStackTrace();
@@ -43,15 +37,15 @@ public class MesRevice {
                     int maxNum = Integer.parseInt(MesClient.fxMaxNum.getText());
                     if(maxNum > 0){
                         ModbusUtil.setTask(MesClient.plcA,(short)maxNum);
+                        ModbusUtil.setTask(MesClient.plcB,(short)maxNum);
                     }
                 }else{
                     ModbusUtil.setTask(MesClient.plcA,MesClient.aSetNum);
+                    ModbusUtil.setTask(MesClient.plcB,MesClient.bSetNum);
                 }
 
-                ModbusUtil.setPowerOn(MesClient.plcA); // 远程关机
-
-//                Short cur = MesClient.plcA.readInt16(1136);
-//                MesClient.curInit = cur;
+                ModbusUtil.setPowerOn(MesClient.plcA); // 远程开机
+                ModbusUtil.setPowerOn(MesClient.plcB); // 远程开机
 
                 MesClient.work_status = 1;
                 MesClient.f_scan_data_bt_1.setEnabled(false);
@@ -103,9 +97,6 @@ public class MesRevice {
 
             }else{
                 MesClient.setMenuStatus("结果提交失败,请重试",-1);
-//                MesClient.status_menu.setText("结果提交失败,请重试");
-//                JOptionPane.showMessageDialog(MesClient.mesClientFrame,"结果提交失败,请重试","提示窗口", JOptionPane.INFORMATION_MESSAGE);
-//                return;
             }
         }catch (Exception e){
             e.printStackTrace();

+ 52 - 66
src/com/mes/ui/ModbusUtil.java

@@ -16,7 +16,6 @@ public class ModbusUtil {
 
         if(MesClient.sortA < cur){
             MesClient.sortA = cur;
-//            MesClient.aFinish = plc.readInt16(1138);
             String fout = plc.readInt16(1064)+"";
             String sout = (float)plc.readInt16(1065)/1000+"";
 
@@ -27,7 +26,7 @@ public class ModbusUtil {
             String smax = (float)plc.readInt16(1071)/1000+"";
 
             MesClient.param2.setText(cur+"");
-            System.out.println("cur:"+cur);
+            System.out.println("curA:"+cur);
 
             // NG处理
             String qty = "1";
@@ -62,34 +61,20 @@ public class ModbusUtil {
             }
         }
 
-        if(MesClient.zdStatusA == 0){
+        if(MesClient.zdStatusA == 0 && MesClient.zdStatusB == 0){
             upResult();
         }
     }
 
     public static void getDataB(ModbusTcp plc){
-
-        // 41065=F-out  41066=S-out
-        // 41069=F-min  41071=S-min 41070=F-max  41072=S-max
-        // 预设数量=41129  完成数=41137
-
         Short cur = plc.readInt16(1136);
-//        System.out.println("F-out:"+plc.readInt16(1064));
-//        System.out.println("S-out:"+plc.readInt16(1065));
-//        System.out.println("F-min:"+plc.readInt16(1068));
-//        System.out.println("S-min:"+plc.readInt16(1070));
-//        System.out.println("F-max:"+plc.readInt16(1069));
-//        System.out.println("S-max:"+plc.readInt16(1071));
-//        System.out.println("set:"+plc.readInt16(1128));
-//        System.out.println("cur:"+cur);
-//        System.out.println("cur2:"+MesClient.sortB);
 
         if(MesClient.bMax <= 0){
             MesClient.bMax = plc.readInt16(1128);
             MesClient.param3.setText(String.valueOf(MesClient.bMax));
         }
 
-        if(MesClient.sortB == cur - 1){
+        if(MesClient.sortB < cur){
             MesClient.sortB = cur;
             String fout = plc.readInt16(1064)+"";
             String sout = (float)plc.readInt16(1065)/1000+"";
@@ -100,25 +85,54 @@ public class ModbusUtil {
             String fmax = plc.readInt16(1069)+"";
             String smax = (float)plc.readInt16(1071)/1000+"";
 
-            if(MesClient.sortB == 32){
-                setTask2S(plc);
+            MesClient.param4.setText(cur+"");
+            System.out.println("curB:"+cur);
+
+            // NG处理
+            String qty = "1";
+            if(Integer.valueOf(fout) < Integer.valueOf(fmin) || Integer.valueOf(fout) > Integer.valueOf(fmax)){
+                qty = "0";
+            }
+            if(Float.valueOf(sout) < Float.valueOf(smin) || Float.valueOf(sout) > Float.valueOf(smax)){
+                qty = "0";
             }
 
-            MesClient.param4.setText(cur+"");
+            if(qty.equals("0")){
+                MesClient.zdStatusB = 1;
+                MesClient.foutB = fout;
+                MesClient.soutB = sout;
+                MesClient.fmaxB = fmax;
+                MesClient.fminB = fmin;
+                MesClient.sminB = smin;
+                MesClient.smaxB = smax;
+                MesClient.curB = cur+"";
+                MesClient.resetResultB.setEnabled(true);
+                MesClient.okResultB.setEnabled(true);
+                MesClient.ngResultB.setEnabled(true);
+                ModbusUtil.setPowerOff(plc);
 
-            System.out.println("cur:"+cur);
-            if(!MesClient.product_sn.getText().isEmpty()){
-                JdbcUtils.insertProdData(MesClient.mes_gw, MesClient.mes_line_sn, MesClient.product_sn.getText(),"B",fout,sout,fmin,smin,fmax,smax,"1",cur+"", MesClient.user_menu.getText());
+                if(!MesClient.product_sn.getText().isEmpty()){
+                    DataUtil.addNgData(MesClient.product_sn.getText(),"B");
+                }
+            }
+            if(qty.equals("1") && !MesClient.product_sn.getText().isEmpty()){
+                MesClient.bFinish++;
+                JdbcUtils.insertProdData(MesClient.mes_gw, MesClient.mes_line_sn, MesClient.product_sn.getText(),"B",fout,sout,fmin,smin,fmax,smax,qty,cur+"", MesClient.user_menu.getText());
             }
         }
 
-        upResult();
-
+        if(MesClient.zdStatusA == 0 && MesClient.zdStatusB == 0){
+            upResult();
+        }
     }
 
-    // 上传总结果
+    // 上传总结果(双枪都完成且无NG中断时)
     public static void upResult(){
-        if(!MesClient.curSn.isEmpty() && MesClient.aMax > 0 && MesClient.aMax <= MesClient.sortA){
+        if (MesClient.zdStatusA != 0 || MesClient.zdStatusB != 0) {
+            return;
+        }
+        if(!MesClient.curSn.isEmpty() && MesClient.aMax > 0 && MesClient.aMax <= MesClient.sortA
+                && MesClient.bMax > 0 && MesClient.bMax <= MesClient.sortB){
             MesClient.finish_ok_bt.setEnabled(true);
             MesClient.finish_ng_bt.setEnabled(true);
 
@@ -129,6 +143,9 @@ public class ModbusUtil {
                 if(MesClient.aFinish != MesClient.aMax){
                     retf = "NG";
                 }
+                if(MesClient.bFinish != MesClient.bMax){
+                    retf = "NG";
+                }
                 Boolean ret = DataUtil.sendQuality(MesClient.nettyClient, MesClient.product_sn.getText(),retf, MesClient.user20);
                 if(!ret){
                     MesClient.setMenuStatus(MesClient.tjFlagTextErr,-1);
@@ -183,13 +200,11 @@ public class ModbusUtil {
         return String.join("",result);
     }
 
-    // 远程开机
+    // 远程开机(解锁)
     public static Boolean setPowerOn(ModbusTcp plc){
         Boolean ret = false;
         try{
             plc.writeCoil(3128,true);
-//            plc.writeCoil(3079,false);
-//            plc.writeCoil(3328,true); // 必须选关掉关机,开机才起左右
             ret = true;
         }catch (Exception e){
             e.printStackTrace();
@@ -199,14 +214,11 @@ public class ModbusUtil {
         return ret;
     }
 
-    // 远程关机
+    // 远程关机(锁枪)
     public static Boolean setPowerOff(ModbusTcp plc){
         Boolean ret = false;
         try{
             plc.writeCoil(3128,false);
-//            plc.writeCoil(3328,false);
-//            plc.writeCoil(3079,true); // 关机
-            // 必须选关掉关机,开机才起左右
             ret = true;
         }catch (Exception e){
             e.printStackTrace();
@@ -225,15 +237,12 @@ public class ModbusUtil {
             plc.writeInt16(1128,setNum);
             plc.writeInt16(1136,(short) 0);
             plc.writeInt16(1138,(short) 0);
-        }catch (Exception e){
-            e.printStackTrace();
-        }
-    }
 
-    public static void setTask2S(ModbusTcp plc){
-        try{
-            plc.writeInt16(1070,(short) 3600);
-            plc.writeInt16(1071,(short) 4600);
+            if(setNum == 24){
+                plc.writeInt16(1070,(short) 2800);
+                plc.writeInt16(1071,(short) 4600);
+            }
+
         }catch (Exception e){
             e.printStackTrace();
         }
@@ -249,27 +258,4 @@ public class ModbusUtil {
             return false;
         }
     }
-
-
-//        A枪说明 192.168.1.7
-//        plc.writeCoil(3079,false);
-//        plc.writeCoil(3328,true); // 必须选关掉关机,开机才起左右
-////        plc.writeCoil(3128,false);
-//        System.out.println("控制模式:"+plc.readInt16(1090)); // 1091 控制模式
-//        System.out.println("系统运行中:"+plc.readCoil(3128,1)); // 3129 系统运行中
-//        System.out.println("结束暂停:"+plc.readCoil(3132,1)); // 3133 系统运行中
-//        System.out.println("远程开机:"+plc.readCoil(3328,1)); // 3329 远程开机
-//        System.out.println("远程关机:"+plc.readCoil(3079,1)); // 3080 远程关机
-//        System.out.println("作业模式:"+plc.readInt16(1092)); // 1093 作业模式
-//        System.out.println("最大拉力:"+plc.readInt16(1064)); // 1065 最大拉力
-//        System.out.println("对应位移:"+plc.readInt16(1065)); // 1066 对应位移
-//        System.out.println("任务数量:"+plc.readInt16(1128)); // 1129 任务数量
-//        System.out.println("合格数量:"+plc.readInt16(1138)); // 1139 合格数量
-//        System.out.println("质量状态:"+plc.readInt16(1072)); // 1073 质量状态
-//        System.out.println("F-out:"+plc.readInt16(1064));
-//        System.out.println("S-out:"+plc.readInt16(1065));
-//        System.out.println("F-min:"+plc.readInt16(1068));
-//        System.out.println("S-min:"+plc.readInt16(1070));
-//        System.out.println("F-max:"+plc.readInt16(1069));
-//        System.out.println("S-max:"+plc.readInt16(1071));
 }

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

@@ -1,6 +1,6 @@
 mes.gw=OP265A
-mes.server_ip=127.0.0.1
-#mes.server_ip=192.168.18.99
+#mes.server_ip=127.0.0.1
+mes.server_ip=192.168.18.99
 mes.tcp_port=3000
 mes.heart_beat_cycle=60
 mes.line_sn=XT