jingbo преди 1 седмица
родител
ревизия
f2857e7b65
променени са 3 файла, в които са добавени 200 реда и са изтрити 30 реда
  1. 162 10
      src/com/mes/ui/MesClient.java
  2. 22 20
      src/com/mes/ui/MesRevice.java
  3. 16 0
      src/com/mes/util/Test.java

+ 162 - 10
src/com/mes/ui/MesClient.java

@@ -104,9 +104,9 @@ public class MesClient extends JFrame {
     public static boolean timer_flag = false; // 开始计时标志 false=非工作开始计时 true=工件开始计时
     public static long timer_nums = 0; // 秒数
 
-    public static S7PLC s7PLC = new S7PLC(EPlcType.S1200,"10.88.10.180");
+    public static S7PLC s7PLC = new S7PLC(EPlcType.S1200,"10.88.10.80");
+
 
-    public static Integer index = 0;
 
 
     public static void main(String[] args) {
@@ -133,6 +133,8 @@ public class MesClient extends JFrame {
 
                         getMaterailData();
 
+                        startPlcTimer();
+
                     }catch (Exception e){
                         e.printStackTrace();
                     }
@@ -260,12 +262,16 @@ public class MesClient extends JFrame {
     public static void resetScanA() {
         work_status = 0;
         check_quality_result = false;
-        MesClient.finish_ok_bt.setEnabled(false);
-        MesClient.finish_ng_bt.setEnabled(false);
+//        MesClient.finish_ok_bt.setEnabled(false);
+//        MesClient.finish_ng_bt.setEnabled(false);
         product_sn.setText("");
+        product_sn_LB.setText("");
         MesClient.fxlabel.setVisible(false);
-
-        MesClient.f_scan_data_bt_1.setEnabled(true);
+        MesClient.index = 0;
+        // 信号重置
+        MesClient.s7PLC.writeBoolean("DB503.0.2", false);
+        MesClient.s7PLC.writeBoolean("DB503.0.5", false);
+//        MesClient.f_scan_data_bt_1.setEnabled(true);
         MesClient.status_menu.setText("请扫工件码");
 
         updateMaterailData();
@@ -378,7 +384,7 @@ public class MesClient extends JFrame {
 
         // 判断工件码是不是空的
         if(product_sn.getText().equalsIgnoreCase("")) {
-            MesClient.setMenuStatus("请扫工件码",-1);
+            MesClient.setMenuStatus("等待机器人上料",-1);
             return;
         }
         // 绑定冷板
@@ -391,6 +397,7 @@ public class MesClient extends JFrame {
                 setMenuStatus("绑定失败!", 1);
                 return;
             }
+            product_sn_LB.setText(product_sn.getText());
         }
     }
 
@@ -436,7 +443,7 @@ public class MesClient extends JFrame {
             }
         });
 
-        JMenu settingMenu = new JMenu("设置");
+        JMenu settingMenu = new JMenu("交互设置");
         //settingMenu.setVisible(false);
         settingMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/menu_setting.png")));
         settingMenu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
@@ -465,7 +472,65 @@ public class MesClient extends JFrame {
                 resetScanA();
             }
         });
