wangxichen 2 dienas atpakaļ
vecāks
revīzija
7e710b6b63

+ 18 - 35
src/com/mes/controller/LaserControllerDual.java

@@ -74,9 +74,8 @@ public class LaserControllerDual {
                 log.info("A面检测到设备启动,开始采集参数");
                 MesClient.pxstatus1.setText("A面运行中");
 
-                // 写#1590=0(禁止启动)
-                device.writeMesEnable(0);
-                log.info("写入#1590=0(禁止启动)");
+                // A面启动不清零#1590,保持允许信号给B面使用
+                log.info("A面启动,保持#1590=1供B面使用");
 
             } else if(tjFlaga == 2) {
                 // 运行中,检测是否完成(不看 working,因为完成瞬间 working 会变 0)
@@ -99,10 +98,11 @@ public class LaserControllerDual {
                         log.error("A面结果上传MES失败");
                         MesClient.pxstatus1.setText("A面上传失败");
                     } else {
-                        log.info("A面结果上传成功,复位状态");
+                        log.info("A面结果上传成功,复位状态(不清零#1590,供B面使用)");
                         resetStatusA();
                         MesClient.pxstatus1.setText("A面提交成功");
                     }
+                    // A面完成不清零#1590,让B面可以直接启动
                 }
             }
 
