瀏覽代碼

联动plc版本

jingbo 1 周之前
父節點
當前提交
9cc64d77cf
共有 4 個文件被更改,包括 127 次插入84 次删除
  1. 90 66
      src/com/mes/ui/MesClient.java
  2. 18 5
      src/com/mes/ui/MesRevice.java
  3. 16 10
      src/com/mes/ui/OprnoUtil.java
  4. 3 3
      src/resources/config/config.properties

+ 90 - 66
src/com/mes/ui/MesClient.java

@@ -1,12 +1,14 @@
 package com.mes.ui;
 
 import com.alibaba.fastjson2.JSONObject;
+import com.github.xingshuangs.iot.protocol.modbus.service.ModbusTcp;
 import com.mes.component.MesRadio;
 import com.mes.component.MesWebView;
 import com.mes.netty.NettyClient;
 import com.mes.util.DateLocalUtils;
 import com.mes.util.HttpUtils;
 import com.mes.util.JdbcUtils;
+import com.mes.util.ModbusUtils;
 import javafx.embed.swing.JFXPanel;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -97,8 +99,10 @@ public class MesClient extends JFrame {
     public static MesWebView jfxPanel3 = null;
     public static MesRadio mesRadioHj;
 
-    public static JLabel timer_label; // 倒计时显示
-    public static String time =  "";
+    // 流程步骤
+    public static int index = 0;
+
+    public static ModbusTcp modbusTcp = new ModbusTcp("192.168.1.20");
 
     public static JTable table;
     public static Object[] columnNames = { "物料名称", "绑定批次", "剩余次数", "操作" };
@@ -123,7 +127,8 @@ public class MesClient extends JFrame {
                     welcomeWin.setVisible(true);
 
                     getMaterailData();
-                    startTimeTimer();
+
+                    process();
 
 //                    startUpdateQualityTimer(); // 开启提交结果的定时任务
 
@@ -245,32 +250,6 @@ public class MesClient extends JFrame {
     // 时间显示定时任务
     public static java.util.Timer timeTimer;
 
-    public static void startTimeTimer() {
-        if(timeTimer!=null) {
-            timeTimer.cancel();
-        }
-        timeTimer = new Timer();
-        timeTimer.schedule(new TimerTask() {
-            @Override
-            public void run() {
-                if (!"".equals(time)){
-                   // 获取当前时间
-                    String nowTime = DateLocalUtils.getCurrentTime();
-                    // 当前时间减去完成时间得出超过的分秒
-                    try {
-                        long time = DateLocalUtils.DATA_FORMAT.parse(nowTime).getTime() - DateLocalUtils.DATA_FORMAT.parse(MesClient.time).getTime();
-                        long minutes = time / 1000 / 60;
-                        long seconds = time / 1000 % 60;
-                        String wokeTime = minutes + ":" + seconds;
-                        // 设置时间显示
-                        timer_label.setText(wokeTime);
-                    } catch (ParseException e) {
-                        throw new RuntimeException(e);
-                    }
-                }
-            }
-        }, 100,1000);
-    }
 
     //设置tcp连接状态显示
     public static void setTcpStatus() {
@@ -293,10 +272,9 @@ public class MesClient extends JFrame {
         MesClient.finish_ok_bt.setEnabled(false);
         MesClient.finish_ng_bt.setEnabled(false);
         product_sn.setText("");
-        time = "";
         MesClient.f_scan_data_bt_1.setEnabled(true);
         MesClient.setMenuStatus("请扫工件码",0);
-
+        MesClient.index = 0;
         updateMaterailData();
 //        shiftUserCheck();
     }
@@ -574,7 +552,7 @@ public class MesClient extends JFrame {
         f_scan_data_bt_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/scan_barcode.png")));
         f_scan_data_bt_1.setFont(new Font("微软雅黑", Font.PLAIN, 32));
         f_scan_data_bt_1.setBounds(693, 70, 198, 70);
-        indexPanelA.add(f_scan_data_bt_1);
+//        indexPanelA.add(f_scan_data_bt_1);
 
 
 
@@ -584,33 +562,11 @@ public class MesClient extends JFrame {
             public void actionPerformed(ActionEvent e) {
                 if(work_status == 1 && check_quality_result){
 
-                    String qret = "";
-                    String nowTime = DateLocalUtils.getCurrentTime();
-                    try {
-                        long time = DateLocalUtils.DATA_FORMAT.parse(nowTime).getTime() - DateLocalUtils.DATA_FORMAT.parse(MesClient.time).getTime();
-                        System.out.println("时间差:" + time);
-                        long minutes = time / 1000 / 60;
-                        long seconds = time / 1000 % 60;
-                        String wokeTime = minutes + ":" + seconds;
-                        qret = wokeTime;
-                        System.out.println("时间差:" + wokeTime);
-                        // 判断时间是否在5到7分钟之内
-                        if (time<5*60*1000){
-                            MesClient.setMenuStatus("时长过短",-1);
-                        }
-                        if(time > 7*60*1000){
-                            MesClient.setMenuStatus("已超时",-1);
-                        }
-                    } catch (ParseException ex) {
-                        throw new RuntimeException(ex);
-                    }
-
-
                     String sn = getBarcode(product_sn.getText());
                     getUser();
 
 
-                    Boolean result = DataUtil.sendQualityByTime(sn,qret,user20);
+                    Boolean result = DataUtil.sendQuality(sn,"OK",user20);
                     if(result) {
                         MesClient.resetScanA();
                         MesClient.setMenuStatus("结果提交成功,请扫下一件", 0);
@@ -637,7 +593,7 @@ public class MesClient extends JFrame {
                     String sn = getBarcode(product_sn.getText());
                     getUser();
                     String qret = "NG";
-                    Boolean result = DataUtil.sendQualityByTime(sn,qret,user20);
+                    Boolean result = DataUtil.sendQuality(sn,qret,user20);
                     if(result) {
                         MesClient.resetScanA();
                         MesClient.setMenuStatus("结果提交成功,请扫下一件", 0);
@@ -655,17 +611,9 @@ public class MesClient extends JFrame {
         finish_ng_bt.setEnabled(false);
         indexPanelA.add(finish_ng_bt);
 
-        timer_label = new JLabel("00:00:00");
-        timer_label.setFont(new Font("微软雅黑", Font.PLAIN, 35));
-        timer_label.setHorizontalAlignment(SwingConstants.CENTER);
-        timer_label.setBounds(411, 220, 240, 60);
-        indexPanelA.add(timer_label);
 
-        JLabel lblNewLabel = new JLabel("计时");
-        lblNewLabel.setFont(new Font("微软雅黑", Font.PLAIN, 35));
-        lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
-        lblNewLabel.setBounds(306, 220, 156, 60);
-        indexPanelA.add(lblNewLabel);
+
+
 
 
         tabbedPane.addTab("工作面板", new ImageIcon(MesClient.class.getResource("/bg/a_side.png")), indexScrollPaneA, null);
@@ -846,4 +794,80 @@ public class MesClient extends JFrame {
     }
 
 
+    // 流程
+    public static void process() {
+       new Timer().schedule(new TimerTask() {
+           @Override
+           public void run() {
+                if (MesClient.index == 0){
+                    // 等待允许扫码信号
+                    // 提示栏显示等待扫码
+                    if (ModbusUtils.isGetDate(modbusTcp)){
+                        ModbusUtils.rechargeYjgetDate(modbusTcp);
+                    }
+                    MesClient.setMenuStatus("等待扫码",0);
+                    if (ModbusUtils.isReadable(modbusTcp)){
+                        // 允许扫码,进入下一阶段
+                        String sn = change(modbusTcp.readString(4100,120).toString());
+                        MesClient.product_sn.setText(sn);
+                        MesClient.index = 1;
+                    }
+                }else if (MesClient.index == 1){
+                    // 查询工件质量
+                    Boolean sendret = DataUtil.checkQuality(nettyClient,MesClient.product_sn.getText(),user20);
+                    if(!sendret){
+                        JOptionPane.showMessageDialog(mesClientFrame,"消息发送失败,请重试","提示窗口", JOptionPane.INFORMATION_MESSAGE);
+                        return;
+                    }
+                } else if (MesClient.index == 2) {
+                    // 清楚是否可以做件信号
+                    ModbusUtils.rechargeAllow(modbusTcp);
+                    MesClient.index = 3;
+                }else if (MesClient.index == 3) {
+                    // 提示栏显示等待加工
+                    MesClient.setMenuStatus("加工中",0);
+                    //等待产品是否合格
+                    boolean ok = ModbusUtils.isQualityOk(modbusTcp);
+                    boolean ng = ModbusUtils.isQualityNG(modbusTcp);
+                    //当有一个为ture时
+                    if (ok || ng){
+                        if (ok){
+                            Boolean sendret = DataUtil.sendQuality(MesClient.product_sn.getText(),"OK",user20);
+                            if(!sendret){
+                                JOptionPane.showMessageDialog(mesClientFrame,"消息发送失败,请重试","提示窗口", JOptionPane.INFORMATION_MESSAGE);
+                                return;
+                            }
+                        }else {
+                            Boolean sendret = DataUtil.sendQuality(MesClient.product_sn.getText(),"",user20);
+                            if(!sendret){
+                                JOptionPane.showMessageDialog(mesClientFrame,"消息发送失败,请重试","提示窗口", JOptionPane.INFORMATION_MESSAGE);
+                                return;
+                            }
+                        }
+                    }
+                } else if (MesClient.index == 4) {
+                    boolean ok = ModbusUtils.isQualityOk(modbusTcp);
+                    boolean ng = ModbusUtils.isQualityNG(modbusTcp);
+                    // 当两个都为false时
+                    if (!ok && !ng){
+                        ModbusUtils.rechargeYjgetDate(modbusTcp);
+                        MesClient.index = 0;
+                    }
+                }
+           }
+           // 1秒执行一次循环
+       }, 1000, 1000);
+    }
+
+    //    传入字符串,字符串两个一组,换位置
+    public static String change(String str){
+        StringBuffer sb = new StringBuffer();
+        for(int i = 0; i < str.length(); i += 2){
+            sb.append(str.charAt(i + 1));
+            sb.append(str.charAt(i));
+        }
+        return sb.toString();
+    }
+
+
 }

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

@@ -4,9 +4,11 @@ import com.jacob.util.JacobTTSUtil;
 import com.mes.netty.ProtocolParam;
 import com.mes.component.MyDialog;
 import com.mes.util.ErrorMsg;
+import com.mes.util.ModbusUtils;
 
 import javax.swing.*;
 import java.awt.*;
+import java.util.List;
 
 public class MesRevice {
 
@@ -25,8 +27,8 @@ public class MesRevice {
                     MesClient.getUser();
                     DataUtil.startWork(MesClient.nettyClient,barcode36,MesClient.user20);
                     // 获取完成时间
-                    String time = DataUtil.getFinishTime(barcode36);
-                    MesClient.time = time;
+//                    String time = DataUtil.getFinishTime(barcode36);
+//                    MesClient.time = time;
                 }
 
                 //000020017871-0100101425101000145
@@ -52,6 +54,8 @@ public class MesRevice {
                 String lmsg = ErrorMsg.getErrorMsg(processMsgRet, ProtocolParam.getLx(mes_msg));
 
                 MesClient.setMenuStatus(lmsg,-1);
+                ModbusUtils.writeNotAllow(MesClient.modbusTcp);
+                MesClient.index = -1;
 //                // 语音播报错误信息(同样改为异步)
 //                MesClient.voiceExecutor.submit(() -> {
 //                    try {
@@ -87,13 +91,16 @@ public class MesRevice {
                 MesClient.work_status = 1;
 
                 MesClient.f_scan_data_bt_1.setEnabled(false);
+                ModbusUtils.writeAllow(MesClient.modbusTcp);
+                MesClient.index = 2;
+                //
 
 //                String sn = MesClient.getBarcode(MesClient.product_sn.getText());
 //                MesClient.getUser();
 //                DataUtil.bindUser(MesClient.nettyClient,sn,MesClient.user20);
 
-                MesClient.finish_ok_bt.setEnabled(true);
-                MesClient.finish_ng_bt.setEnabled(true);
+//                MesClient.finish_ok_bt.setEnabled(true);
+//                MesClient.finish_ng_bt.setEnabled(true);
 
                 /*String qret = "OK";
                 Boolean sendret = DataUtil.sendQuality(MesClient.nettyClient,sn,qret,MesClient.user20);
@@ -141,7 +148,13 @@ public class MesRevice {
         try{
             if(processMsgRet.equalsIgnoreCase("OK")) {
 
-                MesClient.resetScanA();
+                // 获取数据
+                List<Boolean> data = ModbusUtils.getData(MesClient.modbusTcp);
+                // 发出读取完成信号
+                ModbusUtils.yjgetDate(MesClient.modbusTcp);
+                System.out.println( data);
+                MesClient.index = 4;
+//                MesClient.resetScanA();
 //                MesClient.status_menu.setText("结果提交成功,请扫下一件");
                 MesClient.setMenuStatus("结果提交成功,请扫下一件",0);
                 MesClient.scan_type = 1;

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

@@ -6,18 +6,24 @@ import java.util.Map;
 
 public class OprnoUtil {
     public static String[] xtoprnos = new String[]{
-            "OP040","OP050","OP060","OP070","OP080","OP090","OP100","OP110",
-            "OP120","OP130","OP140","OP150","OP160","OP170","OP180","OP190",
-            "OP200","OP210","OP220","OP230","OP240","OP250","OP260","OP270",
-            "OP280","OP290","OP300","OP310","OP315","OP320","OP330","OP340","OP350",
-            "OP360","OP370","OP380","OP390","OP400","OP410","OP420","OP430"
+            "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"
     };
     public static String[] xtoprnodes = new String[]{
-            "镭雕二维码","小总成焊接(边梁、后梁)","框架焊接","人工补焊","框架矫形","焊道检验","CNC总成反面(1序)","总成反面清洁",
-            "框架找漏","冷板安装+拉铆","清理溢胶","水冷板FSW","CNC总成反面(2序)","CNC总成正面加工","总成正面清洁","框架终检",
-            "恒温静置","正面安装钢丝螺套","反面安装钢丝螺套","反面拉铆","半成品气密","涂液冷板加强件结构胶","涂密封胶 安装加强件","清胶",
-            "胶水固化","底护板预装+水嘴安装","底护板装配","成品气密","液冷板气密","反面贴EPDM保温棉","贴PI膜/限位条","正面涂胶+拉铆",
-            "安装复合横梁","正面贴EPDM保温棉","绝缘耐压测试","在线检测(错漏)","在线检测(尺寸)","终检","GP12","包装"
+            "镭雕二维码", "总成装配", "总成焊接", "螺栓复拧", "框架正面补焊",
+            "框架反面补焊", "焊缝铣削", "焊道检查", "框架气密检测", "箱体反面CNC",
+            "箱体正面CNC", "箱体正面上盖CNC", "框架总成清洁+去毛刺", "封堵片焊接", "反面液冷板拉铆", "水冷板激光焊","液冷板FSW",
+            "FSW匙孔补焊+封堵片焊接","封堵片焊道检查", "FSW焊道打磨", "框架干冰清洁", "框架反面装配", "框架正面装配",
+            "模组/冷板涂密封胶", "箱体封堵", "恒温静置", "半成品气密检测", "安装底护板",
+            "底护板螺栓复拧", "总成气密检测", "冷板气密检测", "安装快换螺栓", "总成检具检验",
+            "总成清洁", "粘贴TC带01/02/保温泡棉片/PET膜", "粘贴PC绝缘片/MPP泡棉/绝缘条", "粘贴外部保温泡棉/安装上盖密封圈", "总成CCD检测",
+            "终检", "GP12", "下线拍照", "包装"
     };
     public static String[] lboprnos = new String[]{
             "OP040","OP050","OP060","OP070","OP080","OP090","OP100","OP110",

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

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