-        settingMenu.add(resetTcpMenu_1);
+//        settingMenu.add(resetTcpMenu_1);
+
+        //允许上料
+        JMenuItem allow_up_material = new JMenuItem("允许上料");
+        allow_up_material.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
+        allow_up_material.setFont(new Font("微软雅黑", Font.PLAIN, 20));
+        allow_up_material.addMouseListener(new MouseAdapter() {
+            @Override
+            public void mousePressed(MouseEvent e) {
+                super.mouseClicked(e);
+                // 弹框输入密码,如果输入的为”503833“即可允许上料
+                String input = JOptionPane.showInputDialog(null, "请输入密码");
+                if (!input.equalsIgnoreCase("503833")) {
+                    JOptionPane.showMessageDialog(mesClientFrame, "密码错误", "提示窗口", JOptionPane.INFORMATION_MESSAGE);
+                    return;
+                }
+                // 允许上料
+                MesClient.s7PLC.writeBoolean("DB503.0.2", true);
+            }
+        });
+        settingMenu.add(allow_up_material);
+        // 允许下料
+        JMenuItem allow_down_material = new JMenuItem("允许下料");
+        allow_down_material.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
+        allow_down_material.setFont(new Font("微软雅黑", Font.PLAIN, 20));
+        allow_down_material.addMouseListener(new MouseAdapter() {
+            @Override
+            public void mousePressed(MouseEvent e) {
+                super.mouseClicked(e);
+                // 弹框输入密码,如果输入的为”503833“即可允许下料
+                String input = JOptionPane.showInputDialog(null, "请输入密码");
+                if (!input.equalsIgnoreCase("503833")) {
+                    JOptionPane.showMessageDialog(mesClientFrame, "密码错误", "提示窗口", JOptionPane.INFORMATION_MESSAGE);
+                    return;
+                }
+                MesClient.s7PLC.writeBoolean("DB503.0.5", true);
+            }
+        });
+        settingMenu.add(allow_down_material);
+        // 重置信号
+        JMenuItem reset_signal = new JMenuItem("重置信号");
+        reset_signal.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
+        reset_signal.setFont(new Font("微软雅黑", Font.PLAIN, 20));
+        reset_signal.addMouseListener(new MouseAdapter() {
+            @Override
+            public void mousePressed(MouseEvent e) {
+                super.mouseClicked(e);
+                // 弹框输入密码,如果输入的为”503833“即可允许下料
+                String input = JOptionPane.showInputDialog(null, "请输入密码");
+                if (!input.equalsIgnoreCase("503833")) {
+                    JOptionPane.showMessageDialog(mesClientFrame, "密码错误", "提示窗口", JOptionPane.INFORMATION_MESSAGE);
+                    return;
+                }
+                MesClient.s7PLC.writeBoolean("DB503.0.2", false);
+                MesClient.s7PLC.writeBoolean("DB503.0.5", false);
+            }
+        });
+        settingMenu.add(reset_signal);
+
 
         contentPane = new JPanel();
         contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
@@ -597,7 +662,7 @@ public class MesClient extends JFrame {
         f_scan_data_bt_2.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
                 scan_type = 2;
-                scanBarcode();
+                scanBarcode2();
             }
         });
         f_scan_data_bt_2.setIcon(new ImageIcon(MesClient.class.getResource("/bg/scan_barcode.png")));
@@ -891,4 +956,91 @@ public class MesClient extends JFrame {
         });
     }
 
+
+    // plc交互定时任务
+    public static java.util.Timer plcTimer;
+
+    // 程序逻辑流程:0:等待扫码信号
+    public static Integer index = 0;
+    public static void startPlcTimer(){
+        if (plcTimer != null){
+            plcTimer.cancel();
+            plcTimer = null;
+        }
+        plcTimer = new java.util.Timer();
+        plcTimer.schedule(new TimerTask() {
+            @Override
+            public void run() {
+                if (index == 0){
+                    String sn ="";
+                    if (MesClient.s7PLC.readBoolean("DB503.0.0") || MesClient.s7PLC.readBoolean("DB503.0.1")){
+                        if (MesClient.s7PLC.readBoolean("DB503.0.0")){
+                            sn = MesClient.s7PLC.readString("DB503.270.0");
+                            // 赋值给输入框
+                            product_sn.setText(sn);
+                        }else if (MesClient.s7PLC.readBoolean("DB503.0.1")){
+                             sn = MesClient.s7PLC.readString("DB503.336.0");
+                            // 赋值给输入框
+                            product_sn.setText(sn);
+                        }
+                        if (sn == null || sn.trim().isEmpty() || "".equals(sn)){
+                            setMenuStatus("机器臂抓手读码为空", -1);
+                            return;
+                        }
+                        MesClient.product_sn.setText( sn);
+                        index = 1;
+                    }
+                }else if (index == 1){
+                    // 取到二维码后发送质量检查
+                    String sn = MesClient.product_sn.getText();
+                    Boolean reg = DataUtil.checkQuality(MesClient.nettyClient, sn, MesClient.user20);
+                    if (!reg){
+                        setMenuStatus("报文发送异常", -1);
+                    }
+                }else if (index == 2){
+                    // 等待上料完成
+                    if (MesClient.s7PLC.readBoolean("DB503.0.3")){
+                        // 将允许上料清空·
+                        MesClient.s7PLC.writeBoolean("DB503.0.2", false);
+                        //发送开始做件
+                        Boolean reg = DataUtil.startWork(MesClient.nettyClient, MesClient.product_sn.getText(), MesClient.user20);
+                        if (!reg){
+                            setMenuStatus("报文发送异常", -1);
+                            return;
+                        }
+                    }
+                }else if (index == 3){
+                    // 等待完成信号
+                    if (MesClient.s7PLC.readBoolean("DB503.0.4")){
+                        // 冷板为空不允许提交
+                        if (product_sn_LB.getText() == null || product_sn_LB.getText().trim().isEmpty()){
+                            setMenuStatus("请先绑定底板", -1);
+                            return;
+                        }
+                        Boolean reg = DataUtil.sendQuality(MesClient.nettyClient, MesClient.product_sn.getText(), "OK",MesClient.user20);
+                        if (!reg){
+                            setMenuStatus("报文发送异常", -1);
+                            return;
+                        }
+                    }
+                } else if (index == 4) {
+//                    将允许上料信号及允许下料信号制空
+                    MesClient.s7PLC.writeBoolean("DB503.0.2", false);
+                    MesClient.s7PLC.writeBoolean("DB503.0.5", false);
+                    // 两个输入框制空
+                    product_sn.setText("");
+                    product_sn_LB.setText("");
+                    work_status = 0;
+                    check_quality_result = false;
+                    updateMaterailData();
+                    shiftUserCheck();
+                    index = 0;
+                }
+
+            }
+        }, 0, 1000);
+    }
+
+
+
 }

