소스 검색

cmt优化

sunxianglong 4 일 전
부모
커밋
b842bea60c
2개의 변경된 파일64개의 추가작업 그리고 18개의 파일을 삭제
  1. 5 4
      src/com/mes/ui/DataUtil.java
  2. 59 14
      src/com/mes/ui/MesClient.java

+ 5 - 4
src/com/mes/ui/DataUtil.java

@@ -138,8 +138,9 @@ public class DataUtil {
 
     /**
      * 上传 CMT 焊接过程数据到 mesProductCmtData 表
+     * wireSpeed/current/voltage 为用 # 拼接的过程曲线字符串
      */
-    public static boolean saveCmtDataHttp(String sn, float wireSpeed, float current, float voltage) {
+    public static boolean saveCmtDataHttp(String sn, String wireSpeed, String current, String voltage) {
         try {
             String enconding = "UTF-8";
             InputStream is = ClassLoader.getSystemResourceAsStream("config/config.properties");
@@ -154,9 +155,9 @@ public class DataUtil {
             data.put("oprno", oprno);
             data.put("lineSn", lineSn);
             data.put("sn", sn == null ? "" : sn.trim());
-            data.put("wireSpeed", String.format("%.2f", wireSpeed));
-            data.put("current", String.format("%.2f", current));
-            data.put("voltage", String.format("%.2f", voltage));
+            data.put("wireSpeed", wireSpeed == null ? "" : wireSpeed);
+            data.put("current", current == null ? "" : current);
+            data.put("voltage", voltage == null ? "" : voltage);
 
             String url = "http://" + mes_server_ip + ":8980/js/a/mes/mesProductCmtData/add?__ajax=json&__sid="
                     + URLEncoder.encode(MesClient.sessionid == null ? "" : MesClient.sessionid, "UTF-8");

+ 59 - 14
src/com/mes/ui/MesClient.java

@@ -100,6 +100,12 @@ public class MesClient extends JFrame {
     public static Timer plcMonitorTimer;
     public static boolean plc_finish_handled = false;
     public static boolean plc_finish_last = false;
+    /** 过程数据按 1 秒采样,用 # 拼接;每满 100 个上传一次,完成时上传剩余 */
+    public static final StringBuilder cmtWireSpeedBuf = new StringBuilder();
+    public static final StringBuilder cmtCurrentBuf = new StringBuilder();
+    public static final StringBuilder cmtVoltageBuf = new StringBuilder();
+    public static int cmtSampleCount = 0;
+    public static final int CMT_UPLOAD_BATCH_SIZE = 100;
 
     public static void main(String[] args) {
         EventQueue.invokeLater(new Runnable() {
@@ -317,6 +323,7 @@ public class MesClient extends JFrame {
         S7Util.setQualityOk(false);
         plc_finish_handled = false;
         plc_finish_last = false;
+        clearCmtDataBuf();
 
         work_status = 0;
         check_quality_result = false;
@@ -438,16 +445,54 @@ public class MesClient extends JFrame {
         finish_ng_bt.setEnabled(false);
         f_scan_data_bt_1.setEnabled(false);
         clearProcessDataUI();
+        clearCmtDataBuf();
 
         S7Util.setQualityOk(true);
         setMenuStatus("质量校验通过,等待设备焊接", 0);
         startPlcMonitor();
     }
 
+    public static void clearCmtDataBuf() {
+        cmtWireSpeedBuf.setLength(0);
+        cmtCurrentBuf.setLength(0);
+        cmtVoltageBuf.setLength(0);
+        cmtSampleCount = 0;
+    }
+
+    private static void appendCmtValue(StringBuilder buf, float value) {
+        if (buf.length() > 0) {
+            buf.append('#');
+        }
+        buf.append(String.format("%.2f", value));
+    }
+
+    /** 上传当前缓冲中的过程数据字符串,成功后清空缓冲 */
+    public static void uploadCmtDataBatch() {
+        final String sn = product_sn.getText().trim();
+        final String wireSpeed = cmtWireSpeedBuf.toString();
+        final String current = cmtCurrentBuf.toString();
+        final String voltage = cmtVoltageBuf.toString();
+        if (sn.isEmpty()) {
+            return;
+        }
+        if (wireSpeed.isEmpty() && current.isEmpty() && voltage.isEmpty()) {
+            return;
+        }
+        clearCmtDataBuf();
+        new Thread(new Runnable() {
+            @Override
+            public void run() {
+                DataUtil.saveCmtDataHttp(sn, wireSpeed, current, voltage);
+            }
+        }).start();
+    }
+
     public static void startPlcMonitor() {
         stopPlcMonitor();
         plc_finish_last = false;
+        clearCmtDataBuf();
         plcMonitorTimer = new Timer();
+        // 每 1 秒采样过程数据
         plcMonitorTimer.schedule(new TimerTask() {
             @Override
             public void run() {
@@ -458,14 +503,15 @@ public class MesClient extends JFrame {
 
                     final boolean finish = S7Util.isFinish();
                     final boolean welding = S7Util.isWelding();
-                    final boolean finishDetected = finish || (finish && !plc_finish_last);
                     plc_finish_last = finish;
 
-                    System.out.println("PLC监控 DB17.0.0完成=" + finish + " DB17.0.1焊接=" + welding);
+                    System.out.println("PLC监控 DB17.0.0完成=" + finish + " DB17.0.1焊接=" + welding
+                            + " 已拼接=" + cmtSampleCount);
 
-                    // 完成信号 DB17.0.0 为 true:停止上传并点亮 OK/NG
-                    if (finishDetected && !plc_finish_handled) {
+                    // 完成信号:停止拼接,上传剩余数据,点亮 OK/NG
+                    if (finish && !plc_finish_handled) {
                         plc_finish_handled = true;
+                        uploadCmtDataBatch();
                         SwingUtilities.invokeLater(new Runnable() {
                             @Override
                             public void run() {
@@ -474,14 +520,18 @@ public class MesClient extends JFrame {
                                 setMenuStatus("设备加工完成,请提交结果", 0);
                             }
                         });
+                        return;
                     }
 
-                    // 未完成且焊接中:读取过程数据并上传
+                    // 未完成且焊接中:读取并按 # 拼接,满 100 个上传一次
                     if (welding && !finish && !plc_finish_handled) {
                         final float wireSpeed = S7Util.readWireSpeed();
                         final float current = S7Util.readCurrent();
                         final float voltage = S7Util.readVoltage();
-                        final String sn = product_sn.getText().trim();
+                        appendCmtValue(cmtWireSpeedBuf, wireSpeed);
+                        appendCmtValue(cmtCurrentBuf, current);
+                        appendCmtValue(cmtVoltageBuf, voltage);
+                        cmtSampleCount++;
                         SwingUtilities.invokeLater(new Runnable() {
                             @Override
                             public void run() {
@@ -489,20 +539,15 @@ public class MesClient extends JFrame {
                                 setMenuStatus("设备焊接中...", 0);
                             }
                         });
-                        if (!sn.isEmpty()) {
-                            new Thread(new Runnable() {
-                                @Override
-                                public void run() {
-                                    DataUtil.saveCmtDataHttp(sn, wireSpeed, current, voltage);
-                                }
-                            }).start();
+                        if (cmtSampleCount >= CMT_UPLOAD_BATCH_SIZE) {
+                            uploadCmtDataBatch();
                         }
                     }
                 } catch (Exception e) {
                     e.printStackTrace();
                 }
             }
-        }, 500, 500);
+        }, 1000, 1000);
     }
 
     public static void stopPlcMonitor() {