Browse Source

first commit

张田野 2 tuần trước cách đây
mục cha
commit
01be93a636

+ 159 - 5
src/com/mes/ui/MesClient.java

@@ -108,6 +108,15 @@ public class MesClient extends JFrame {
     public static Object[] columnNames = { "物料名称", "绑定批次", "剩余次数", "操作" };
     public static Object[] columnNames = { "物料名称", "绑定批次", "剩余次数", "操作" };
     public static Object[][] rowData = null;
     public static Object[][] rowData = null;
 
 
+    public static JLabel feedinglabel; // 允许MES读码 M190
+    public static JLabel feedingmeslabel; // MES允许检测 M293
+    public static JLabel runlabel; // 检测完成 M192/M193
+    public static JLabel blankingmeslabel; // MES读取结果反馈 M295
+    public static JLabel heartBeatlabel; // PLC心跳 M194
+    public static ImageIcon imageGreen;
+    public static ImageIcon imageGray;
+    public static Timer plcHeartBeatTimer; // 单独刷新 M194,避开与 PLC 1s 同频
+
     public static void main(String[] args) {
     public static void main(String[] args) {
 
 
         EventQueue.invokeLater(new Runnable() {
         EventQueue.invokeLater(new Runnable() {
@@ -129,6 +138,7 @@ public class MesClient extends JFrame {
                     getMaterailData();
                     getMaterailData();
 
 
                     process();
                     process();
+                    startPlcHeartBeatTimer();
 
 
 //                    startUpdateQualityTimer(); // 开启提交结果的定时任务
 //                    startUpdateQualityTimer(); // 开启提交结果的定时任务
 
 
@@ -611,10 +621,90 @@ public class MesClient extends JFrame {
         finish_ng_bt.setEnabled(false);
         finish_ng_bt.setEnabled(false);
         indexPanelA.add(finish_ng_bt);
         indexPanelA.add(finish_ng_bt);
 
 
+        imageGreen = new ImageIcon(MesClient.class.getResource("/bg/green_dot.png"));
+        imageGreen.setImage(imageGreen.getImage().getScaledInstance(40, 40, Image.SCALE_SMOOTH));
+        imageGray = new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png"));
+        imageGray.setImage(imageGray.getImage().getScaledInstance(40, 40, Image.SCALE_SMOOTH));
+
+        feedinglabel = new JLabel("允许MES读码");
+        feedinglabel.setHorizontalAlignment(SwingConstants.LEFT);
+        feedinglabel.setIcon(imageGray);
+        feedinglabel.setForeground(Color.BLACK);
+        feedinglabel.setBounds(50, 220, 150, 40);
+        indexPanelA.add(feedinglabel);
+
+        feedingmeslabel = new JLabel("MES允许检测");
+        feedingmeslabel.setHorizontalAlignment(SwingConstants.LEFT);
+        feedingmeslabel.setIcon(imageGray);
+        feedingmeslabel.setForeground(Color.BLACK);
+        feedingmeslabel.setBounds(250, 220, 150, 40);
+        feedingmeslabel.setToolTipText("点击可手动翻转 M293,防止设备卡住");
+        feedingmeslabel.addMouseListener(new MouseAdapter() {
+            public void mouseClicked(MouseEvent e) {
+                try {
+                    boolean ret = ModbusUtils.isAllown(modbusTcp);
+                    int choice = JOptionPane.showConfirmDialog(mesClientFrame,
+                            "确定修改MES允许检测为" + (!ret) + "吗?",
+                            "操作确认", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
+                    if (choice == JOptionPane.YES_OPTION) {
+                        if (!ret) {
+                            ModbusUtils.writeAllow(modbusTcp);
+                        } else {
+                            ModbusUtils.writeAllowDeny(modbusTcp);
+                        }
+                        feedingmeslabel.setIcon((!ret) ? imageGreen : imageGray);
+                    }
+                } catch (Exception ex) {
+                    JOptionPane.showMessageDialog(mesClientFrame, "写入失败:" + ex.getMessage(),
+                            "提示窗口", JOptionPane.ERROR_MESSAGE);
+                }
+            }
+        });
+        indexPanelA.add(feedingmeslabel);
+
+        runlabel = new JLabel("检测完成");
+        runlabel.setHorizontalAlignment(SwingConstants.LEFT);
+        runlabel.setIcon(imageGray);
+        runlabel.setForeground(Color.BLACK);
+        runlabel.setBounds(450, 220, 150, 40);
+        indexPanelA.add(runlabel);
+
+        blankingmeslabel = new JLabel("MES读取结果反馈");
+        blankingmeslabel.setHorizontalAlignment(SwingConstants.LEFT);
+        blankingmeslabel.setIcon(imageGray);
+        blankingmeslabel.setForeground(Color.BLACK);
+        blankingmeslabel.setBounds(650, 220, 180, 40);
+        blankingmeslabel.setToolTipText("点击可手动翻转 M295,防止设备卡住");
+        blankingmeslabel.addMouseListener(new MouseAdapter() {
+            public void mouseClicked(MouseEvent e) {
+                try {
+                    boolean ret = ModbusUtils.isGetDate(modbusTcp);
+                    int choice = JOptionPane.showConfirmDialog(mesClientFrame,
+                            "确定修改MES读取结果反馈为" + (!ret) + "吗?",
+                            "操作确认", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
+                    if (choice == JOptionPane.YES_OPTION) {
+                        if (!ret) {
+                            ModbusUtils.yjgetDate(modbusTcp);
+                        } else {
+                            ModbusUtils.rechargeYjgetDate(modbusTcp);
+                        }
+                        blankingmeslabel.setIcon((!ret) ? imageGreen : imageGray);
+                    }
+                } catch (Exception ex) {
+                    JOptionPane.showMessageDialog(mesClientFrame, "写入失败:" + ex.getMessage(),
+                            "提示窗口", JOptionPane.ERROR_MESSAGE);
+                }
+            }
+        });
+        indexPanelA.add(blankingmeslabel);
 
 
-
-
-
+        heartBeatlabel = new JLabel("心跳");
+        heartBeatlabel.setHorizontalAlignment(SwingConstants.LEFT);
+        heartBeatlabel.setIcon(imageGray);
+        heartBeatlabel.setForeground(Color.BLACK);
+        heartBeatlabel.setBounds(850, 220, 120, 40);
+        heartBeatlabel.setToolTipText("读取 M194,1.3 秒刷新一次显示");
+        indexPanelA.add(heartBeatlabel);
 
 
         tabbedPane.addTab("工作面板", new ImageIcon(MesClient.class.getResource("/bg/a_side.png")), indexScrollPaneA, null);
         tabbedPane.addTab("工作面板", new ImageIcon(MesClient.class.getResource("/bg/a_side.png")), indexScrollPaneA, null);
         tabbedPane.setEnabledAt(0, true);
         tabbedPane.setEnabledAt(0, true);
@@ -794,11 +884,62 @@ public class MesClient extends JFrame {
     }
     }
 
 
 
 
+    // 刷新 PLC 信号指示灯(不含心跳;心跳单独 1.3s 刷新,避免与 PLC 1s 翻转同频)
+    private static void refreshSignalIcons() {
+        try {
+            final boolean retFeeding = ModbusUtils.isReadable(modbusTcp);
+            final boolean retFeedingAllow = ModbusUtils.isAllown(modbusTcp);
+            final boolean ok = ModbusUtils.isQualityOk(modbusTcp);
+            final boolean ng = ModbusUtils.isQualityNG(modbusTcp);
+            final boolean retAllowBlanking = ModbusUtils.isGetDate(modbusTcp);
+            SwingUtilities.invokeLater(() -> {
+                if (feedinglabel != null) {
+                    feedinglabel.setIcon(retFeeding ? imageGreen : imageGray);
+                }
+                if (feedingmeslabel != null) {
+                    feedingmeslabel.setIcon(retFeedingAllow ? imageGreen : imageGray);
+                }
+                if (runlabel != null) {
+                    runlabel.setIcon((ok || ng) ? imageGreen : imageGray);
+                }
+                if (blankingmeslabel != null) {
+                    blankingmeslabel.setIcon(retAllowBlanking ? imageGreen : imageGray);
+                }
+            });
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    // PLC 心跳 M194:1.3 秒读一次,避免与 PLC 1 秒翻转相位锁死
+    public static void startPlcHeartBeatTimer() {
+        if (plcHeartBeatTimer != null) {
+            plcHeartBeatTimer.cancel();
+        }
+        plcHeartBeatTimer = new Timer();
+        plcHeartBeatTimer.schedule(new TimerTask() {
+            @Override
+            public void run() {
+                try {
+                    final boolean heartBeat = ModbusUtils.isHeartBeat(modbusTcp);
+                    SwingUtilities.invokeLater(() -> {
+                        if (heartBeatlabel != null) {
+                            heartBeatlabel.setIcon(heartBeat ? imageGreen : imageGray);
+                        }
+                    });
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+            }
+        }, 1000, 1300);
+    }
+
     // 流程
     // 流程
     public static void process() {
     public static void process() {
        new Timer().schedule(new TimerTask() {
        new Timer().schedule(new TimerTask() {
            @Override
            @Override
            public void run() {
            public void run() {
+                refreshSignalIcons();
                 if (MesClient.index == 0){
                 if (MesClient.index == 0){
                     // 等待允许扫码信号
                     // 等待允许扫码信号
                     // 提示栏显示等待扫码
                     // 提示栏显示等待扫码
@@ -807,18 +948,26 @@ public class MesClient extends JFrame {
                     }
                     }
                     MesClient.setMenuStatus("等待扫码",0);
                     MesClient.setMenuStatus("等待扫码",0);
                     if (ModbusUtils.isReadable(modbusTcp)){
                     if (ModbusUtils.isReadable(modbusTcp)){
-                        // 允许扫码,进入下一阶段
+                        // 允许扫码,进入下一阶段;新码到来时清加工状态,保证会重新开工
                         String sn = change(modbusTcp.readString(4100,120).toString());
                         String sn = change(modbusTcp.readString(4100,120).toString());
                         MesClient.product_sn.setText(sn);
                         MesClient.product_sn.setText(sn);
+                        MesClient.work_status = 0;
+                        MesClient.check_quality_result = false;
+                        MesClient.finish_ok_bt.setEnabled(false);
+                        MesClient.finish_ng_bt.setEnabled(false);
                         MesClient.index = 1;
                         MesClient.index = 1;
                     }
                     }
                 }else if (MesClient.index == 1){
                 }else if (MesClient.index == 1){
-                    // 查询工件质量
+                    // 查询工件质量(只发一次,进入11等待回复)
+                    getUser();
                     Boolean sendret = DataUtil.checkQuality(nettyClient,MesClient.product_sn.getText(),user20);
                     Boolean sendret = DataUtil.checkQuality(nettyClient,MesClient.product_sn.getText(),user20);
                     if(!sendret){
                     if(!sendret){
                         JOptionPane.showMessageDialog(mesClientFrame,"消息发送失败,请重试","提示窗口", JOptionPane.INFORMATION_MESSAGE);
                         JOptionPane.showMessageDialog(mesClientFrame,"消息发送失败,请重试","提示窗口", JOptionPane.INFORMATION_MESSAGE);
                         return;
                         return;
                     }
                     }
+                    MesClient.index = 11;
+                }else if (MesClient.index == 11){
+                    // 等待AQDW/MKSW回复,由MesRevice推进到index=2或-1
                 } else if (MesClient.index == 2) {
                 } else if (MesClient.index == 2) {
                     // 清楚是否可以做件信号
                     // 清楚是否可以做件信号
                     ModbusUtils.rechargeAllow(modbusTcp);
                     ModbusUtils.rechargeAllow(modbusTcp);
@@ -831,6 +980,7 @@ public class MesClient extends JFrame {
                     boolean ng = ModbusUtils.isQualityNG(modbusTcp);
                     boolean ng = ModbusUtils.isQualityNG(modbusTcp);
                     //当有一个为ture时
                     //当有一个为ture时
                     if (ok || ng){
                     if (ok || ng){
+                        getUser();
                         if (ok){
                         if (ok){
                             Boolean sendret = DataUtil.sendQuality(MesClient.product_sn.getText(),"OK",user20);
                             Boolean sendret = DataUtil.sendQuality(MesClient.product_sn.getText(),"OK",user20);
                             if(!sendret){
                             if(!sendret){
@@ -844,7 +994,11 @@ public class MesClient extends JFrame {
                                 return;
                                 return;
                             }
                             }
                         }
                         }
+                        // 已发送MQDW,等待回复,避免重复提交
+                        MesClient.index = 5;
                     }
                     }
+                }else if (MesClient.index == 5){
+                    // 等待MQDW回复,由MesRevice.updateResultRevice推进到index=4
                 } else if (MesClient.index == 4) {
                 } else if (MesClient.index == 4) {
                     boolean ok = ModbusUtils.isQualityOk(modbusTcp);
                     boolean ok = ModbusUtils.isQualityOk(modbusTcp);
                     boolean ng = ModbusUtils.isQualityNG(modbusTcp);
                     boolean ng = ModbusUtils.isQualityNG(modbusTcp);

+ 15 - 18
src/com/mes/ui/MesRevice.java

@@ -67,18 +67,9 @@ public class MesRevice {
 //                MesClient.status_menu.setText(lmsg);
 //                MesClient.status_menu.setText(lmsg);
 //                new MyDialog(MesClient.mesClientFrame,"提示",lmsg);
 //                new MyDialog(MesClient.mesClientFrame,"提示",lmsg);
             }
             }
-            if(MesClient.check_quality_result){
-                if(MesClient.work_status == 0){
-                    MesClient.finish_ok_bt.setEnabled(false);
-                    MesClient.finish_ng_bt.setEnabled(false);
-                }else{
-                    MesClient.finish_ok_bt.setEnabled(true);
-                    MesClient.finish_ng_bt.setEnabled(true);
-                }
-            }else{
-                MesClient.finish_ok_bt.setEnabled(false);
-                MesClient.finish_ng_bt.setEnabled(false);
-            }
+            // 本工位由PLC结果自动提交,质量查询后不点亮OK/NG,避免误点/打断自动流程
+            MesClient.finish_ok_bt.setEnabled(false);
+            MesClient.finish_ng_bt.setEnabled(false);
         }catch (Exception e){
         }catch (Exception e){
             e.printStackTrace();
             e.printStackTrace();
         }
         }
@@ -153,18 +144,24 @@ public class MesRevice {
                 // 发出读取完成信号
                 // 发出读取完成信号
                 ModbusUtils.yjgetDate(MesClient.modbusTcp);
                 ModbusUtils.yjgetDate(MesClient.modbusTcp);
                 System.out.println( data);
                 System.out.println( data);
+
+                // 提交成功后复位加工状态,供下一件重新开工;index保持4等待PLC清除OK/NG信号
+                MesClient.work_status = 0;
+                MesClient.check_quality_result = false;
+                MesClient.finish_ok_bt.setEnabled(false);
+                MesClient.finish_ng_bt.setEnabled(false);
+                MesClient.f_scan_data_bt_1.setEnabled(true);
+
                 MesClient.index = 4;
                 MesClient.index = 4;
-//                MesClient.resetScanA();
-//                MesClient.status_menu.setText("结果提交成功,请扫下一件");
                 MesClient.setMenuStatus("结果提交成功,请扫下一件",0);
                 MesClient.setMenuStatus("结果提交成功,请扫下一件",0);
                 MesClient.scan_type = 1;
                 MesClient.scan_type = 1;
-//                MesClient.scanBarcode();
 
 
             }else{
             }else{
                 MesClient.setMenuStatus("结果提交失败,请重试",-1);
                 MesClient.setMenuStatus("结果提交失败,请重试",-1);
-//                MesClient.status_menu.setText("结果提交失败,请重试");
-//                JOptionPane.showMessageDialog(MesClient.mesClientFrame,"结果提交失败,请重试","提示窗口", JOptionPane.INFORMATION_MESSAGE);
-//                return;
+                // 回到等待PLC结果阶段,允许再次自动提交
+                if(MesClient.index == 5){
+                    MesClient.index = 3;
+                }
             }
             }
         }catch (Exception e){
         }catch (Exception e){
             e.printStackTrace();
             e.printStackTrace();

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

@@ -6,24 +6,10 @@ import java.util.Map;
 
 
 public class OprnoUtil {
 public class OprnoUtil {
     public static String[] xtoprnos = new String[]{
     public static String[] xtoprnos = new String[]{
-            "OP040", "OP100", "OP110", "OP120", "OP130",
-            "OP140", "OP150", "OP160", "OP170", "OP180",
-            "OP190", "OP200", "OP210", "OP220", "OP265", "OP270", "OP280",
-            "OP290", "OP295", "OP300", "OP310", "OP320", "OP330",
-            "OP340", "OP350", "OP360", "OP370", "OP380",
-            "OP390", "OP400", "OP410", "OP420", "OP430",
-            "OP440", "OP450", "OP460", "OP470", "OP480",
-            "OP490", "OP500", "OP510", "OP520"
+            "OP390"
     };
     };
     public static String[] xtoprnodes = new String[]{
     public static String[] xtoprnodes = new String[]{
-            "镭雕二维码", "总成装配", "总成焊接", "螺栓复拧", "框架正面补焊",
-            "框架反面补焊", "焊缝铣削", "焊道检查", "框架气密检测", "箱体反面CNC",
-            "箱体正面CNC", "箱体正面上盖CNC", "框架总成清洁+去毛刺", "封堵片焊接", "反面液冷板拉铆", "水冷板激光焊","液冷板FSW",
-            "FSW匙孔补焊+封堵片焊接","封堵片焊道检查", "FSW焊道打磨", "框架干冰清洁", "框架反面装配", "框架正面装配",
-            "模组/冷板涂密封胶", "箱体封堵", "恒温静置", "半成品气密检测", "安装底护板",
-            "底护板螺栓复拧", "总成气密检测", "冷板气密检测", "安装快换螺栓", "总成检具检验",
-            "总成清洁", "粘贴TC带01/02/保温泡棉片/PET膜", "粘贴PC绝缘片/MPP泡棉/绝缘条", "粘贴外部保温泡棉/安装上盖密封圈", "总成CCD检测",
-            "终检", "GP12", "下线拍照", "包装"
+            "总成检具检验"
     };
     };
     public static String[] lboprnos = new String[]{
     public static String[] lboprnos = new String[]{
             "OP040","OP050","OP060","OP070","OP080","OP090","OP100","OP110",
             "OP040","OP050","OP060","OP070","OP080","OP090","OP100","OP110",

+ 20 - 0
src/com/mes/util/ModbusUtils.java

@@ -13,12 +13,32 @@ public class ModbusUtils {
         return allow.get(0);
         return allow.get(0);
     }
     }
 
 
+    // PLC 心跳,M194 约一秒翻转一次
+    public static boolean isHeartBeat(ModbusTcp modbusTcp) {
+        List<Boolean> beat = modbusTcp.readCoil(194, 1);
+        System.out.println("===========PLC心跳:" + beat.get(0) + "===========");
+        return beat.get(0);
+    }
+
+    // 读取 MES 允许检测信号
+    public static boolean isAllown(ModbusTcp modbusTcp) {
+        List<Boolean> allow = modbusTcp.readCoil(293,1);
+        System.out.println("===========MES允许检测:"+allow.get(0)+"===========");
+        return allow.get(0);
+    }
+
     // 写入允许做件
     // 写入允许做件
     public static void writeAllow(ModbusTcp modbusTcp) {
     public static void writeAllow(ModbusTcp modbusTcp) {
         System.out.println("===========写入允许做件===========");
         System.out.println("===========写入允许做件===========");
         modbusTcp.writeCoil(293,true);
         modbusTcp.writeCoil(293,true);
     }
     }
 
 
+    // 清除允许做件
+    public static void writeAllowDeny(ModbusTcp modbusTcp) {
+        System.out.println("===========清除允许做件===========");
+        modbusTcp.writeCoil(293,false);
+    }
+
     // 写入不允许做件
     // 写入不允许做件
     public static void writeNotAllow(ModbusTcp modbusTcp) {
     public static void writeNotAllow(ModbusTcp modbusTcp) {
         System.out.println("===========写入不允许做件===========");
         System.out.println("===========写入不允许做件===========");

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

@@ -1,6 +1,6 @@
-mes.gw=OP430A
-mes.server_ip=127.0.0.1
-#mes.server_ip=192.168.18.99
+mes.gw=OP390A
+#mes.server_ip=127.0.0.1
+mes.server_ip=192.168.24.99
 mes.tcp_port=3000
 mes.tcp_port=3000
 mes.heart_beat_cycle=60
 mes.heart_beat_cycle=60
 mes.line_sn=XT
 mes.line_sn=XT