+ 22 - 20
src/com/mes/ui/MesRevice.java

@@ -18,21 +18,14 @@ public class MesRevice {
                 MesClient.check_quality_result = true;//质量合格,可以绑定加工
                 MesClient.status_menu.setText("该工件可以加工");
                 MesClient.work_status = 1;
-                MesClient.f_scan_data_bt_1.setEnabled(false);
-                MesClient.finish_ok_bt.setEnabled(true);
-                MesClient.finish_ng_bt.setEnabled(true);
-
-                String oprno = ProtocolParam.getOprno(mes_msg).trim();
-                if(oprno.equals("OP400")){
-                    String lx = ProtocolParam.getLx(mes_msg);
-                    if(lx.equals("FX")){
-                        MesClient.fxlabel.setVisible(true);
-                    }
-                }
-
-//                String qret = "OK";
-//                MesClient.getUser();
-//                DataUtil.sendQuality(MesClient.nettyClient,sn,qret,MesClient.user20);
+
+                // 允许做件
+                MesClient.s7PLC.writeBoolean("DB503.0.2", true);
+                // 发送开始做件报文
+                MesClient.index = 2;
+
+
+
             }else {
                 MesClient.check_quality_result = false;
                 String lmsg = ErrorMsg.getErrorMsg(processMsgRet, ProtocolParam.getLx(mes_msg));
@@ -47,7 +40,9 @@ public class MesRevice {
     public static void startRevice(String processMsgRet,String mes_msg){
         try{
             if(processMsgRet.equalsIgnoreCase("OK")) {
-
+                // 绑定底护板按钮开启
+                MesClient.product_sn_LB.setEnabled(true);
+                MesClient.index = 3;
             }
         }catch (Exception e){
             e.printStackTrace();
@@ -84,11 +79,18 @@ public class MesRevice {
     public static void updateResultRevice(String processMsgRet,String mes_msg){
         try{
             if(processMsgRet.equalsIgnoreCase("OK")) {
-
-                MesClient.resetScanA();
+//
+//                MesClient.resetScanA();
+//                MesClient.setMenuStatus("结果提交成功,请扫下一件",0);
+//                MesClient.scan_type = 1;
+//                MesClient.scanBarcode();
+                // 下料允许
+                MesClient.s7PLC.writeBoolean("DB503.0.5", true);
+                //菜单提示信息
                 MesClient.setMenuStatus("结果提交成功,请扫下一件",0);
-                MesClient.scan_type = 1;
-                MesClient.scanBarcode();
+                MesClient.index = 4;
+
+
 
             }else{
                 MesClient.setMenuStatus("结果提交失败,请重试",-1);

+ 16 - 0
src/com/mes/util/Test.java

@@ -0,0 +1,16 @@
+package com.mes.util;
+
+import com.github.xingshuangs.iot.protocol.s7.enums.EPlcType;
+import com.github.xingshuangs.iot.protocol.s7.service.S7PLC;
+import com.mes.ui.MesClient;
+
+public class Test {
+
+    public static S7PLC s7PLC = new S7PLC(EPlcType.S1200,"10.88.10.180");
+
+    public static void main(String[] args) {
+
+        System.out.println("12345"+ s7PLC.readBoolean("DB503.0.0"));
+
+    }
+}