hou vor 2 Stunden
Ursprung
Commit
327091a600

+ 0 - 1
src/com/mes/ui/LoginFarme.java

@@ -180,7 +180,6 @@ public class LoginFarme extends JFrame {
                     //启动timer心跳包
                     MesClient.startHeartBeatTimer();
                     MesClient.startIweldLoginTimer();
-                    MesClient.startIweldRobotRunInfoTimer();
 
                     //1操作工人,2管理员
                     //登录成功

+ 1 - 17
src/com/mes/ui/MesClient.java

@@ -272,7 +272,7 @@ public class MesClient extends JFrame {
         cjTimer2.schedule(new TimerTask() {
             public void run() {
                 try{
-                    PlcUtil.getParamDyDl(s7PLC);
+                    IweldCloudUtil.collectWeldingParams();
                 }catch (Exception e){
                     e.printStackTrace();
                 }
@@ -325,7 +325,6 @@ public class MesClient extends JFrame {
     public static java.util.Timer heartBeatTimer;
     public static java.util.Timer heartBeatIconTimer;
     public static java.util.Timer iweldLoginTimer;
-    public static java.util.Timer iweldRobotRunInfoTimer;
     public static boolean iconREDFlag = true;
     public static JTextField param1;
     public static JTextField param2;
@@ -403,18 +402,6 @@ public class MesClient extends JFrame {
         }, 0, twoHoursMs);
     }
 
-    public static void startIweldRobotRunInfoTimer() {
-        if(iweldRobotRunInfoTimer != null) {
-            iweldRobotRunInfoTimer.cancel();
-        }
-        iweldRobotRunInfoTimer = new Timer();
-        iweldRobotRunInfoTimer.schedule(new TimerTask() {
-            public void run() {
-                IweldCloudUtil.fetchRobotRunInfo();
-            }
-        }, 1000, 1000);
-    }
-
     //鐠佸墽鐤唗cp鏉╃偞甯撮悩鑸碉拷浣规▔缁�锟�
     public static void setTcpStatus() {
         if(tcp_connect_flag) {
@@ -569,9 +556,6 @@ public class MesClient extends JFrame {
         if(iweldLoginTimer!=null) {
             iweldLoginTimer.cancel();
         }
-        if(iweldRobotRunInfoTimer!=null) {
-            iweldRobotRunInfoTimer.cancel();
-        }
         tcp_connect_flag = false;
         connect_request_flag = false;
     }

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

@@ -18,22 +18,16 @@ public class MesRevice {
                 String oprno = ProtocolParam.getOprno(mes_msg).trim();
                 String sn = ProtocolParam.getSn(mes_msg).trim();
                 System.out.println(":"+oprno);
-                if(oprno.equals("OP110A")){
-                    String barcode36 = MesClient.getBarcode(sn);//处理36为码
-                    MesClient.getUser();
-                    DataUtil.startWork(MesClient.nettyClient,barcode36,MesClient.user20,"A");
-                }else if(oprno.equals("OP110B")){
-                    String barcode36 = MesClient.getBarcode(sn);//处理36为码
-                    MesClient.getUser();
-                    DataUtil.startWork(MesClient.nettyClient,barcode36,MesClient.user20,"B");
-                }else if(oprno.equals("OP110C")){
-                    String barcode36 = MesClient.getBarcode(sn);//处理36为码
-                    MesClient.getUser();
-                    DataUtil.startWork(MesClient.nettyClient,barcode36,MesClient.user20,"A");
-                }else if(oprno.equals("OP110D")){
-                    String barcode36 = MesClient.getBarcode(sn);//处理36为码
+                String op = null;
+                if(oprno.equals(MesClient.mes_gw+"A") || oprno.equals(MesClient.mes_gw+"C")){
+                    op = "A";
+                }else if(oprno.equals(MesClient.mes_gw+"B") || oprno.equals(MesClient.mes_gw+"D")){
+                    op = "B";
+                }
+                if(op != null){
+                    String barcode36 = MesClient.getBarcode(sn);
                     MesClient.getUser();
-                    DataUtil.startWork(MesClient.nettyClient,barcode36,MesClient.user20,"B");
+                    DataUtil.startWork(MesClient.nettyClient,barcode36,MesClient.user20,op);
                 }
 
             }else {

+ 0 - 56
src/com/mes/ui/PlcUtil.java

@@ -14,62 +14,6 @@ import java.util.Arrays;
 
 public class PlcUtil {
 
-    public static void getParamDyDl(S7PLC s7PLC){
-        Boolean starta = s7PLC.readBoolean("DB7.0.2"); //A面运行中
-        Boolean startb = s7PLC.readBoolean("DB7.1.2"); //B面运行中
-
-        String oprno = MesClient.mes_gw+"A";
-        if(startb){
-            oprno = MesClient.mes_gw+"B";
-        }
-        if(MesClient.mes_gwflag.equals("B")){
-            if(oprno.equals(MesClient.mes_gw+"A")){
-                oprno = MesClient.mes_gw+"C";
-            }else{
-                oprno = MesClient.mes_gw+"D";
-            }
-        }
-
-        if(MesClient.tjFlaga == 2 || MesClient.tjFlagb == 2){ //运行中
-            Float dya = s7PLC.readFloat32("DB1010.2");
-            Float dla = s7PLC.readFloat32("DB1010.8");
-            Float ssa = s7PLC.readFloat32("DB1010.14");
-//            Short cwa = s7PLC.readInt16("DB1010.18");
-//            Short joba = s7PLC.readInt16("DB1010.20");
-
-            MesClient.param1.setText(dya+"");
-            MesClient.param2.setText(dla+"");
-            MesClient.param3.setText(ssa+"");
-
-            Float dyb = s7PLC.readFloat32("DB1010.26");
-            Float dlb = s7PLC.readFloat32("DB1010.34");
-            Float ssb = s7PLC.readFloat32("DB1010.42");
-//            Short cwb = s7PLC.readInt16("DB1010.46");
-//            Short jobb = s7PLC.readInt16("DB1010.48");
-
-            MesClient.param21.setText(dyb+"");
-            MesClient.param22.setText(dlb+"");
-            MesClient.param23.setText(ssb+"");
-
-            String record_time = DateLocalUtils.getCurrentTime();
-            MesClient.hjparams.add(dya+"|"+dla+"|"+ssa+"|"+"|"+"|"+dyb+"|"+dlb+"|"+ssb+"|"+"|"+"|"+record_time);
-
-            if(MesClient.hjparams.size() == 60){
-                try{
-                    if(MesClient.curFlag.equals("A")){
-                        JdbcUtils.insertCmtData(oprno,MesClient.mes_line_sn,MesClient.product_sn.getText(), JSON.toJSONString(MesClient.hjparams));
-                    }else{
-                        JdbcUtils.insertCmtData(oprno,MesClient.mes_line_sn,MesClient.product_sn2.getText(), JSON.toJSONString(MesClient.hjparams));
-                    }
-                    System.out.println("cmt:"+MesClient.curFlag);
-                    MesClient.hjparams = new ArrayList<>();
-                }catch (Exception e){
-                    e.printStackTrace();
-                }
-            }
-        }
-    }
-
     public static void getStatusAOld(S7PLC s7PLC){
         String sna = "";
         if(MesClient.tjFlaga == 1){ // 待运行

+ 142 - 1
src/com/mes/util/IweldCloudUtil.java

@@ -1,12 +1,16 @@
 package com.mes.util;
 
+import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.JSONArray;
 import com.alibaba.fastjson2.JSONObject;
+import com.mes.ui.MesClient;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.io.BufferedReader;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.util.ArrayList;
 import java.util.Properties;
 
 public class IweldCloudUtil {
@@ -15,6 +19,16 @@ public class IweldCloudUtil {
     private static volatile String sessionKey = "";
     private static volatile String robotRunInfo = "";
 
+    public static class WelderParams {
+        public String voltage = "";
+        public String current = "";
+        public String wireSpeed = "";
+
+        public boolean hasData() {
+            return !voltage.isEmpty() || !current.isEmpty() || !wireSpeed.isEmpty();
+        }
+    }
+
     public static String getSessionKey() {
         return sessionKey;
     }
@@ -80,7 +94,6 @@ public class IweldCloudUtil {
             }
 
             robotRunInfo = response;
-            System.out.println("IweldCloud getRobotRunInfo: " + response);
             return true;
         } catch (Exception e) {
             log.error("IweldCloud getRobotRunInfo error", e);
@@ -88,6 +101,134 @@ public class IweldCloudUtil {
         }
     }
 
+    /**
+     * 焊接运行中从 IweldCloud 采集焊机参数,更新界面并写入本地缓存。
+     */
+    public static void collectWeldingParams() {
+        if (MesClient.tjFlaga != 2 && MesClient.tjFlagb != 2) {
+            return;
+        }
+        if (sessionKey == null || sessionKey.isEmpty()) {
+            login();
+        }
+        if (!fetchRobotRunInfo()) {
+            return;
+        }
+
+        WelderParams[] welders = parseWelderParamsFromResponse(robotRunInfo);
+        welders = mergeSecondProdCode(welders);
+        if (welders == null || (!welders[0].hasData() && !welders[1].hasData())) {
+            return;
+        }
+
+        MesClient.param1.setText(welders[0].voltage);
+        MesClient.param2.setText(welders[0].current);
+        MesClient.param3.setText(welders[0].wireSpeed);
+        MesClient.param21.setText(welders[1].voltage);
+        MesClient.param22.setText(welders[1].current);
+        MesClient.param23.setText(welders[1].wireSpeed);
+
+        String recordTime = DateLocalUtils.getCurrentTime();
+        MesClient.hjparams.add(
+                welders[0].voltage + "|" + welders[0].current + "|" + welders[0].wireSpeed + "|" + "" + "|" + "" + "|"
+                        + welders[1].voltage + "|" + welders[1].current + "|" + welders[1].wireSpeed + "|" + "" + "|" + "" + "|"
+                        + recordTime
+        );
+
+        if (MesClient.hjparams.size() == 60) {
+            try {
+                String oprno = buildOprno();
+                if (MesClient.curFlag.equals("A")) {
+                    JdbcUtils.insertCmtData(oprno, MesClient.mes_line_sn, MesClient.product_sn.getText(), JSON.toJSONString(MesClient.hjparams));
+                } else {
+                    JdbcUtils.insertCmtData(oprno, MesClient.mes_line_sn, MesClient.product_sn2.getText(), JSON.toJSONString(MesClient.hjparams));
+                }
+                MesClient.hjparams = new ArrayList<>();
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+    }
+
+    public static WelderParams[] parseWelderParamsFromResponse(String response) {
+        if (response == null || response.isEmpty()) {
+            return null;
+        }
+        try {
+            JSONObject json = JSONObject.parseObject(response);
+            JSONArray dataList = json.getJSONArray("dataList");
+            if (dataList == null || dataList.isEmpty()) {
+                return null;
+            }
+
+            WelderParams[] welders = new WelderParams[2];
+            welders[0] = parseWelderItem(dataList.getJSONObject(0));
+            if (dataList.size() > 1) {
+                welders[1] = parseWelderItem(dataList.getJSONObject(1));
+            } else {
+                welders[1] = new WelderParams();
+            }
+            return welders;
+        } catch (Exception e) {
+            log.error("IweldCloud parse welder params error", e);
+            return null;
+        }
+    }
+
+    private static WelderParams parseWelderItem(JSONObject item) {
+        WelderParams params = new WelderParams();
+        if (item == null) {
+            return params;
+        }
+        params.voltage = readField(item,
+                "weldingVoltage", "voltage", "vol", "v_meas", "actualVoltage", "actualVol", "U", "dy", "voltageValue");
+        params.current = readField(item,
+                "weldingCurrent", "current", "cur", "c_meas", "actualCurrent", "actualCur", "I", "dl", "currentValue", "electricity");
+        params.wireSpeed = readField(item,
+                "wireFeedSpeed", "wireSpeed", "feedingSpeed", "f_meas", "speed", "ss", "feedSpeed", "wireFeed", "feeding");
+        return params;
+    }
+
+    private static String readField(JSONObject item, String... keys) {
+        for (String key : keys) {
+            if (item.containsKey(key) && item.get(key) != null) {
+                return String.valueOf(item.get(key));
+            }
+        }
+        return "";
+    }
+
+    private static WelderParams[] mergeSecondProdCode(WelderParams[] welders) {
+        try {
+            Properties pro = loadConfig();
+            String prodCode2 = pro.getProperty("iweld.prodCode2", "").trim();
+            if (prodCode2.isEmpty()) {
+                return welders;
+            }
+            if (welders == null) {
+                welders = new WelderParams[]{new WelderParams(), new WelderParams()};
+            }
+            String baseUrl = pro.getProperty("iweld.robot.run.info.url",
+                    "https://api.iweldcloud.com/ApiServer/rest/WeldWebService/getRobotRunInfo").trim();
+            String response = HttpUtils.sendGetRequestWithHeader(baseUrl + "?prodCode=" + prodCode2, "app-token", sessionKey);
+            WelderParams[] second = parseWelderParamsFromResponse(response);
+            if (second != null && second[0].hasData()) {
+                welders[1] = second[0];
+            }
+        } catch (Exception e) {
+            log.error("IweldCloud fetch second prodCode error", e);
+        }
+        return welders;
+    }
+
+    private static String buildOprno() {
+        String side = MesClient.curFlag.equals("A") ? "A" : "B";
+        if (MesClient.mes_gwflag.equals("B")) {
+            side = MesClient.curFlag.equals("A") ? "C" : "D";
+        }
+        return MesClient.mes_gw + side;
+    }
+
     private static Properties loadConfig() throws Exception {
         Properties pro = new Properties();
         InputStream is = ClassLoader.getSystemResourceAsStream("config/config.properties");

+ 6 - 4
src/resources/config/config.properties

@@ -1,6 +1,6 @@
-mes.gw=OP050
-#mes.server_ip=127.0.0.1
-mes.server_ip=192.168.16.99
+mes.gw=OP032
+mes.server_ip=127.0.0.1
+#mes.server_ip=192.168.16.99
 mes.tcp_port=3000
 mes.heart_beat_cycle=60
 mes.line_sn=XT
@@ -9,5 +9,7 @@ mes.gwflag=A
 # IweldCloud Login
 iweld.accessKey=19353:BN15MTY2NA==08X
 iweld.login.url=https://api.iweldcloud.com/ApiServer/Login
-iweld.prodCode=D262650085
+iweld.prodCode=D2626S0083
+# 焊机2产品编码,留空则仅使用 dataList 第2条或焊机2显示为空
+iweld.prodCode2=
 iweld.robot.run.info.url=https://api.iweldcloud.com/ApiServer/rest/WeldWebService/getRobotRunInfo