소스 검색

页面优化-工件码优化显示以及工件码点击

张田野 1 일 전
부모
커밋
d199e3e988
2개의 변경된 파일76개의 추가작업 그리고 39개의 파일을 삭제
  1. 46 32
      src/com/mes/component/MesClientComponent.java
  2. 30 7
      src/com/mes/ui/MesClient.java

+ 46 - 32
src/com/mes/component/MesClientComponent.java

@@ -46,6 +46,10 @@ public class MesClientComponent extends JPanel {
     public JLabel sllabel1;
     /** 下料完成反馈(可手动点击翻转) */
     public JLabel sllabel2;
+    /** 上料完成信号(仅展示,不可点击) */
+    public JLabel sllabelLoad;
+    /** 下料完成信号(仅展示,不可点击) */
+    public JLabel sllabelUnload;
     /** 工位状态:正常/故障 */
     public JLabel stationStatusLabel;
     /** 加工结果展示 */
@@ -102,7 +106,8 @@ public class MesClientComponent extends JPanel {
         y += hStatus + gap;
 
         productSn = new JTextField("");
-        productSn.setHorizontalAlignment(SwingConstants.CENTER);
+        // 过长时右对齐,尾部顶满格,开头被裁切,便于看清后缀
+        productSn.setHorizontalAlignment(SwingConstants.RIGHT);
         productSn.setForeground(Color.BLACK);
         int snFont = Math.max(14, Math.min(22, w / 16));
         productSn.setFont(new Font("微软雅黑", Font.PLAIN, snFont));
@@ -110,26 +115,28 @@ public class MesClientComponent extends JPanel {
         productSn.setBounds(margin, y, w - 2 * margin, hSn);
         productSn.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
         productSn.setToolTipText("点击显示二维码");
-        productSn.setFocusable(false);
+        productSn.setColumns(10);
         productSn.addMouseListener(new MouseAdapter() {
             @Override
             public void mousePressed(MouseEvent e) {
-                MesClient.createQRCode(productSn.getText(), oprnoClass.getOprno());
+                // 与 op300 一致:可点;工控触摸屏上 pressed 比 clicked 更稳
+                String sn = productSn.getText() == null ? "" : productSn.getText().trim();
+                if (!sn.isEmpty()) {
+                    MesClient.createQRCode(sn, oprnoClass.getOprno());
+                }
             }
         });
         this.add(productSn);
         y += hSn + gap;
 
-        stationStatusLabel = new JLabel("工位状态: --");
-        stationStatusLabel.setHorizontalAlignment(SwingConstants.CENTER);
-        stationStatusLabel.setFont(new Font("微软雅黑", Font.PLAIN, Math.max(12, w / 18)));
-        stationStatusLabel.setBounds(0, y, w / 2, hLab);
-        this.add(stationStatusLabel);
+        // 工位状态(station_status)暂不显示:现场点位未就绪时会一直报故障
+        stationStatusLabel = new JLabel("");
+        stationStatusLabel.setVisible(false);
 
         resultLabel = new JLabel("结果: --");
         resultLabel.setHorizontalAlignment(SwingConstants.CENTER);
         resultLabel.setFont(new Font("微软雅黑", Font.PLAIN, Math.max(12, w / 18)));
-        resultLabel.setBounds(w / 2, y, w - w / 2, hLab);
+        resultLabel.setBounds(margin, y, w - 2 * margin, hLab);
         this.add(resultLabel);
         y += hLab + gap;
 
@@ -204,6 +211,26 @@ public class MesClientComponent extends JPanel {
             }
         });
         this.add(sllabel2);
+        y += hFeedback + gap;
+
+        // 上料/下料信号:只读展示 PLC→MES 完成位,不可点击
+        sllabelLoad = new JLabel("上料信号");
+        sllabelLoad.setHorizontalAlignment(SwingConstants.CENTER);
+        sllabelLoad.setVerticalAlignment(SwingConstants.CENTER);
+        sllabelLoad.setIcon(dot(false));
+        sllabelLoad.setForeground(Color.BLACK);
+        sllabelLoad.setToolTipText("上料完成信号(只读)");
+        sllabelLoad.setBounds(0, y, w / 2, hFeedback);
+        this.add(sllabelLoad);
+
+        sllabelUnload = new JLabel("下料信号");
+        sllabelUnload.setHorizontalAlignment(SwingConstants.CENTER);
+        sllabelUnload.setVerticalAlignment(SwingConstants.CENTER);
+        sllabelUnload.setIcon(dot(false));
+        sllabelUnload.setForeground(Color.BLACK);
+        sllabelUnload.setToolTipText("下料完成信号(只读)");
+        sllabelUnload.setBounds(w / 2, y, w - w / 2, hFeedback);
+        this.add(sllabelUnload);
 
         this.startOprnoTimer();
     }
