Jelajahi Sumber

e38-气密自动扫码工装新增扫码

张田野 1 hari lalu
induk
melakukan
d843fa054d

+ 60 - 54
src/com/mes/ui/MesClient.java

@@ -133,7 +133,10 @@ public class MesClient extends JFrame {
     public static List<TaskParam> taskParamList = new ArrayList<>();
     public static TaskParam curTaskParam = null;
 
-    public static TCPClient tcpClient1 = new TCPClient("192.168.18.182",9004);
+    //OP260扫码枪
+    public static TCPClient tcpClient1 = new TCPClient("192.168.17.50",9004);
+    //OP350扫码枪
+//    public static TCPClient tcpClient1 = new TCPClient("192.168.17.52",9004);
     public static int scanFlag1 = 0;
 
     public static void main(String[] args) {
@@ -338,15 +341,28 @@ public class MesClient extends JFrame {
         mesStartFlag = 0;
         curTaskName.setText("");
 
-//        f_scan_data_bt_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/scan_barcode.png")));
-//        f_scan_data_bt_1.setText("扫码");
-//        MesClient.f_scan_data_bt_1.setEnabled(true);
+        setScanButtonText("扫码");
         MesClient.setMenuStatus("请扫工件码",0);
 
 //        MesClient.result.setText("等待结果");
 //        MesClient.result.setForeground(Color.GRAY);
     }
 
+    public static void setScanButtonText(String text) {
+        if(f_scan_data_bt_1 == null){
+            return;
+        }
+        Runnable update = () -> {
+            f_scan_data_bt_1.setIcon(null);
+            f_scan_data_bt_1.setText(text);
+        };
+        if(SwingUtilities.isEventDispatchThread()){
+            update.run();
+        }else{
+            SwingUtilities.invokeLater(update);
+        }
+    }
+
     public static int userLoginHours;//用户登录所处小时
     public static JTextField param1;
     public static JTextField param2;
@@ -618,64 +634,57 @@ public class MesClient extends JFrame {
         }
     }
 
+    /** 输入框回车 / 键盘楔入式扫码枪:使用输入框内容,不触发 TCP 扫码 */
+    public static void scanBarcodeFromInput() {
+        if(work_status == 1){
+            MesClient.serialPortUtils.start();
+            return;
+        }
+        handleProductSn(product_sn.getText().trim());
+    }
+
+    /** 扫码按钮:空闲时 TCP 扫码;已扫码等待时执行启动 */
     public static void scanBarcode2() {
         if(work_status == 1){
-//            MesClient.serialPortUtils.sendData("START");
+            MesClient.serialPortUtils.start();
             return;
         }
-//        String scanBarcode = product_sn.getText().trim();
-        String scanBarcode = MesClient.scanQrcode();
+        // 扫码在后台线程执行,避免阻塞 Swing 界面线程导致卡顿
+        if(scanFlag1 == 1){
+            return;
+        }
+        setMenuStatus("正在扫码,请对准条码...", 0);
+        if(f_scan_data_bt_1 != null){
+            f_scan_data_bt_1.setEnabled(false);
+        }
+        new Thread(() -> {
+            String scanBarcode = MesClient.scanQrcode();
+            SwingUtilities.invokeLater(() -> {
+                if(f_scan_data_bt_1 != null){
+                    f_scan_data_bt_1.setEnabled(true);
+                }
+                String sn = scanBarcode == null ? "" : scanBarcode.trim();
+                if(sn.isEmpty()){
+                    setMenuStatus("扫码超时或未识别,请重试", 1);
+                    product_sn.setText("");
+                    return;
+                }
+                handleProductSn(sn);
+            });
+        }, "tcp-barcode-scan").start();
+    }
+
+    public static void handleProductSn(String scanBarcode) {
         //刷新界面
         mesClientFrame.repaint();
 
-        if(scanBarcode.isEmpty()){
+        if(scanBarcode == null || scanBarcode.isEmpty()){
             MesClient.setMenuStatus("工件码不能为空",1);
             product_sn.setText("");
             return;
         }
         MesClient.product_sn.setText(scanBarcode);
 
-//        // 验证工件码前缀
-//        if(MesClient.configParam.getProductSnPre() != null && !MesClient.configParam.getProductSnPre().trim().isEmpty()) {
-//            int preLen = MesClient.configParam.getProductSnPre().trim().length();
-//            if(preLen > scanBarcode.length()){
-//                MesClient.setMenuStatus("工件码前缀不符合要求",-1);
-//                product_sn.setText("");
-//                return;
-//            }else{
-//                String pre = scanBarcode.substring(0,preLen);
-//                if(!pre.equals(MesClient.configParam.getProductSnPre().trim())){
-//                    MesClient.setMenuStatus("工件码前缀不符合要求",-1);
-//                    product_sn.setText("");
-//                    return;
-//                }
-//            }
-//        }
-//
-//        //验证工件码长度
-//        int snLen = MesClient.configParam.getProductSnLength() != null && MesClient.configParam.getProductSnLength().trim().isEmpty() ? 0 : Integer.valueOf(MesClient.configParam.getProductSnLength());
-//        if(snLen > 0 && snLen != scanBarcode.length()) {
-//            MesClient.setMenuStatus("工件码长度不符合要求",-1);
-//            product_sn.setText("");
-//            return;
-//        }
-
-//        // 验证NG
-//        int isCheck = JdbcUtils.checkSnTimer(scanBarcode,configParam);
-//        System.err.println("isCheck:" + isCheck);
-//        if(isCheck == 1){
-//            int ngTime = Integer.valueOf(configParam.getNgTime());
-//            MesClient.setMenuStatus("工件码测试NG必须间隔"+ngTime+"分钟",-1);
-//            product_sn.setText("");
-//            return;
-//        } else if(isCheck == 2){
-//            int ngUpgradeTime = Integer.valueOf(configParam.getNgUpgradeTime());
-//            int ngNumber = Integer.valueOf(configParam.getNgNumber());
-//            MesClient.setMenuStatus("工件码测试NG"+ngNumber+"次,必须间隔"+ngUpgradeTime+"分钟",-1);
-//            product_sn.setText("");
-//            return;
-//        }
-
         if(checkProductSn(scanBarcode.trim())){
             serialPortUtils.changeProgram(); // 切换程序
             if(MesClient.mes_enable){
@@ -691,6 +700,7 @@ public class MesClient extends JFrame {
                 MesClient.tjFlag = 1;
                 MesClient.setMenuStatus("扫码成功,等待测试",0);
                 product_sn.setEditable(false);
+                setScanButtonText("启动");
                 if(MesClient.configParam.getStartMode().equals("自动启动")){
                     MesClient.serialPortUtils.start();
                 }
@@ -698,9 +708,6 @@ public class MesClient extends JFrame {
                 MesClient.result.setForeground(Color.GRAY);
             }
         }
-//        f_scan_data_bt_1.setIcon(null);
-//        f_scan_data_bt_1.setText("启动");
-
     }
 
     public static void scanBarcodeOld() {
@@ -944,7 +951,7 @@ public class MesClient extends JFrame {
         product_sn.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
                 scan_type = 1;
-                scanBarcode2();
+                scanBarcodeFromInput();
             }
         });
 
@@ -953,7 +960,6 @@ public class MesClient extends JFrame {
         f_scan_data_bt_1.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
                 scan_type = 1;
-//                scanBarcode();
                 scanBarcode2();
             }
         });

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

@@ -18,6 +18,7 @@ public class MesRevice {
                 MesClient.tjFlag = 1;
                 MesClient.setMenuStatus("该工件可以测试,等待测试",0);
                 MesClient.product_sn.setEditable(false);
+                MesClient.setScanButtonText("启动");
                 if(MesClient.configParam.getStartMode().equals("自动启动")){
                     MesClient.serialPortUtils.start();
                 }

+ 2 - 20
src/com/mes/ui/OprnoUtil.java

@@ -6,28 +6,10 @@ import java.util.Map;
 
 public class OprnoUtil {
     public static String[] xtoprnos = new String[]{
-            "OP070","OP080", "OP100",
-            "OP110", "OP120", "OP130", "OP140", "OP150",
-            "OP160", "OP170", "OP180", "OP190", "OP200",
-            "OP210", "OP220", "OP230", "OP240", "OP250",
-            "OP260", "OP270", "OP280", "OP290", "OP300",
-            "OP310", "OP320", "OP330", "OP340", "OP350",
-            "OP360", "OP370", "OP380", "OP390", "OP400",
-            "OP410", "OP420", "OP430", "OP440", "OP450",
-            "OP460", "OP470", "OP480", "OP490", "OP500",
-            "OP510", "OP520", "OP550"
+            "OP260","OP350"
     };
     public static String[] xtoprnodes = new String[]{
-            "右边梁镭雕二维码","左边梁防爆阀拉铆","CMT框架一序焊接",
-            "人工补焊", "框架CMT二序焊接", "人工补焊", "焊道检查", "总成正面CNC",
-            "总成反面CNC", "框架去毛刺+清洁", "封堵片焊接+打磨", "边框气密", "焊道补焊",
-            "框架反面涂胶", "液冷板安装", "正面溢胶清理,补胶", "液冷板激光点固", "液冷板水嘴处焊接",
-            "焊道打磨", "液冷板FSW", "匙孔补焊打磨", "总成反面拉铆", "总成正面拉铆1",
-            "总成正面拉铆2", "边梁套筒涂胶+压合", "箱体封堵", "胶水固化", "半成品气密",
-            "补强板安装", "胶水固化", "拆卸补强板压紧工装", "FSW焊道涂胶+双层拉铆螺母涂胶", "人工抹胶",
-            "胶水固化", "反面部件装配", "底护板装配+底部套筒螺母安装", "底护板螺栓复拧", "总成气密",
-            "液冷板气密", "总成正面装配", "总成清洁", "总成检具检验", "模拟客户安装界面(装)",
-            "CCD", "GP12", "称重"
+            "半成品气密","成品气密"
     };
     public static String[] lboprnos = new String[]{
 

+ 12 - 7
src/com/mes/util/TCPClient.java

@@ -60,21 +60,26 @@ public class TCPClient {
             });
 
             try {
-                // 尝试在10秒内获取结果
-                return future.get(10, TimeUnit.SECONDS);
+                // 等待扫码结果;超时后结束等待(默认 3 秒)
+                return future.get(3, TimeUnit.SECONDS);
             } catch (TimeoutException e) {
-                // 处理超时情况future.cancel(true);
                 future.cancel(true);
                 throw new TimeoutException("Read operation timed out");
             }
         } catch (TimeoutException e) {
-            this.sendCommand("LOFF\r\n");
-//            this.setMenuStatus("扫码枪识别超时,请重试",1);
+            try {
+                this.sendCommand("LOFF\r\n");
+            } catch (Exception ignore) {
+            }
+            // 关闭连接以打断阻塞的 readLine
+            close();
             e.printStackTrace();
             return null;
         } catch (Exception e) {
-            this.sendCommand("LOFF\r\n");
-//            this.setMenuStatus("扫码枪连接异常,请重试",1);
+            try {
+                this.sendCommand("LOFF\r\n");
+            } catch (Exception ignore) {
+            }
             close();
             e.printStackTrace();
             return null;

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

@@ -1,6 +1,7 @@
-mes.gw=OP370A
+mes.gw=OP260A
+#mes.gw=OP350A
 #mes.server_ip=127.0.0.1
-mes.server_ip=192.168.18.99
+mes.server_ip=192.168.15.99
 mes.tcp_port=3000
 mes.heart_beat_cycle=60
 mes.line_sn=XT