zxl hace 3 semanas
padre
commit
28d6ee4505

+ 83 - 58
src/com/mes/ui/MesClient.java

@@ -13,7 +13,6 @@ import com.mes.util.DateLocalUtils;
 import com.mes.util.HttpUtils;
 import com.mes.util.HttpUtils;
 import com.mes.util.JdbcUtils;
 import com.mes.util.JdbcUtils;
 import com.mes.util.S7Util;
 import com.mes.util.S7Util;
-import javafx.embed.swing.JFXPanel;
 import com.github.xingshuangs.iot.protocol.s7.enums.EPlcType;
 import com.github.xingshuangs.iot.protocol.s7.enums.EPlcType;
 import com.github.xingshuangs.iot.protocol.s7.service.S7PLC;
 import com.github.xingshuangs.iot.protocol.s7.service.S7PLC;
 import org.slf4j.Logger;
 import org.slf4j.Logger;
@@ -50,7 +49,7 @@ public class MesClient extends JFrame {
     public static int mes_tcp_port = 3000; // TCP服务端口
     public static int mes_tcp_port = 3000; // TCP服务端口
     public static int mes_heart_beat_cycle = 10; // 心跳周期
     public static int mes_heart_beat_cycle = 10; // 心跳周期
     public static int mes_heart_icon_cycle = 1;
     public static int mes_heart_icon_cycle = 1;
-    public static S7PLC s7PLC = new S7PLC(EPlcType.S1200, "192.168.10.10"); //
+    public static S7PLC s7PLC = new S7PLC(EPlcType.S1200, "192.168.11.10"); //
     public static String mes_line_sn = ""; // 产线编号
     public static String mes_line_sn = ""; // 产线编号
 
 
     //TCP连接
     //TCP连接
@@ -74,7 +73,7 @@ public class MesClient extends JFrame {
 
 
     public static Boolean check_quality_result = false;
     public static Boolean check_quality_result = false;
     public static Integer work_status = 0;  //0=未开始 1=进行中
     public static Integer work_status = 0;  //0=未开始 1=进行中
-    public static Integer work_status_next = 0; // 下一件
+    public static Integer work_status_next = 0; // 预留
 
 
     public static JButton heart_beat_menu;
     public static JButton heart_beat_menu;
     public static JButton status_menu;
     public static JButton status_menu;
@@ -90,7 +89,7 @@ public class MesClient extends JFrame {
     public static JButton finish_ng_bt_test;
     public static JButton finish_ng_bt_test;
     public static JTextField product_sn;
     public static JTextField product_sn;
     public static JTextField product_sn_test;
     public static JTextField product_sn_test;
-    public static JTextField product_sn_next;
+    public static JTextField product_sn_waiting;
     public static JButton f_scan_data_bt_1;
     public static JButton f_scan_data_bt_1;
     public static JButton f_scan_data_bt_1_test;
     public static JButton f_scan_data_bt_1_test;
 
 
@@ -156,7 +155,9 @@ public class MesClient extends JFrame {
         cjTimer.schedule(new TimerTask() {
         cjTimer.schedule(new TimerTask() {
             public void run() {
             public void run() {
                 try{
                 try{
-                    if(!MesClient.sessionid.isEmpty() && MesClient.work_status == 0){
+                    // 空闲可扫;等待结果时可扫下一件进 product_sn;product_sn 已有码则提示不覆盖
+                    if(!MesClient.sessionid.isEmpty()
+                            && (MesClient.work_status == 0 || !product_sn_waiting.getText().isEmpty())){
                         //获取扫码状态
                         //获取扫码状态
                         Boolean statusSn = S7Util.getStatusSn(s7PLC);
                         Boolean statusSn = S7Util.getStatusSn(s7PLC);
                         log.info("获取扫码状态:"+statusSn);
                         log.info("获取扫码状态:"+statusSn);
@@ -166,8 +167,14 @@ public class MesClient extends JFrame {
                             log.info("scanBarcode:"+scanBarcode);
                             log.info("scanBarcode:"+scanBarcode);
                             s7PLC.writeBoolean("DB71.0.0",false); // 重置扫码状态
                             s7PLC.writeBoolean("DB71.0.0",false); // 重置扫码状态
 
 
-                            if(!product_sn_next.getText().isEmpty() && product_sn_next.getText().equals(scanBarcode)){
-//                                MesClient.setMenuStatus("该工件等待结果中,勿重复扫码",-1);
+                            String waitingSn = product_sn_waiting.getText();
+                            String currentSn = product_sn.getText();
+                            if(!waitingSn.isEmpty() && waitingSn.equals(scanBarcode)){
+                                // 当前等待结果的件,忽略重复扫码
+                            }else if(!currentSn.isEmpty() && currentSn.equals(scanBarcode)){
+                                // 已在 product_sn 的同一件,忽略
+                            }else if(!currentSn.isEmpty()){
+                                setMenuStatus("已有待接工件["+currentSn+"],请先等上件结果上传",1);
                             }else{
                             }else{
                                 scanStatus = 1;
                                 scanStatus = 1;
                                 productSnSetValue(scanBarcode);
                                 productSnSetValue(scanBarcode);
@@ -189,12 +196,20 @@ public class MesClient extends JFrame {
         cjTimer2.schedule(new TimerTask() {
         cjTimer2.schedule(new TimerTask() {
             public void run() {
             public void run() {
                 try{
                 try{
-                    String sn = product_sn_next.getText();
-                    if(!sn.isEmpty()){ // 监控结果
+                    String sn = product_sn_waiting.getText();
+                    if(!sn.isEmpty()){ // 只监控等待结果槽,不碰 product_sn
                         //检测结束信号
                         //检测结束信号
                         Boolean detectionEnd = S7Util.getDetectionEnd(s7PLC);
                         Boolean detectionEnd = S7Util.getDetectionEnd(s7PLC);
                         log.info("监控["+sn+"]结果状态:"+detectionEnd);
                         log.info("监控["+sn+"]结果状态:"+detectionEnd);
                         if (detectionEnd){
                         if (detectionEnd){
+                            // 结束核对:以 PLC 结束 SN 为准,只改 waiting
+                            String endSn = S7Util.getDetectionEndSn(s7PLC);
+                            if(endSn != null && !endSn.trim().isEmpty() && !endSn.equals(sn)){
+                                log.info("结束SN不一致, waiting["+sn+"] -> PLC["+endSn+"]");
+                                product_sn_waiting.setText(endSn);
+                                sn = endSn;
+                            }
+
                             MesClient.setMenuStatus(MesClient.tjFlagText3,0);
                             MesClient.setMenuStatus(MesClient.tjFlagText3,0);
                             MesClient.finish_ok_bt.setEnabled(true);
                             MesClient.finish_ok_bt.setEnabled(true);
                             MesClient.finish_ng_bt.setEnabled(true);
                             MesClient.finish_ng_bt.setEnabled(true);
@@ -205,7 +220,7 @@ public class MesClient extends JFrame {
                                 if (detectionResult.equals("OK") || detectionResult.equals("NG")){//读取成功
                                 if (detectionResult.equals("OK") || detectionResult.equals("NG")){//读取成功
                                     sendFeedback(s7PLC,true);
                                     sendFeedback(s7PLC,true);
                                 }
                                 }
-                                //提交结果到MES
+                                //提交结果到MES(始终用 waiting)
                                 Boolean ret = DataUtil.sendQuality(MesClient.nettyClient,sn,detectionResult,MesClient.user20);
                                 Boolean ret = DataUtil.sendQuality(MesClient.nettyClient,sn,detectionResult,MesClient.user20);
                                 if(!ret){
                                 if(!ret){
                                     MesClient.tjStatus = 1; // 未提交成功
                                     MesClient.tjStatus = 1; // 未提交成功
@@ -248,45 +263,49 @@ public class MesClient extends JFrame {
     }
     }
     public static void scanToEnd( ) {
     public static void scanToEnd( ) {
         try {
         try {
-            if(work_status == 1){
+            String waitingSn = product_sn_waiting.getText();
+            if(waitingSn == null || waitingSn.isEmpty()){
+                return;
+            }
 
 
-                //已扫码
-                if (tjFlag == 1){
+            //已扫码
+            if (tjFlag == 1){
+                tjFlag=2;
+                MesClient.status_menu.setText(MesClient.tjFlagText2);
+            }
+            //运行中
+            if (tjFlag == 2){
+                //检测结束信号
+                Boolean detectionEnd = S7Util.getDetectionEnd(s7PLC);
+                if (detectionEnd){
+                    //结束核对:只改 waiting,不碰 product_sn
+                    String scanBarcode = S7Util.getDetectionEndSn(s7PLC);
+                    if(scanBarcode != null && !scanBarcode.trim().isEmpty()
+                            && !scanBarcode.equals(waitingSn)) {
+                        product_sn_waiting.setText(scanBarcode);
+                        waitingSn = scanBarcode;
+                    }
 
 
-                    tjFlag=2;
-                    MesClient.status_menu.setText(MesClient.tjFlagText2);
+                    tjFlag=3;
+                    MesClient.status_menu.setText(MesClient.tjFlagText3);
+                    MesClient.finish_ok_bt.setEnabled(true);
+                    MesClient.finish_ng_bt.setEnabled(true);
+                    if(tjStatus == 0){
 
 
-                }
-                //运行中
-                if (tjFlag == 2){
-                    //检测结束信号
-                    Boolean detectionEnd = S7Util.getDetectionEnd(s7PLC);
-                    if (detectionEnd){
-                        tjFlag=3;
-                        MesClient.status_menu.setText(MesClient.tjFlagText3);
-                        MesClient.finish_ok_bt.setEnabled(true);
-                        MesClient.finish_ng_bt.setEnabled(true);
-                        if(tjStatus == 0){
+                        String detectionResult = S7Util.getDetectionResult(s7PLC);// 获取检测结果
+                        if (!detectionResult.equals("")){//读取成功
+                            sendFeedback(s7PLC,true);
+                        }
 
 
-                            String detectionResult = S7Util.getDetectionResult(s7PLC);// 获取检测结果
-                            if (!detectionResult.equals("")){//读取成功
-                                sendFeedback(s7PLC,true);
-                            }
-                            //提交结果到MES
-                            Boolean ret = DataUtil.sendQuality(MesClient.nettyClient,MesClient.product_sn.getText(),detectionResult,MesClient.user20);
-                            if(!ret){
-                                MesClient.tjStatus = 1; // 未提交成功
-                                setMenuStatus("结果上传MES失败,请重试",1);
+                        //提交结果到MES
+                        Boolean ret = DataUtil.sendQuality(MesClient.nettyClient,waitingSn,detectionResult,MesClient.user20);
+                        if(!ret){
+                            MesClient.tjStatus = 1; // 未提交成功
+                            setMenuStatus("结果上传MES失败,请重试",1);
 //                                new MyDialog(MesClient.mesClientFrame,MesClient.tcTitle,MesClient.tjFlagTextErr);
 //                                new MyDialog(MesClient.mesClientFrame,MesClient.tcTitle,MesClient.tjFlagTextErr);
-                            }
                         }
                         }
-
-
                     }
                     }
                 }
                 }
-
-            }else{
-
             }
             }
         } catch (Exception e) {
         } catch (Exception e) {
             e.printStackTrace();
             e.printStackTrace();
@@ -546,7 +565,7 @@ public class MesClient extends JFrame {
 
 
     public static void resetScanA() {
     public static void resetScanA() {
 
 
-        //重置扫码状态
+        //重置扫码状态(上传成功后清 waiting;保留 product_sn,有下一件则接上)
         work_status = 0;
         work_status = 0;
         scan_type=1;
         scan_type=1;
 //        tjFlag = 0;
 //        tjFlag = 0;
@@ -556,7 +575,7 @@ public class MesClient extends JFrame {
         check_quality_result = false;
         check_quality_result = false;
         MesClient.finish_ok_bt.setEnabled(false);
         MesClient.finish_ok_bt.setEnabled(false);
         MesClient.finish_ng_bt.setEnabled(false);
         MesClient.finish_ng_bt.setEnabled(false);
-        product_sn_next.setText("");
+        product_sn_waiting.setText("");
 
 
         formatResult();
         formatResult();
 
 
@@ -564,8 +583,10 @@ public class MesClient extends JFrame {
 //		DataUtil.stopWork(sessionid);
 //		DataUtil.stopWork(sessionid);
 //        MesClient.status_menu.setText("MES等待扫码信号");
 //        MesClient.status_menu.setText("MES等待扫码信号");
 
 
-//        重置plc扫码状态
-        S7Util.sendRestJianCe(s7PLC);
+        // 无下一件才彻底复位 PLC;有下一件已在 startWork 时放行检测,避免打断
+        if(product_sn_waiting.getText().isEmpty()){
+            S7Util.sendRestJianCe(s7PLC);
+        }
 //        shiftUserCheck();
 //        shiftUserCheck();
     }
     }
 
 
@@ -644,10 +665,14 @@ public class MesClient extends JFrame {
         MesClient.status_menu.setText(msg);
         MesClient.status_menu.setText(msg);
     }
     }
 
 
+    /** waiting 空时把 product_sn 接到等待结果槽;waiting 占用时保留 product_sn 不覆盖 */
     public static void formatResult(){
     public static void formatResult(){
-        if(MesClient.product_sn_next.getText().isEmpty()){
-            MesClient.product_sn_next.setText(MesClient.product_sn.getText());
-            MesClient.product_sn.setText("");
+        if(MesClient.product_sn_waiting.getText().isEmpty()){
+            String nextSn = MesClient.product_sn.getText();
+            if(nextSn != null && !nextSn.isEmpty()){
+                MesClient.product_sn_waiting.setText(nextSn);
+                MesClient.product_sn.setText("");
+            }
             MesClient.f_scan_data_bt_1.setEnabled(true);
             MesClient.f_scan_data_bt_1.setEnabled(true);
             MesClient.tjFlag = 0;
             MesClient.tjFlag = 0;
             MesClient.work_status = 0;
             MesClient.work_status = 0;
@@ -891,15 +916,15 @@ public class MesClient extends JFrame {
         nextLabel.setBounds(165, 170, 602, 70);
         nextLabel.setBounds(165, 170, 602, 70);
         indexPanelA.add(nextLabel);
         indexPanelA.add(nextLabel);
 
 
-        product_sn_next = new JTextField("");
-        product_sn_next.setHorizontalAlignment(SwingConstants.CENTER);
-        product_sn_next.setEditable(false);
-        product_sn_next.setFont(new Font("微软雅黑", Font.PLAIN, 28));
-        product_sn_next.setBounds(165, 230, 602, 70);
-        indexPanelA.add(product_sn_next);
-        product_sn_next.addMouseListener(new MouseAdapter() {
+        product_sn_waiting = new JTextField("");
+        product_sn_waiting.setHorizontalAlignment(SwingConstants.CENTER);
+        product_sn_waiting.setEditable(false);
+        product_sn_waiting.setFont(new Font("微软雅黑", Font.PLAIN, 28));
+        product_sn_waiting.setBounds(165, 230, 602, 70);
+        indexPanelA.add(product_sn_waiting);
+        product_sn_waiting.addMouseListener(new MouseAdapter() {
             public void mouseClicked(MouseEvent e) {
             public void mouseClicked(MouseEvent e) {
-                createQRCode(product_sn_next.getText());
+                createQRCode(product_sn_waiting.getText());
             }
             }
         });
         });
 
 
@@ -926,7 +951,7 @@ public class MesClient extends JFrame {
         finish_ok_bt.setEnabled(false);
         finish_ok_bt.setEnabled(false);
         finish_ok_bt.addActionListener(new ActionListener() {
         finish_ok_bt.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
             public void actionPerformed(ActionEvent e) {
-                String sn = getBarcode(product_sn_next.getText());
+                String sn = getBarcode(product_sn_waiting.getText());
                 if(!sn.isEmpty()){
                 if(!sn.isEmpty()){
                     getUser();
                     getUser();
                     String qret = "OK";
                     String qret = "OK";
@@ -948,7 +973,7 @@ public class MesClient extends JFrame {
         finish_ng_bt.setEnabled(false);
         finish_ng_bt.setEnabled(false);
         finish_ng_bt.addActionListener(new ActionListener() {
         finish_ng_bt.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
             public void actionPerformed(ActionEvent e) {
-                String sn = getBarcode(product_sn_next.getText());
+                String sn = getBarcode(product_sn_waiting.getText());
                 if(!sn.isEmpty()){
                 if(!sn.isEmpty()){
                     getUser();
                     getUser();
                     String qret = "NG";
                     String qret = "NG";

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

@@ -107,7 +107,12 @@ public class MesRevice {
             if(processMsgRet.equalsIgnoreCase("OK")) {
             if(processMsgRet.equalsIgnoreCase("OK")) {
 
 
                 MesClient.resetScanA();
                 MesClient.resetScanA();
-                MesClient.status_menu.setText("结果提交成功,请扫下一件");
+                String waiting = MesClient.product_sn_waiting.getText();
+                if(waiting != null && !waiting.isEmpty()){
+                    MesClient.setMenuStatus("上件结果已上传,当前等待结果:"+waiting,0);
+                }else{
+                    MesClient.setMenuStatus("结果提交成功,请扫下一件",0);
+                }
 //                MesClient.scan_type = 1;
 //                MesClient.scan_type = 1;
 //                MesClient.scanBarcode();
 //                MesClient.scanBarcode();
 
 

+ 12 - 0
src/com/mes/util/S7Util.java

@@ -98,4 +98,16 @@ public class S7Util {
             e.printStackTrace();
             e.printStackTrace();
         }
         }
     }
     }
+
+    //检测结束时获取二维码,用来对比开始扫描二维码是否与现在读取二维码一致
+    public static String getDetectionEndSn(S7PLC s7PLC){
+        try {
+            String sn =s7PLC.readString("DB71.46",33);
+            return sn;
+        } catch (Exception e) {
+            e.printStackTrace();
+            return "";
+        }
+    }
+
 }
 }

+ 1 - 1
src/com/mes/util/Test.java

@@ -6,7 +6,7 @@ import com.github.xingshuangs.iot.protocol.s7.service.S7PLC;
 public class Test {
 public class Test {
 
 
     public static void main(String[] args) {
     public static void main(String[] args) {
-        S7PLC s7PLC = new S7PLC(EPlcType.S1200, "192.168.0.1"); // 供胶系统
+        S7PLC s7PLC = new S7PLC(EPlcType.S1200, "192.168.0.1");
         System.out.println("是否已扫码"+s7PLC.readBoolean("DB50.0.0"));
         System.out.println("是否已扫码"+s7PLC.readBoolean("DB50.0.0"));
         System.out.println("是否检测结束"+s7PLC.readBoolean("DB50.0.1"));
         System.out.println("是否检测结束"+s7PLC.readBoolean("DB50.0.1"));
         System.out.println("检测结果是否OK"+s7PLC.readBoolean("DB50.2"));
         System.out.println("检测结果是否OK"+s7PLC.readBoolean("DB50.2"));