@@ -261,8 +288,12 @@ public class MesClientComponent extends JPanel {
         try {
             boolean lf = MesClient.s7PLC.readBoolean(oprnoClass.getLoad_feedback());
             boolean uf = MesClient.s7PLC.readBoolean(oprnoClass.getUnload_feedback());
+            boolean lc = MesClient.s7PLC.readBoolean(oprnoClass.getLoad_complete());
+            boolean uc = MesClient.s7PLC.readBoolean(oprnoClass.getUnload_complete());
             sllabel1.setIcon(dot(lf));
             sllabel2.setIcon(dot(uf));
+            sllabelLoad.setIcon(dot(lc));
+            sllabelUnload.setIcon(dot(uc));
         } catch (Exception ignored) {
         }
     }
@@ -313,28 +344,6 @@ public class MesClientComponent extends JPanel {
     }
 
     private void pollOnce() {
-        // 工位状态显示(故障时同步到上方状态栏)
-        try {
-            boolean stationOk = MesClient.s7PLC.readBoolean(oprnoClass.getStation_status());
-            final boolean ok = stationOk;
-            SwingUtilities.invokeLater(() -> {
-                if (ok) {
-                    stationStatusLabel.setText("工位状态: 正常");
-                    stationStatusLabel.setForeground(new Color(0, 128, 0));
-                    if (lastStationOk != null && !lastStationOk) {
-                        restoreStatusAfterFault();
-                    }
-                } else {
-                    stationStatusLabel.setText("工位状态: 故障");
-                    stationStatusLabel.setForeground(Color.RED);
-                    setMenuStatus("工位故障", -1);
-                }
-                lastStationOk = ok;
-            });
-        } catch (Exception e) {
-            // PLC 未就绪时忽略
-        }
-
         refreshFeedbackIcons();
 
         boolean loadComplete = false;
@@ -362,7 +371,10 @@ public class MesClientComponent extends JPanel {
         lastUnloadComplete = unloadComplete;
 
         if (work_status == 0) {
-            if (loadComplete && !loadEdgeHandled) {
+            // 面板尚无码时按电平触发,避免 loadEdgeHandled 卡住后 PLC 已有上料完成+码却一直“等待上料完成”
+            String curSn = productSn.getText();
+            boolean noSnYet = curSn == null || curSn.trim().isEmpty();
+            if (loadComplete && (!loadEdgeHandled || noSnYet)) {
                 String sn = "";
                 try {
                     sn = MesClient.s7PLC.readString(oprnoClass.getProduct_sn());
@@ -504,6 +516,8 @@ public class MesClientComponent extends JPanel {
         resultLabel.setText("结果: --");
         resultLabel.setForeground(Color.BLACK);
         work_status = 0;
+        loadEdgeHandled = false;
+        unloadEdgeHandled = false;
         resultHandled = false;
         aqdwSent = false;
         setMenuStatus("等待上料完成", 0);

+ 30 - 7
src/com/mes/ui/MesClient.java

@@ -285,7 +285,7 @@ public class MesClient extends JFrame {
 
         r1SnField = new JTextField("");
         r1SnField.setEditable(false);
-        r1SnField.setFocusable(false);
+        r1SnField.setHorizontalAlignment(SwingConstants.RIGHT);
         r1SnField.setFont(new Font("微软雅黑", Font.PLAIN, 18));
         r1SnField.setBounds(140, 24, snW, 36);
         r1SnField.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
@@ -293,7 +293,10 @@ public class MesClient extends JFrame {
         r1SnField.addMouseListener(new MouseAdapter() {
             @Override
             public void mousePressed(MouseEvent e) {
-                createQRCode(r1SnField.getText(), "R1");
+                String sn = r1SnField.getText() == null ? "" : r1SnField.getText().trim();
+                if (!sn.isEmpty()) {
+                    createQRCode(sn, "R1");
+                }
             }
         });
         r1Panel.add(r1SnField);
@@ -410,10 +413,20 @@ public class MesClient extends JFrame {
                 try {
                     boolean req = s7PLC.readBoolean(r1RequestRead);
                     if (lastR1Request && !req) {
-                        // 请求下降沿:仅复位软件标记,不清 PLC 反馈(由 PLC 自行复位)
+                        // 请求下降沿:复位软件标记,并清零读码 OK/NG 反馈
                         r1RequestHandled = false;
                         r1CheckPending = false;
                         r1PendingSn = "";
+                        try {
+                            if (r1FeedbackOk != null && !r1FeedbackOk.isEmpty()) {
+                                s7PLC.writeBoolean(r1FeedbackOk, false);
+                            }
+                            if (r1FeedbackNg != null && !r1FeedbackNg.isEmpty()) {
+                                s7PLC.writeBoolean(r1FeedbackNg, false);
+                            }
+                        } catch (Exception ex) {
+                            log.debug("R1 复位读码反馈失败: " + ex.getMessage());
+                        }
                         setR1Status("等待 R1 请求读码", 0);
                     }
                     lastR1Request = req;
@@ -649,27 +662,37 @@ public class MesClient extends JFrame {
         }
     }
 
-    /** 点击工件码弹窗显示二维码 */
+    /** 点击工件码弹窗显示二维码(对齐 mesclient-op300-ng) */
     public static void createQRCode(String s, String title) {
         log.info("二维码:" + s);
-        if (s == null || s.trim().isEmpty()) {
+        if (s == null || s.isEmpty()) {
+            return;
+        }
+        s = s.replace("\u0000", "").trim();
+        if (s.isEmpty()) {
             return;
         }
-        s = s.trim();
         try {
             BitMatrix bitMatrix = new QRCodeWriter().encode(s, BarcodeFormat.QR_CODE, 200, 200);
             BufferedImage qrImage = MatrixToImageWriter.toBufferedImage(bitMatrix);
             JDialog qrDialog = new JDialog(mesClientFrame, title == null ? "" : title, Dialog.ModalityType.APPLICATION_MODAL);
             qrDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
-            qrDialog.setSize(250, 250);
+            qrDialog.setSize(320, 300);
             qrDialog.setLocationRelativeTo(mesClientFrame);
             qrDialog.setResizable(false);
+            JLabel snLabel = new JLabel(s);
+            snLabel.setHorizontalAlignment(SwingConstants.CENTER);
+            snLabel.setFont(new Font("微软雅黑", Font.PLAIN, 14));
+            snLabel.setBorder(BorderFactory.createEmptyBorder(8, 8, 4, 8));
             JLabel qrLabel = new JLabel(new ImageIcon(qrImage));
+            qrLabel.setHorizontalAlignment(SwingConstants.CENTER);
+            qrDialog.getContentPane().add(snLabel, BorderLayout.NORTH);
             qrDialog.getContentPane().add(qrLabel, BorderLayout.CENTER);
             qrDialog.setVisible(true);
             log.info("已生成二维码");
         } catch (Exception e) {
             log.error("生成二维码失败", e);
+            JOptionPane.showMessageDialog(mesClientFrame, "生成二维码失败: " + e.getMessage(), "提示窗口", JOptionPane.WARNING_MESSAGE);
         }
     }