@@ -113,26 +113,22 @@ public class LaserControllerDual {
 
     /**
      * B面状态检测(参考OP60的getStatusB)
-     * 完成判定只看 #1594==1(持续信号),不要求 working==1
-     * 因为加工完成瞬间 #1592 会变 0、#1594 变 1,两者互斥
+     * B面不需要扫码,利用A面的允许信号直接启动
+     * B面完成后才清零#1590,为下一轮A面扫码准备
      */
     private void checkStatusB() {
         try {
             // 读取B面加工中状态 #1592
             int working = device.readWorking("B");
 
-            if(tjFlagb == 1 && working == 1) {
-                // 状态切换:1(等待启动)→ 2(运行中
+            if(tjFlagb == 0 && working == 1) {
+                // B面直接启动(无需扫码,tjFlagb从0直接到2
                 tjFlagb = 2;
-                log.info("B面检测到设备启动,开始采集参数");
+                log.info("B面检测到设备启动(无需扫码),开始采集参数");
                 MesClient.pxstatus2.setText("B面运行中");
 
-                // 写#1590=0(禁止启动)
-                device.writeMesEnable(0);
-                log.info("写入#1590=0(禁止启动)");
-
             } else if(tjFlagb == 2) {
-                // 运行中,检测是否完成(不看 working,因为完成瞬间 working 会变 0)
+                // 运行中,检测是否完成
                 int finish = device.readFinish("B");
                 if(finish == 1) {
                     // 状态切换:2(运行中)→ 3(完成)
@@ -145,17 +141,11 @@ public class LaserControllerDual {
                         saveParams("B");
                     }
 
-                    // 上传结果到MES
-                    boolean sendret = sendQuality(curSnb, "OK", "B");
-                    if(!sendret) {
-                        tjStatusb = 1;
-                        log.error("B面结果上传MES失败");
-                        MesClient.pxstatus2.setText("B面上传失败");
-                    } else {
-                        log.info("B面结果上传成功,复位状态");
-                        resetStatusB();
-                        MesClient.pxstatus2.setText("B面提交成功");
-                    }
+                    // B面不上传MES,直接复位
+                    log.info("B面完成,清零#1590禁止启动,等待下一轮A面扫码");
+                    device.writeMesEnable(0);
+                    resetStatusB();
+                    MesClient.pxstatus2.setText("B面完成");
                 }
             }
 
@@ -420,20 +410,13 @@ public class LaserControllerDual {
 
     /**
      * MES质检通过回调(B面)
+     * B面不需要扫码,此方法不再使用
      */
     public void onMesQualityPassB() {
         try {
             mesQualityFlagB = true;
-
-            // 写#1590=1(允许启动)
-            boolean ret = device.writeMesEnable(1);
-            if(ret) {
-                log.info("B面MES质检通过,写入#1590=1(允许启动)");
-                MesClient.pxstatus2.setText("B面等待启动");
-            } else {
-                log.error("B面写入#1590=1失败");
-                MesClient.pxstatus2.setText("B面写信号失败");
-            }
+            log.info("B面质检回调(B面不需要扫码,忽略)");
+            // B面不写#1590,利用A面的允许信号
 
         } catch (Exception e) {
             log.error("B面MES质检回调异常", e);

+ 89 - 43
src/com/mes/ui/MesClient.java

@@ -313,7 +313,21 @@ public class MesClient extends JFrame {
         // 老版本的隐藏按钮/返修标签 op090 不一定创建,防御式访问
         if (finish_ok_bt != null) finish_ok_bt.setEnabled(false);
         if (finish_ng_bt != null) finish_ng_bt.setEnabled(false);
-        if (product_sn != null) product_sn.setText("");
+
+        // 根据当前转台位置恢复提示(参考 OP50)
+        if (product_sn != null) {
+            String side = (laserDevice != null) ? laserDevice.readSideAtLoad() : "";
+            if (side.equals("A")) {
+                product_sn.setText(mes_gw + " - 请扫码");
+                product_sn.setBackground(new Color(144, 238, 144)); // 浅绿色
+                product_sn.setForeground(Color.BLACK);
+            } else {
+                product_sn.setText("请等待转到A面扫码");
+                product_sn.setBackground(Color.LIGHT_GRAY);
+                product_sn.setForeground(Color.DARK_GRAY);
+            }
+        }
+
         if (fxlabel != null) fxlabel.setVisible(false);
         if (status_menu != null) status_menu.setText("请扫工件码");
 
@@ -333,8 +347,12 @@ public class MesClient extends JFrame {
     }
 
     public static void resetScanB() {
-        // B面复位逻辑
-        if(product_sn2 != null) product_sn2.setText("");
+        // B面复位逻辑(B面不需要扫码,保持提示)
+        if(product_sn2 != null) {
+            product_sn2.setText("B面无需扫码");
+            product_sn2.setBackground(Color.WHITE);
+            product_sn2.setForeground(Color.GRAY);
+        }
         if(param21 != null) param21.setText("");
         if(param22 != null) param22.setText("");
         if(param23 != null) param23.setText("");
@@ -405,20 +423,26 @@ public class MesClient extends JFrame {
     public static void updateCurSideLabel(String side) {
         if (scanCurSideLabel == null) return;
         if ("A".equals(side)) {
-            scanCurSideLabel.setText("当前:A面");
-            scanCurSideLabel.setForeground(new Color(0, 128, 64));
+            scanCurSideLabel.setText("当前:A面(可扫码)");
+            scanCurSideLabel.setOpaque(true);
+            scanCurSideLabel.setBackground(new Color(144, 238, 144)); // 浅绿色
+            scanCurSideLabel.setForeground(Color.BLACK);
         } else if ("B".equals(side)) {
-            scanCurSideLabel.setText("当前:B面");
-            scanCurSideLabel.setForeground(new Color(0, 128, 64));
+            scanCurSideLabel.setText("当前:B面(等待A面)");
+            scanCurSideLabel.setOpaque(true);
+            scanCurSideLabel.setBackground(Color.LIGHT_GRAY);
+            scanCurSideLabel.setForeground(Color.DARK_GRAY);
         } else {
-            scanCurSideLabel.setText("当前:转台未到位");
-            scanCurSideLabel.setForeground(new Color(200, 100, 0));
+            scanCurSideLabel.setText("转台未到位");
+            scanCurSideLabel.setOpaque(true);
+            scanCurSideLabel.setBackground(Color.LIGHT_GRAY);
+            scanCurSideLabel.setForeground(Color.DARK_GRAY);
         }
     }
 
     /**
-     * 扫码处理(参考 OP60,走顶部 scanTextField
-     * A/B 面由 #1581 转台位置自动判断(=1 → 上料面 B,=2 → 上料面 A,=0 → 未到位)
+     * 扫码处理(参考 OP50,只管控A面扫码,B面直接启动
+     * 只有转台在A面位置时才允许扫码
      */
     public static void scanBarcode() {
         // 从扫码框取值并清空
@@ -433,29 +457,20 @@ public class MesClient extends JFrame {
             return;
         }
 
-        // 判 A/B 面:读 #1581
+        // 检查转台位置,只有在A面才允许扫码
         String side = (laserDevice != null) ? laserDevice.readSideAtLoad() : "";
-        if (side.isEmpty()) {
-            MesClient.setMenuStatus("转台未到位,暂不能扫码", -1);
+        if (!side.equals("A")) {
+            MesClient.setMenuStatus("请等待转到A面", -1);
             return;
         }
 
         // 已合格工件未处理完 → 拒收
-        if (side.equals("A")) {
-            if (!product_sn.getText().isEmpty()
-                    && com.mes.controller.LaserControllerDual.mesQualityFlagA) {
-                MesClient.setMenuStatus("A面已有合格工件码,勿重复扫码", -1);
-                return;
-            }
-            product_sn.setText(sn);
-        } else {
-            if (!product_sn2.getText().isEmpty()
-                    && com.mes.controller.LaserControllerDual.mesQualityFlagB) {
-                MesClient.setMenuStatus("B面已有合格工件码,勿重复扫码", -1);
-                return;
-            }
-            product_sn2.setText(sn);
+        if (!product_sn.getText().isEmpty()
+                && com.mes.controller.LaserControllerDual.mesQualityFlagA) {
+            MesClient.setMenuStatus("A面已有合格工件码,勿重复扫码", -1);
+            return;
         }
+        product_sn.setText(sn);
 
         MesClient.setMenuStatus("扫码成功", 0);
         mesClientFrame.repaint();
@@ -470,19 +485,15 @@ public class MesClient extends JFrame {
         String barcode36 = getBarcode(sn);
 
         // 查询工件质量(MES 质检)
-        Boolean sendret = DataUtil.checkQuality(nettyClient, barcode36, user20, side);
+        Boolean sendret = DataUtil.checkQuality(nettyClient, barcode36, user20, "A");
         if (!sendret) {
             MesClient.setMenuStatus("消息发送失败,请重试", -1);
             return;
         }
 
-        // 扫码处理交给控制器(推进状态机 tjFlag → 1)
+        // 扫码处理交给控制器(推进A面状态机 tjFlaga → 1)
         if (laserController != null) {
-            if (side.equals("A")) {
-                laserController.onScanCodeA(sn, user20);
-            } else {
-                laserController.onScanCodeB(sn, user20);
-            }
+            laserController.onScanCodeA(sn, user20);
         }
     }
 
@@ -655,7 +666,9 @@ public class MesClient extends JFrame {
 
         // ========== 顶部扫码区(参考 OP60)==========
         scanCurSideLabel = new JLabel("当前:转台未到位");
-        scanCurSideLabel.setForeground(new Color(128, 128, 128));
+        scanCurSideLabel.setOpaque(true); // 允许显示背景色
+        scanCurSideLabel.setBackground(Color.LIGHT_GRAY);
+        scanCurSideLabel.setForeground(Color.DARK_GRAY);
         scanCurSideLabel.setHorizontalAlignment(SwingConstants.CENTER);
         scanCurSideLabel.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
         scanCurSideLabel.setBounds(26, 15, 240, 50);
@@ -682,7 +695,9 @@ public class MesClient extends JFrame {
         indexPanelA.add(pxstatus1);
 
         product_sn = new JTextField();
-        product_sn.setText("");
+        product_sn.setText("请等待转到A面扫码");
+        product_sn.setBackground(Color.LIGHT_GRAY);
+        product_sn.setForeground(Color.DARK_GRAY);
         product_sn.setHorizontalAlignment(SwingConstants.CENTER);
         product_sn.setEditable(false);
         product_sn.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 22));
@@ -757,7 +772,9 @@ public class MesClient extends JFrame {
         indexPanelA.add(pxstatus2);
 
         product_sn2 = new JTextField();
-        product_sn2.setText("");
+        product_sn2.setText("B面无需扫码");
+        product_sn2.setBackground(Color.WHITE);
+        product_sn2.setForeground(Color.GRAY);
         product_sn2.setHorizontalAlignment(SwingConstants.CENTER);
         product_sn2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 22));
         product_sn2.setEditable(false);
@@ -1194,7 +1211,7 @@ public class MesClient extends JFrame {
                 }
             }, 1000, 1000);
 
-            // 2.5 转台位置检测(1秒)— 更新顶部标签 + 保持扫码框焦点 + 面切换禁用(对齐 OP60)
+            // 2.5 转台位置检测(1秒)— 更新顶部标签 + 保持扫码框焦点 + 面切换时的UI提示
             Timer sideDetectTimer = new Timer();
             sideDetectTimer.schedule(new TimerTask() {
                 public void run() {
@@ -1207,13 +1224,42 @@ public class MesClient extends JFrame {
                         String side = laserDevice.readSideAtLoad();
                         SwingUtilities.invokeLater(() -> updateCurSideLabel(side));
 
-                        // 面切换瞬间 → 写 #1590=0 禁用启动(对齐 OP60 的 changeEnable(false))
-                        // 防止转台旋转过程中机床误触发下一次加工循环
+                        // 面切换时更新工件码输入框的提示信息(参考 OP50)
                         if (!side.equals(lastSideAtLoad)) {
                             String prev = lastSideAtLoad;
                             lastSideAtLoad = side;
-                            laserDevice.writeMesEnable(0);
-                            log.info("转台面切换 [{} → {}],写#1590=0 禁用启动",
+
+                            // 转到B面时,如果A面已完成,写#1590=1允许B面启动
+                            if (side.equals("B") && com.mes.controller.LaserControllerDual.tjFlaga == 0) {
+                                // A面已完成(tjFlaga=0表示已复位),允许B面启动
+                                laserDevice.writeMesEnable(1);
+                                log.info("转台切到B面,A面已完成,写#1590=1允许B面启动");
+                            }
+
+                            // 更新A面工件码输入框的状态提示
+                            SwingUtilities.invokeLater(() -> {
+                                if (side.equals("A")) {
+                                    // 转到A面:可扫码(绿色背景)
+                                    if (product_sn.getText().isEmpty()
+                                            || product_sn.getText().contains("请扫码")
+                                            || product_sn.getText().contains("请等待")) {
+                                        product_sn.setText(mes_gw + " - 请扫码");
+                                        product_sn.setBackground(new Color(144, 238, 144)); // 浅绿色
+                                        product_sn.setForeground(Color.BLACK);
+                                    }
+                                } else {
+                                    // 转到B面:等待提示(灰色背景)
+                                    if (product_sn.getText().isEmpty()
+                                            || product_sn.getText().contains("请扫码")
+                                            || product_sn.getText().contains("请等待")) {
+                                        product_sn.setText("请等待转到A面扫码");
+                                        product_sn.setBackground(Color.LIGHT_GRAY);
+                                        product_sn.setForeground(Color.DARK_GRAY);
+                                    }
+                                }
+                            });
+
+                            log.info("转台面切换 [{} → {}]",
                                     prev.isEmpty() ? "未到位" : prev,
                                     side.isEmpty() ? "未到位" : side);
                         }