Przeglądaj źródła

增加交互逻辑

jingbo 2 dni temu
rodzic
commit
b0be3ae8e4

BIN
lib/iot-communication-1.4.4.jar


BIN
lib/iot-communication-1.5.3.jar


+ 5 - 1
src/com/mes/ui/MultiStationClient.java

@@ -247,7 +247,11 @@ public class MultiStationClient extends JFrame {
                     config.getGw(),
                     config.getGwDes(),
                     config.getLineSn(),
-                    config.getServerIp()
+                    config.getServerIp(),
+                    config.getAllowStart(),
+                    config.getAllowDown(),
+                    config.getStartMethod(),
+                    config.getStopMethod()
                 );
                 stationPanels.add(panel);
                 mainPanel.add(panel);

+ 24 - 8
src/com/mes/ui/WorkStationPanel.java

@@ -22,6 +22,11 @@ public class WorkStationPanel extends JPanel {
     private String gwDes;
     private String lineSn;
     private String serverIp;
+
+    private String allowStart;
+    private String allowDown;
+    private String startMethod;
+    private String stopMethod;
     
     public int workStatus = 0;
     public int plcStatus = 0;
@@ -44,11 +49,15 @@ public class WorkStationPanel extends JPanel {
 
     private boolean iconREDFlag = true;
 
-    public WorkStationPanel(String gw, String gwDes, String lineSn, String serverIp) {
+    public WorkStationPanel(String gw, String gwDes, String lineSn, String serverIp, String allowStart, String allowDown, String startMethod, String stopMethod) {
         this.gw = gw;
         this.gwDes = gwDes;
         this.lineSn = lineSn;
         this.serverIp = serverIp;
+        this.allowStart = allowStart;
+        this.allowDown = allowDown;
+        this.startMethod = startMethod;
+        this.stopMethod = stopMethod;
         initUI();
         startHeartBeatTimer();
         startGetCurSn();
@@ -370,34 +379,34 @@ public class WorkStationPanel extends JPanel {
                         }
                     } else if (plcStatus == 1) {
                         // 发送允许启动信号
-                        Boolean ret = PLCUtils.writeStartMethod();
+                        Boolean ret = PLCUtils.writeStartMethod(allowStart);
                         if (ret) {
                             plcStatus = 2;
                         }
                     } else if (plcStatus == 2) {
                         // 等待开始加工信号
-                        Boolean ret = PLCUtils.readStartMethod();
+                        Boolean ret = PLCUtils.readStartMethod(startMethod);
                         if (ret){
-                            boolean ret2 = PLCUtils.writeStopMethod();
+                            // 将允许启动置空
+                            boolean ret2 = PLCUtils.writeStopMethod(allowStart);
                             if (ret2){
                                 plcStatus = 3;
                             }
                         }
                     } else if (plcStatus ==3) {
                         // 等待加工结束信号
-                        Boolean ret = PLCUtils.readStopMethod();
+                        Boolean ret = PLCUtils.readStopMethod(stopMethod);
                         if (ret){
                             // 发送结果
                             String sn = productSnField.getText().trim();
                             JSONObject retObj = DataUtil.sendQuality( sn,"OK", currentUser, gw, lineSn, serverIp);
                             if (retObj != null && "true".equalsIgnoreCase(retObj.getString("result"))) {
                                 // 发送允许下料
-                                PLCUtils.writeDownMethod();
-                                resetState();
+                                PLCUtils.writeDownMethod(allowDown);
                                 statusLabel.setForeground(Color.GREEN);
                                 statusLabel.setText("结果提交成功,请扫下一件");
                                 finishNgButton.setEnabled(false);
-
+                                plcStatus = 4;
                             } else {
                                 statusLabel.setForeground(Color.RED);
                                 String msg = (retObj != null && retObj.containsKey("message")) ? retObj.getString("message") : "提交失败";
@@ -407,6 +416,13 @@ public class WorkStationPanel extends JPanel {
                             // 获取参数
                             PLCUtils.getParameter();
                         }
+                    }else if (plcStatus == 4){
+                        // 等待加工结束为空
+                        Boolean ret = PLCUtils.readStopMethod(stopMethod);
+                        if (!ret){
+                            PLCUtils.writeDownStopMethod(allowDown);
+                            resetState();
+                        }
                     }
 
                     return;

+ 23 - 14
src/com/mes/util/PLCUtils.java

@@ -1,41 +1,50 @@
 package com.mes.util;
 
+import com.github.xingshuangs.iot.protocol.melsec.service.McPLC;
+import com.github.xingshuangs.iot.protocol.melsec.enums.EMcSeries;
+
+
 public class PLCUtils {
 
+    private static McPLC plc = new McPLC(EMcSeries.QnA, "192.168.0.35", 8000);
+
     // 写入允许启动方法
-    public static boolean writeStartMethod() {
-        // TODO
+    public static boolean writeStartMethod(String allowStart) {
         // 对plc写入ture
+        plc.writeBoolean(allowStart, true);
         return true;
     }
 
     // 将允许启动置空
-    public static boolean writeStopMethod() {
-        // TODO
+    public static boolean writeStopMethod(String allowStart) {
+
+        plc.writeBoolean(allowStart, false);
         return true;
     }
 
     // 读取PLC开始加工信号
-    public static boolean readStartMethod() {
-        // TODO
-        return true;
+    public static boolean readStartMethod(String startMethod) {
+
+        return plc.readBoolean(startMethod);
     }
 
     // 读取PLC结束加工信号
-    public static boolean readStopMethod() {
-        // TODO
-        return true;
+    public static boolean readStopMethod(String stopMethod) {
+
+        return plc.readBoolean(stopMethod);
     }
 
     // 给出允许下料信号
-    public static boolean writeDownMethod() {
-        // TODO
+    public static boolean writeDownMethod(String allowDown) {
+
+        plc.writeBoolean(allowDown, true);
         return true;
     }
 
     // 允许下料置空
-    public static boolean writeDownStopMethod() {
-        // TODO
+    public static boolean writeDownStopMethod(String allowDown) {
+
+        plc.writeBoolean(allowDown, false);
         return true;
     }
 

+ 78 - 1
src/com/mes/util/StationConfig.java

@@ -14,6 +14,16 @@ public class StationConfig {
     private String lineSn;
     private String serverIp;
 
+    // 允许启动
+    private String allowStart;
+    // 允许下料
+    private String allowDown;
+    // 开始加工
+    private String startMethod;
+    // 加工结束
+    private String stopMethod;
+    // 故障
+
     public StationConfig(String gw, String gwDes, String lineSn, String serverIp) {
         this.gw = gw;
         this.gwDes = gwDes;
@@ -21,22 +31,82 @@ public class StationConfig {
         this.serverIp = serverIp;
     }
 
+    public StationConfig(String gw, String gwDes, String lineSn, String serverIp, String allowStart, String allowDown,
+            String startMethod, String stopMethod) {
+        this.gw = gw;
+        this.gwDes = gwDes;
+        this.lineSn = lineSn;
+        this.serverIp = serverIp;
+        this.allowStart = allowStart;
+        this.allowDown = allowDown;
+        this.startMethod = startMethod;
+        this.stopMethod = stopMethod;
+    }
+
     public String getGw() {
         return gw;
     }
 
+    public void setGw(String gw) {
+        this.gw = gw;
+    }
+
     public String getGwDes() {
         return gwDes;
     }
 
+    public void setGwDes(String gwDes) {
+        this.gwDes = gwDes;
+    }
+
     public String getLineSn() {
         return lineSn;
     }
 
+    public void setLineSn(String lineSn) {
+        this.lineSn = lineSn;
+    }
+
     public String getServerIp() {
         return serverIp;
     }
 
+    public void setServerIp(String serverIp) {
+        this.serverIp = serverIp;
+    }
+
+    public String getAllowStart() {
+        return allowStart;
+    }
+
+    public void setAllowStart(String allowStart) {
+        this.allowStart = allowStart;
+    }
+
+    public String getAllowDown() {
+        return allowDown;
+    }
+
+    public void setAllowDown(String allowDown) {
+        this.allowDown = allowDown;
+    }
+
+    public String getStartMethod() {
+        return startMethod;
+    }
+
+    public void setStartMethod(String startMethod) {
+        this.startMethod = startMethod;
+    }
+
+    public String getStopMethod() {
+        return stopMethod;
+    }
+
+    public void setStopMethod(String stopMethod) {
+        this.stopMethod = stopMethod;
+    }
+
     public static List<StationConfig> loadAllStations() throws IOException {
         List<StationConfig> stations = new ArrayList<>();
         Properties props = new Properties();
@@ -53,10 +123,17 @@ public class StationConfig {
                 for (String gw : stationList.split(",")) {
                     gw = gw.trim();
                     String gwDes = props.getProperty("mes.station." + gw + ".name", gw);
-                    stations.add(new StationConfig(gw, gwDes, lineSn, serverIp));
+                    String allowStart = props.getProperty("mes.station." + gw + ".allowStart", "");
+                    String allowDown = props.getProperty("mes.station." + gw + ".allowDown", "");
+                    String startMethod = props.getProperty("mes.station." + gw + ".startMethod", "");
+                    String stopMethod = props.getProperty("mes.station." + gw + ".stopMethod", "");
+                    stations.add(new StationConfig(gw, gwDes, lineSn, serverIp, allowStart, allowDown, startMethod, stopMethod));
                 }
             }
         }
         return stations;
     }
+
+
+
 }

+ 25 - 0
src/resources/config/config.properties

@@ -8,11 +8,36 @@ mes.stations=OP050A,OP060A,OP070A,OP080A,OP090A,OP160A
 
 # 各工位名称配置
 mes.station.OP050A.name=左右吊耳组件弧焊
+mes.station.OP050A.allowStart=M6661
+mes.station.OP050A.allowDown=M6662
+mes.station.OP050A.startMethod=M6663
+mes.station.OP050A.stopMethod=M6664
+
 mes.station.OP060A.name=左右吊耳组件点焊
+mes.station.OP060A.allowStart=M6641
+mes.station.OP060A.allowDown=M6642
+mes.station.OP060A.startMethod=M6643
+mes.station.OP060A.stopMethod=M6644
+
 mes.station.OP070A.name=电池壳分总成1点焊
+mes.station.OP070A.allowStart=M6621
+mes.station.OP070A.allowDown=M6622
+mes.station.OP070A.startMethod=M6623
+mes.station.OP070A.stopMethod=M6624
+
 mes.station.OP080A.name=电池壳分总成1点焊补焊
+mes.station.OP080A.allowStart=M6601
+mes.station.OP080A.allowDown=M6602
+mes.station.OP080A.startMethod=M6603
+mes.station.OP080A.stopMethod=M6604
+
 mes.station.OP090A.name=电池壳分总成2点焊
+
 mes.station.OP160A.name=电池壳分总成8弧焊
+mes.station.OP090A.allowStart=M6681
+mes.station.OP090A.allowDown=M6682
+mes.station.OP090A.startMethod=M6683
+mes.station.OP090A.stopMethod=M6684
 
 # 单工位配置(保留原配置以兼容旧代码)
 mes.gw=OP050A