Bläddra i källkod

绑定压铸码,增加二驱四驱与程序校验逻辑

dkk 1 dag sedan
förälder
incheckning
27ab4e1730
3 ändrade filer med 263 tillägg och 173 borttagningar
  1. 132 67
      src/com/mes/ui/MesClient.java
  2. 5 7
      src/com/mes/ui/MesRevice.java
  3. 126 99
      src/com/mes/ui/PlcUtil.java

+ 132 - 67
src/com/mes/ui/MesClient.java

@@ -456,11 +456,11 @@ public class MesClient extends JFrame {
         MesClient.tjFlaga = 0;
         MesClient.checkA = 0;
 
-//        MesClient.batch_status = 0;
-//        MesClient.textField.setText("");
-//        MesClient.batch_scan_1.setEnabled(false);
+        MesClient.batch_status = 0;
+        MesClient.textField.setText("");
+        MesClient.batch_scan_1.setEnabled(false);
         MesClient.formatScanType(1);
-       PlcUtil.changeEnable(MesClient.s7PLC,false);
+//        PlcUtil.changeEnable(MesClient.s7PLC,false);
 
         finish_ok_bt.setEnabled(false);
         finish_ng_bt.setEnabled(false);
@@ -517,11 +517,11 @@ public class MesClient extends JFrame {
         MesClient.tjFlagb = 0;
         MesClient.checkB = 0;
 
-//        MesClient.batch_status2 = 0;
-//        MesClient.textField_1.setText("");
-//        MesClient.batch_scan_2.setEnabled(false);
+        MesClient.batch_status2 = 0;
+        MesClient.textField_1.setText("");
+        MesClient.batch_scan_2.setEnabled(false);
         MesClient.formatScanType(1);
-        PlcUtil.changeEnable(MesClient.s7PLC,false);
+//        PlcUtil.changeEnable(MesClient.s7PLC,false);
         finish_ok_bt2.setEnabled(false);
         finish_ng_bt2.setEnabled(false);
 
@@ -568,6 +568,25 @@ public class MesClient extends JFrame {
         return sn.length() >= 22 && sn.length() <= 36 && sn.matches("[A-Za-z0-9]+");
     }
 
+    // 根据工件码前13位识别驱动类型:5019016600341-四驱,5019016600511-二驱
+    public static String getDriveTypeByBarcode(String barcode){
+        if(barcode == null){
+            return "";
+        }
+        String sn = barcode.trim();
+        if(sn.length() < 13){
+            return "";
+        }
+        String prefix = sn.substring(0,13);
+        if(prefix.equals("5019016600341")){
+            return "四驱";
+        }
+        if(prefix.equals("5019016600511")){
+            return "二驱";
+        }
+        return "";
+    }
+
     public static synchronized void beginQualityCheck(String sn, String page){
         waitingQualityReply = true;
         waitingQualitySn = sn == null ? "" : sn.trim();
@@ -1011,14 +1030,14 @@ public class MesClient extends JFrame {
         lblNewLabel.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
         lblNewLabel.setBounds(26, 340, 100, 40);
         lblNewLabel.setVisible(true);
-        indexPanelA.add(lblNewLabel);
+//        indexPanelA.add(lblNewLabel);
 
         JLabel lblNewLabel_1 = new JLabel("电流");
         lblNewLabel_1.setHorizontalAlignment(SwingConstants.RIGHT);
         lblNewLabel_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
         lblNewLabel_1.setBounds(226, 340, 100, 40);
         lblNewLabel_1.setVisible(true);
-        indexPanelA.add(lblNewLabel_1);
+//        indexPanelA.add(lblNewLabel_1);
 
         param1 = new JTextField();
         param1.setEnabled(false);
@@ -1027,7 +1046,7 @@ public class MesClient extends JFrame {
         param1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
         param1.setBounds(136, 340, 70, 40);
         param1.setVisible(true);
-        indexPanelA.add(param1);
+//        indexPanelA.add(param1);
         param1.setColumns(10);
 
         param2 = new JTextField();
@@ -1038,14 +1057,14 @@ public class MesClient extends JFrame {
         param2.setColumns(10);
         param2.setBounds(345, 340, 70, 40);
         param2.setVisible(true);
-        indexPanelA.add(param2);
+//        indexPanelA.add(param2);
 
         JLabel lblNewLabel_2 = new JLabel("送丝速度");
         lblNewLabel_2.setHorizontalAlignment(SwingConstants.RIGHT);
         lblNewLabel_2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
         lblNewLabel_2.setBounds(26, 401, 100, 40);
         lblNewLabel_2.setVisible(true);
-        indexPanelA.add(lblNewLabel_2);
+//        indexPanelA.add(lblNewLabel_2);
 
         param3 = new JTextField();
         param3.setEnabled(false);
@@ -1055,14 +1074,14 @@ public class MesClient extends JFrame {
         param3.setColumns(10);
         param3.setBounds(136, 401, 70, 40);
         param3.setVisible(true);
-        indexPanelA.add(param3);
+//        indexPanelA.add(param3);
 
         JLabel lblNewLabel_1_1 = new JLabel("错误代码");
         lblNewLabel_1_1.setHorizontalAlignment(SwingConstants.RIGHT);
         lblNewLabel_1_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
         lblNewLabel_1_1.setBounds(213, 401, 122, 40);
         lblNewLabel_1_1.setVisible(true);
-        indexPanelA.add(lblNewLabel_1_1);
+//        indexPanelA.add(lblNewLabel_1_1);
 
         param4 = new JTextField();
         param4.setEnabled(false);
@@ -1072,7 +1091,7 @@ public class MesClient extends JFrame {
         param4.setColumns(10);
         param4.setBounds(345, 401, 70, 40);
         param4.setVisible(true);
-        indexPanelA.add(param4);
+//        indexPanelA.add(param4);
 
         param5 = new JTextField();
         param5.setEnabled(false);
@@ -1082,14 +1101,14 @@ public class MesClient extends JFrame {
         param5.setColumns(10);
         param5.setBounds(226, 470, 70, 40);
         param5.setVisible(true);
-        indexPanelA.add(param5);
+//        indexPanelA.add(param5);
 
         JLabel lblNewLabel_1_1_1 = new JLabel("JOB号");
         lblNewLabel_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT);
         lblNewLabel_1_1_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
         lblNewLabel_1_1_1.setBounds(106, 470, 122, 40);
         lblNewLabel_1_1_1.setVisible(true);
-        indexPanelA.add(lblNewLabel_1_1_1);
+//        indexPanelA.add(lblNewLabel_1_1_1);
 
         product_sn2 = new JTextField();
         product_sn2.setText("");
@@ -1114,7 +1133,7 @@ public class MesClient extends JFrame {
         lblNewLabel_3.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
         lblNewLabel_3.setBounds(528, 340, 100, 40);
         lblNewLabel_3.setVisible(true);
-        indexPanelA.add(lblNewLabel_3);
+//        indexPanelA.add(lblNewLabel_3);
 
         param21 = new JTextField();
         param21.setEnabled(false);
@@ -1124,14 +1143,14 @@ public class MesClient extends JFrame {
         param21.setColumns(10);
         param21.setBounds(638, 340, 70, 40);
         param21.setVisible(true);
-        indexPanelA.add(param21);
+//        indexPanelA.add(param21);
 
         JLabel lblNewLabel_1_2 = new JLabel("电流");
         lblNewLabel_1_2.setHorizontalAlignment(SwingConstants.RIGHT);
         lblNewLabel_1_2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
         lblNewLabel_1_2.setBounds(742, 340, 100, 40);
         lblNewLabel_1_2.setVisible(true);
-        indexPanelA.add(lblNewLabel_1_2);
+//        indexPanelA.add(lblNewLabel_1_2);
 
         param22 = new JTextField();
         param22.setEnabled(false);
@@ -1141,14 +1160,14 @@ public class MesClient extends JFrame {
         param22.setColumns(10);
         param22.setBounds(852, 340, 70, 40);
         param22.setVisible(true);
-        indexPanelA.add(param22);
+//        indexPanelA.add(param22);
 
         JLabel lblNewLabel_2_1 = new JLabel("送丝速度");
         lblNewLabel_2_1.setHorizontalAlignment(SwingConstants.RIGHT);
         lblNewLabel_2_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
         lblNewLabel_2_1.setBounds(528, 401, 100, 40);
         lblNewLabel_2_1.setVisible(true);
-        indexPanelA.add(lblNewLabel_2_1);
+//        indexPanelA.add(lblNewLabel_2_1);
 
         param23 = new JTextField();
         param23.setEnabled(false);
@@ -1158,14 +1177,14 @@ public class MesClient extends JFrame {
         param23.setColumns(10);
         param23.setBounds(638, 401, 70, 40);
         param23.setVisible(true);
-        indexPanelA.add(param23);
+//        indexPanelA.add(param23);
 
         JLabel lblNewLabel_1_1_2 = new JLabel("错误代码");
         lblNewLabel_1_1_2.setHorizontalAlignment(SwingConstants.RIGHT);
         lblNewLabel_1_1_2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
         lblNewLabel_1_1_2.setBounds(718, 401, 122, 40);
         lblNewLabel_1_1_2.setVisible(true);
-        indexPanelA.add(lblNewLabel_1_1_2);
+//        indexPanelA.add(lblNewLabel_1_1_2);
 
         param24 = new JTextField();
         param24.setEnabled(false);
@@ -1175,14 +1194,14 @@ public class MesClient extends JFrame {
         param24.setColumns(10);
         param24.setBounds(852, 401, 70, 40);
         param24.setVisible(true);
-        indexPanelA.add(param24);
+//        indexPanelA.add(param24);
 
         JLabel lblNewLabel_1_1_1_1 = new JLabel("JOB号");
         lblNewLabel_1_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT);
         lblNewLabel_1_1_1_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
         lblNewLabel_1_1_1_1.setBounds(609, 470, 122, 40);
         lblNewLabel_1_1_1_1.setVisible(true);
-        indexPanelA.add(lblNewLabel_1_1_1_1);
+//        indexPanelA.add(lblNewLabel_1_1_1_1);
 
         param25 = new JTextField();
         param25.setEnabled(false);
@@ -1192,7 +1211,7 @@ public class MesClient extends JFrame {
         param25.setColumns(10);
         param25.setBounds(742, 470, 70, 40);
         param25.setVisible(true);
-        indexPanelA.add(param25);
+//        indexPanelA.add(param25);
 
         pxstatus1 = new JLabel("A");
         pxstatus1.setForeground(new Color(255, 128, 64));
@@ -1217,14 +1236,14 @@ public class MesClient extends JFrame {
         lblNewLabel_4.setFont(new Font("微软雅黑", Font.PLAIN, 24));
         lblNewLabel_4.setBounds(170, 290, 156, 40);
         lblNewLabel_4.setVisible(true);
-        indexPanelA.add(lblNewLabel_4);
+//        indexPanelA.add(lblNewLabel_4);
 
         JLabel lblNewLabel_4_1 = new JLabel("焊机2");
         lblNewLabel_4_1.setHorizontalAlignment(SwingConstants.CENTER);
         lblNewLabel_4_1.setFont(new Font("微软雅黑", Font.PLAIN, 24));
         lblNewLabel_4_1.setBounds(670, 287, 156, 40);
         lblNewLabel_4_1.setVisible(true);
-        indexPanelA.add(lblNewLabel_4_1);
+//        indexPanelA.add(lblNewLabel_4_1);
 
         JSeparator separator_1_1 = new JSeparator();
         separator_1_1.setOrientation(SwingConstants.VERTICAL);
@@ -1238,24 +1257,24 @@ public class MesClient extends JFrame {
         textField.setEditable(false);
         textField.setColumns(10);
         textField.setBounds(26, 333, 446, 70);
-//        indexPanelA.add(textField);
+        indexPanelA.add(textField);
 
         batch_scan_1 = new JButton("解绑");
         batch_scan_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/delete.png")));
         batch_scan_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 32));
         batch_scan_1.setEnabled(false);
-        batch_scan_1.setVisible(false);
+        batch_scan_1.setVisible(true);
         batch_scan_1.setBounds(136, 430, 230, 80);
         batch_scan_1.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
                 if(MesClient.curPage.equals("B")){
-                    MesClient.setMenuStatus("该状态后梁无法解绑",-1);
+                    MesClient.setMenuStatus("该状态前梁压铸码无法解绑",-1);
                 }else{
                     String sn = MesClient.product_sn.getText().trim();
                     String wsn = MesClient.textField.getText().trim();
-                    JSONObject retObj = DataUtil.unBindWarehouseData(sn,wsn,user_menu.getText().trim(),"400007");
+                    JSONObject retObj = DataUtil.unBindWarehouseData(sn,wsn,user_menu.getText().trim(),"400002");
                     if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
-                        MesClient.setMenuStatus("后梁码解绑成功",0);
+                        MesClient.setMenuStatus("前梁压铸码解绑成功",0);
                         MesClient.formatScanType(2);
 
                         textField.setText("");
@@ -1265,7 +1284,7 @@ public class MesClient extends JFrame {
                         MesClient.formatScanType(2);
                         batch_scan_1.setEnabled(true);
                         if(retObj.get("result")==null){
-                            MesClient.setMenuStatus("请求失败,后梁码解绑失败,请重试",-1);
+                            MesClient.setMenuStatus("请求失败,前梁压铸码解绑失败,请重试",-1);
                         }else{
                             if(retObj.get("result").toString().equalsIgnoreCase("false")){
                                 MesClient.setMenuStatus(retObj.getString("message"),-1);
@@ -1284,31 +1303,31 @@ public class MesClient extends JFrame {
         textField_1.setEditable(false);
         textField_1.setColumns(10);
         textField_1.setBounds(517, 333, 446, 70);
-//        indexPanelA.add(textField_1);
+        indexPanelA.add(textField_1);
 
         batch_scan_2 = new JButton("解绑");
         batch_scan_2.setIcon(new ImageIcon(MesClient.class.getResource("/bg/delete.png")));
         batch_scan_2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 32));
         batch_scan_2.setEnabled(false);
-        batch_scan_2.setVisible(false);
+        batch_scan_2.setVisible(true);
         batch_scan_2.setBounds(633, 430, 230, 80);
         batch_scan_2.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
                 if(MesClient.curPage.equals("A")){
-                    MesClient.setMenuStatus("该状态后梁无法解绑",-1);
+                    MesClient.setMenuStatus("该状态前梁压铸码无法解绑",-1);
                 }else{
                     String sn = MesClient.product_sn2.getText().trim();
                     String wsn = MesClient.textField_1.getText().trim();
-                    JSONObject retObj = DataUtil.unBindWarehouseData(sn,wsn,user_menu.getText().trim(),"400007");
+                    JSONObject retObj = DataUtil.unBindWarehouseData(sn,wsn,user_menu.getText().trim(),"400002");
                     if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
-                        MesClient.setMenuStatus("后梁码解绑成功",0);
+                        MesClient.setMenuStatus("前梁压铸码解绑成功",0);
                         MesClient.formatScanType(2);
                         textField_1.setText("");
                         batch_scan_2.setEnabled(false);
                         PlcUtil.changeEnable(s7PLC,false);
                     }else{
                         if(retObj.get("result")==null){
-                            MesClient.setMenuStatus("请求失败,前梁码解绑失败,请重试",-1);
+                            MesClient.setMenuStatus("请求失败,前梁压铸码解绑失败,请重试",-1);
                         }else{
                             if(retObj.get("result").toString().equalsIgnoreCase("false")){
                                 MesClient.setMenuStatus(retObj.getString("message"),-1);
@@ -1320,19 +1339,19 @@ public class MesClient extends JFrame {
         });
         indexPanelA.add(batch_scan_2);
 
-        JLabel pxstatus1_1 = new JLabel("A后梁");
+        JLabel pxstatus1_1 = new JLabel("A前梁压铸码");
         pxstatus1_1.setHorizontalAlignment(SwingConstants.CENTER);
         pxstatus1_1.setForeground(new Color(0, 0, 0));
         pxstatus1_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
         pxstatus1_1.setBounds(26, 283, 446, 44);
-//        indexPanelA.add(pxstatus1_1);
+        indexPanelA.add(pxstatus1_1);
 
-        JLabel pxstatus1_1_1 = new JLabel("B后梁");
+        JLabel pxstatus1_1_1 = new JLabel("B前梁压铸码");
         pxstatus1_1_1.setHorizontalAlignment(SwingConstants.CENTER);
         pxstatus1_1_1.setForeground(Color.BLACK);
         pxstatus1_1_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
         pxstatus1_1_1.setBounds(517, 283, 446, 44);
-//        indexPanelA.add(pxstatus1_1_1);
+        indexPanelA.add(pxstatus1_1_1);
 
         txtfa = new JTextField();
         txtfa.setHorizontalAlignment(SwingConstants.LEFT);
@@ -1394,7 +1413,7 @@ public class MesClient extends JFrame {
         if(scan_type == 1){
             scan_type_text.setText("镭雕码");
         }else if(scan_type == 2){
-            scan_type_text.setText("后梁码");
+            scan_type_text.setText("前梁压铸码");
         }else{
             scan_type_text.setText("");
         }
@@ -1425,6 +1444,12 @@ public class MesClient extends JFrame {
                 MesClient.setMenuStatus("未连接MES服务器",-1);
                 return;
             }
+            // 校验工件码与PLC程序号是否匹配(二驱/四驱)
+            String programErr = PlcUtil.checkBarcodeProgram(s7PLC, scanBarcodeSn, MesClient.curPage);
+            if(programErr != null){
+                MesClient.setMenuStatus(programErr, 1);
+                return;
+            }
             if(MesClient.curPage.equals("A")){
                 System.out.println("typeA");
                 if(!product_sn.getText().isEmpty() && mesQualityFlagA){
@@ -1456,6 +1481,46 @@ public class MesClient extends JFrame {
             }else{
                 MesClient.setMenuStatus("正在校验工件码",0);
             }
+        }else if(MesClient.scan_type == 2){ // 前梁压铸码
+            if(scanBarcodeSn.isEmpty()){
+                MesClient.setMenuStatus("前梁压铸码不能为空",1);
+                return;
+            }
+
+            String sn = "";
+            if(MesClient.curPage.equals("A")){
+                sn = product_sn.getText().trim();
+            }else{
+                sn = product_sn2.getText().trim();
+            }
+
+//            if(!checkSnAndBatch(sn,scanBarcodeSn)){
+//                MesClient.setMenuStatus("前梁压铸码与工件不匹配",1);
+//                return;
+//            }
+
+            JSONObject retObj = DataUtil.bindWarehouseData(sn,scanBarcodeSn,user_menu.getText().trim(),"400004");
+            if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
+                MesClient.setMenuStatus("前梁压铸码扫码绑定成功",0);
+                MesClient.formatScanType(1);
+                if(MesClient.curPage.equals("A")){
+                    textField.setText(scanBarcodeSn);
+                    batch_scan_1.setEnabled(true);
+                }else{
+                    textField_1.setText(scanBarcodeSn);
+                    batch_scan_2.setEnabled(true);
+                }
+                PlcUtil.changeEnable(s7PLC,true);
+            }else{
+                MesClient.formatScanType(2);
+                if(retObj.get("result")==null){
+                    MesClient.setMenuStatus("请求失败,前梁压铸码绑定失败,请重试",-1);
+                }else{
+                    if(retObj.get("result").toString().equalsIgnoreCase("false")){
+                        MesClient.setMenuStatus(retObj.getString("message"),-1);
+                    }
+                }
+            }
         }
     }
 
@@ -1602,13 +1667,13 @@ public class MesClient extends JFrame {
         },1000, 5000);
     }
 
-    public static void formatBatchSn(){
-        if((MesClient.batch_status == 1 && MesClient.tjFlaga == 1) || (MesClient.batch_status2 == 1 && MesClient.tjFlagb == 1)){
-            PlcUtil.changeEnable(MesClient.s7PLC,true);
-        }else{
-            PlcUtil.changeEnable(MesClient.s7PLC,false);
-        }
-    }
+//    public static void formatBatchSn(){
+//        if((MesClient.batch_status == 1 && MesClient.tjFlaga == 1) || (MesClient.batch_status2 == 1 && MesClient.tjFlagb == 1)){
+//            PlcUtil.changeEnable(MesClient.s7PLC,true);
+//        }else{
+//            PlcUtil.changeEnable(MesClient.s7PLC,false);
+//        }
+//    }
 
     private static String checkSnType(String sn){
         String str = sn.substring(9,12);
@@ -1622,17 +1687,17 @@ public class MesClient extends JFrame {
     }
 
     // 检查工件是否匹配
-    private static Boolean checkSnAndBatch(String sn,String batchSn){
-        String gdStr1 = "151245P000012131001000"; // MX11-2
-        String gdStr2 = "151245P000017812001000"; // MX11-2S
-        String cate = sn.substring(0,22);
-        String ptype = checkSnType(batchSn);
-        if(ptype.equals("MX11-2") && cate.equals(gdStr1)){
-            return true;
-        }
-        if(ptype.equals("MX11-2S") && cate.equals(gdStr2)){
-            return true;
-        }
-        return false;
-    }
+//    private static Boolean checkSnAndBatch(String sn,String batchSn){
+//        String gdStr1 = "151245P000012131001000"; // MX11-2
+//        String gdStr2 = "151245P000017812001000"; // MX11-2S
+//        String cate = sn.substring(0,22);
+//        String ptype = checkSnType(batchSn);
+//        if(ptype.equals("MX11-2") && cate.equals(gdStr1)){
+//            return true;
+//        }
+//        if(ptype.equals("MX11-2S") && cate.equals(gdStr2)){
+//            return true;
+//        }
+//        return false;
+//    }
 }

+ 5 - 7
src/com/mes/ui/MesRevice.java

@@ -68,21 +68,19 @@ public class MesRevice {
 
                 if(oprno.equals(MesClient.mes_gw+"A") || oprno.equals(MesClient.mes_gw+"C")){
                     MesClient.mesQualityFlagA = true;
-                    MesClient.pxstatus1.setText("A:可以加工,等待设备启动");
+                    MesClient.pxstatus1.setText("A:可以加工,请扫描前梁压铸码");
                     MesClient.curSna = MesClient.product_sn.getText();
                     MesClient.tjFlaga = 1;
-                    PlcUtil.changeEnable(MesClient.s7PLC,true);
 
                 }else{
                     MesClient.mesQualityFlagB = true;
-                    MesClient.pxstatus2.setText("B:可以加工,等待设备启动");
+                    MesClient.pxstatus2.setText("B:可以加工,请扫描前梁压铸码");
                     MesClient.curSnb = MesClient.product_sn2.getText();
                     MesClient.tjFlagb = 1;
-                    PlcUtil.changeEnable(MesClient.s7PLC,true);
                 }
-//                System.out.println("scan_type1:"+MesClient.scan_type);
-//                MesClient.formatScanType(2);// 1=镭雕码 2=后梁
-//                System.out.println("scan_type2:"+MesClient.scan_type);
+                System.out.println("scan_type1:"+MesClient.scan_type);
+                MesClient.formatScanType(2);// 1=镭雕码 2=前梁压铸
+                System.out.println("scan_type2:"+MesClient.scan_type);
 
 
             }

+ 126 - 99
src/com/mes/ui/PlcUtil.java

@@ -74,99 +74,99 @@ public class PlcUtil {
         }
     }
 
-    public static void getStatusAOld(S7PLC s7PLC){
-        String sna = "";
-        if(MesClient.tjFlaga == 1){ // 待运行
-            MesClient.checkA = 0;
-            Boolean starta = s7PLC.readBoolean("DB1.2.2"); //A启动中
-            if(starta){
-                MesClient.curFlag = "A";
-                MesClient.tjFlaga = 2;
-                MesClient.pxstatus1.setText("A:设备运行中");
-                PlcUtil.changeEnable(MesClient.s7PLC,false);
-            }
-        }else if(MesClient.tjFlaga == 2){ // 运行中
-            MesClient.batch_scan_1.setEnabled(false);
-            Boolean starta = s7PLC.readBoolean("DB1.2.5"); //A焊接完成
-            Boolean startb = s7PLC.readBoolean("DB1.2.3"); //B启动中
-            if(starta || startb){ // B启动中,A当做完成
-                MesClient.tjFlaga = 3;
-                MesClient.pxstatus1.setText("A:设备运行结束,提交结果中");
-                MesClient.finish_ok_bt.setEnabled(true);
-
-                Boolean sendret = DataUtil.sendQuality(MesClient.nettyClient,MesClient.product_sn.getText(),"OK",MesClient.user20,"A");
-                if(!sendret){
-                    MesClient.pxstatus1.setText("A:结果上传MES失败");
-                    MesClient.tjStatusa = 1;
-                }else{
-//                    MesClient.pxstatus1.setText("A:提交成功");
-//                    MesClient.status_menu.setText("A件提交成功");
-//                    MesClient.resetScanA();
-                }
-            }
-//            Boolean sa = s7PLC.readBoolean("DB1.2.2"); //A启动中
-//            if(!sa){
-//                MesClient.pxstatus1.setText("A:设备运行停止");
+//    public static void getStatusAOld(S7PLC s7PLC){
+//        String sna = "";
+//        if(MesClient.tjFlaga == 1){ // 待运行
+//            MesClient.checkA = 0;
+//            Boolean starta = s7PLC.readBoolean("DB1.2.2"); //A启动中
+//            if(starta){
+//                MesClient.curFlag = "A";
+//                MesClient.tjFlaga = 2;
+//                MesClient.pxstatus1.setText("A:设备运行中");
+//                PlcUtil.changeEnable(MesClient.s7PLC,false);
+//            }
+//        }else if(MesClient.tjFlaga == 2){ // 运行中
+//            MesClient.batch_scan_1.setEnabled(false);
+//            Boolean starta = s7PLC.readBoolean("DB1.2.5"); //A焊接完成
+//            Boolean startb = s7PLC.readBoolean("DB1.2.3"); //B启动中
+//            if(starta || startb){ // B启动中,A当做完成
+//                MesClient.tjFlaga = 3;
+//                MesClient.pxstatus1.setText("A:设备运行结束,提交结果中");
 //                MesClient.finish_ok_bt.setEnabled(true);
+//
+//                Boolean sendret = DataUtil.sendQuality(MesClient.nettyClient,MesClient.product_sn.getText(),"OK",MesClient.user20,"A");
+//                if(!sendret){
+//                    MesClient.pxstatus1.setText("A:结果上传MES失败");
+//                    MesClient.tjStatusa = 1;
+//                }else{
+////                    MesClient.pxstatus1.setText("A:提交成功");
+////                    MesClient.status_menu.setText("A件提交成功");
+////                    MesClient.resetScanA();
+//                }
 //            }
-        }
-    }
-
-    public static void getStatusBOld(S7PLC s7PLC){
-        String snb = "";
-        if(MesClient.tjFlagb == 0){ // 未扫码
-            snb = s7PLC.readString("DB8.100",50);
-            System.out.println("snb:"+snb);
-            if(!snb.isEmpty() && !MesClient.curSnb.equals(snb) && snb.length() == 33){
-                MesClient.product_sn2.setText(snb);
-            }else{
-                snb = "";
-            }
-            if(!MesClient.mesQualityFlagB && !snb.isEmpty() && MesClient.curSnb.isEmpty()){ // 查询工件质量
-                if(!MesClient.tcp_connect_flag) {
-                    MesClient.status_menu.setText("未连接MES服务器");
-                }else{
-                    if(MesClient.checkB == 0) {
-                        MesClient.checkB = 1;
-                        MesClient.getUser();
-                        Boolean sendret = DataUtil.checkQuality(MesClient.nettyClient,snb,MesClient.user20,"B");
-                        if(!sendret){
-                            MesClient.pxstatus2.setText("B:查询质量失败");
-                            MesClient.checkB = 0;
-                        }
-                    }
-                }
-            }
-        }else if(MesClient.tjFlagb == 1){ // 待运行
-            MesClient.checkB = 0;
-            Boolean startb = s7PLC.readBoolean("DB1.2.3"); //B启动中
-            if(startb){
-                MesClient.curFlag = "B";
-                MesClient.tjFlagb = 2;
-                MesClient.pxstatus2.setText("B:设备运行中");
-                PlcUtil.changeEnable(MesClient.s7PLC,false);
-            }
-        }else if(MesClient.tjFlagb == 2){ // 运行中
-            MesClient.batch_scan_2.setEnabled(false);
-            Boolean starta = s7PLC.readBoolean("DB1.2.7"); //B焊接完成
-            Boolean startb = s7PLC.readBoolean("DB1.2.2"); //A启动中
-            if(starta || startb){
-                MesClient.tjFlagb = 3;
-                MesClient.pxstatus2.setText("B:设备运行结束,提交结果中");
-                MesClient.finish_ng_bt.setEnabled(true);
-
-                Boolean sendret = DataUtil.sendQuality(MesClient.nettyClient,MesClient.product_sn2.getText(),"OK",MesClient.user20,"B");
-                if(!sendret){
-                    MesClient.pxstatus2.setText("B:结果上传MES失败");
-                    MesClient.tjStatusb = 1;
-                }else{
-//                    MesClient.pxstatus2.setText("B:提交成功");
-//                    MesClient.status_menu.setText("B件提交成功");
-//                    MesClient.resetScanB();
-                }
-            }
-        }
-    }
+////            Boolean sa = s7PLC.readBoolean("DB1.2.2"); //A启动中
+////            if(!sa){
+////                MesClient.pxstatus1.setText("A:设备运行停止");
+////                MesClient.finish_ok_bt.setEnabled(true);
+////            }
+//        }
+//    }
+
+//    public static void getStatusBOld(S7PLC s7PLC){
+//        String snb = "";
+//        if(MesClient.tjFlagb == 0){ // 未扫码
+//            snb = s7PLC.readString("DB8.100",50);
+//            System.out.println("snb:"+snb);
+//            if(!snb.isEmpty() && !MesClient.curSnb.equals(snb) && snb.length() == 33){
+//                MesClient.product_sn2.setText(snb);
+//            }else{
+//                snb = "";
+//            }
+//            if(!MesClient.mesQualityFlagB && !snb.isEmpty() && MesClient.curSnb.isEmpty()){ // 查询工件质量
+//                if(!MesClient.tcp_connect_flag) {
+//                    MesClient.status_menu.setText("未连接MES服务器");
+//                }else{
+//                    if(MesClient.checkB == 0) {
+//                        MesClient.checkB = 1;
+//                        MesClient.getUser();
+//                        Boolean sendret = DataUtil.checkQuality(MesClient.nettyClient,snb,MesClient.user20,"B");
+//                        if(!sendret){
+//                            MesClient.pxstatus2.setText("B:查询质量失败");
+//                            MesClient.checkB = 0;
+//                        }
+//                    }
+//                }
+//            }
+//        }else if(MesClient.tjFlagb == 1){ // 待运行
+//            MesClient.checkB = 0;
+//            Boolean startb = s7PLC.readBoolean("DB1.2.3"); //B启动中
+//            if(startb){
+//                MesClient.curFlag = "B";
+//                MesClient.tjFlagb = 2;
+//                MesClient.pxstatus2.setText("B:设备运行中");
+//                PlcUtil.changeEnable(MesClient.s7PLC,false);
+//            }
+//        }else if(MesClient.tjFlagb == 2){ // 运行中
+//            MesClient.batch_scan_2.setEnabled(false);
+//            Boolean starta = s7PLC.readBoolean("DB1.2.7"); //B焊接完成
+//            Boolean startb = s7PLC.readBoolean("DB1.2.2"); //A启动中
+//            if(starta || startb){
+//                MesClient.tjFlagb = 3;
+//                MesClient.pxstatus2.setText("B:设备运行结束,提交结果中");
+//                MesClient.finish_ng_bt.setEnabled(true);
+//
+//                Boolean sendret = DataUtil.sendQuality(MesClient.nettyClient,MesClient.product_sn2.getText(),"OK",MesClient.user20,"B");
+//                if(!sendret){
+//                    MesClient.pxstatus2.setText("B:结果上传MES失败");
+//                    MesClient.tjStatusb = 1;
+//                }else{
+////                    MesClient.pxstatus2.setText("B:提交成功");
+////                    MesClient.status_menu.setText("B件提交成功");
+////                    MesClient.resetScanB();
+//                }
+//            }
+//        }
+//    }
 
     public static void getStatusA(S7PLC s7PLC){
         if(MesClient.tjFlaga == 1){ // 已扫码,设备未运行
@@ -175,12 +175,9 @@ public class PlcUtil {
                 MesClient.curFlag = "A";
                 MesClient.tjFlaga = 2;
                 MesClient.pxstatus1.setText("A:设备运行中");
-//                MesClient.formatScanType(1);
-//                MesClient.batch_scan_1.setEnabled(false);
+                MesClient.formatScanType(1);
+                MesClient.batch_scan_1.setEnabled(false);
                 PlcUtil.changeEnable(s7PLC,false);
-            }else{
-                    PlcUtil.changeEnable(s7PLC,true);
-
             }
         }else if(MesClient.tjFlaga == 2){
             Boolean afinish = getAFinish(s7PLC); //A焊接完成
@@ -209,9 +206,6 @@ public class PlcUtil {
                 MesClient.batch_scan_2.setEnabled(false);
                 MesClient.formatScanType(1);
                 PlcUtil.changeEnable(s7PLC,false);
-            }else{
-                    PlcUtil.changeEnable(s7PLC,true);
-
             }
         }else if(MesClient.tjFlagb == 2){
             Boolean bfinish = getBFinish(s7PLC); //B焊接完成
@@ -291,6 +285,39 @@ public class PlcUtil {
         }
     }
 
+    // 校验工件码与PLC程序号是否匹配(二驱/四驱)
+    // 程序号存储点位:A面DB8.5.0,B面DB8.6.0;值为1对应二驱,值为2对应四驱
+    // 返回null表示匹配通过,否则返回错误信息
+    public static String checkBarcodeProgram(S7PLC s7PLC, String barcode, String page){
+        try{
+            byte program;
+            if("A".equals(page)){
+                program = s7PLC.readByte("DB8.5.0");
+            }else{
+                program = s7PLC.readByte("DB8.6.0");
+            }
+            String plcDrive;
+            if(program == 1){
+                plcDrive = "二驱";
+            }else if(program == 2){
+                plcDrive = "四驱";
+            }else{
+                return "PLC程序号异常(值:"+program+"),无法校验二驱/四驱";
+            }
+            String snDrive = MesClient.getDriveTypeByBarcode(barcode);
+            if(snDrive.isEmpty()){
+                return "无法识别工件码的二驱/四驱类型";
+            }
+            if(!snDrive.equals(plcDrive)){
+                return "工件码与程序不匹配:当前程序为"+plcDrive+",工件码为"+snDrive;
+            }
+            return null;
+        }catch (Exception e){
+            e.printStackTrace();
+            return "读取PLC程序号失败,无法校验二驱/四驱";
+        }
+    }
+
     // 获取当前是A面还是B面
     public static String getCurAside(S7PLC s7PLC){
         String str = "A";