|
@@ -100,6 +100,12 @@ public class MesClient extends JFrame {
|
|
|
public static Timer plcMonitorTimer;
|
|
public static Timer plcMonitorTimer;
|
|
|
public static boolean plc_finish_handled = false;
|
|
public static boolean plc_finish_handled = false;
|
|
|
public static boolean plc_finish_last = 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) {
|
|
public static void main(String[] args) {
|
|
|
EventQueue.invokeLater(new Runnable() {
|
|
EventQueue.invokeLater(new Runnable() {
|
|
@@ -317,6 +323,7 @@ public class MesClient extends JFrame {
|
|
|
S7Util.setQualityOk(false);
|
|
S7Util.setQualityOk(false);
|
|
|
plc_finish_handled = false;
|
|
plc_finish_handled = false;
|
|
|
plc_finish_last = false;
|
|
plc_finish_last = false;
|
|
|
|
|
+ clearCmtDataBuf();
|
|
|
|
|
|
|
|
work_status = 0;
|
|
work_status = 0;
|
|
|
check_quality_result = false;
|
|
check_quality_result = false;
|
|
@@ -438,16 +445,54 @@ public class MesClient extends JFrame {
|
|
|
finish_ng_bt.setEnabled(false);
|
|
finish_ng_bt.setEnabled(false);
|
|
|
f_scan_data_bt_1.setEnabled(false);
|
|
f_scan_data_bt_1.setEnabled(false);
|
|
|
clearProcessDataUI();
|
|
clearProcessDataUI();
|
|
|
|
|
+ clearCmtDataBuf();
|
|
|
|
|
|
|
|
S7Util.setQualityOk(true);
|
|
S7Util.setQualityOk(true);
|
|
|
setMenuStatus("质量校验通过,等待设备焊接", 0);
|
|
setMenuStatus("质量校验通过,等待设备焊接", 0);
|
|
|
startPlcMonitor();
|
|
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() {
|
|
public static void startPlcMonitor() {
|
|
|
stopPlcMonitor();
|
|
stopPlcMonitor();
|
|
|
plc_finish_last = false;
|
|
plc_finish_last = false;
|
|
|
|
|
+ clearCmtDataBuf();
|
|
|
plcMonitorTimer = new Timer();
|
|
plcMonitorTimer = new Timer();
|
|
|
|
|
+ // 每 1 秒采样过程数据
|
|
|
plcMonitorTimer.schedule(new TimerTask() {
|
|
plcMonitorTimer.schedule(new TimerTask() {
|
|
|
@Override
|
|
@Override
|
|
|
public void run() {
|
|
public void run() {
|
|
@@ -458,14 +503,15 @@ public class MesClient extends JFrame {
|
|
|
|
|
|
|
|
final boolean finish = S7Util.isFinish();
|
|
final boolean finish = S7Util.isFinish();
|
|
|
final boolean welding = S7Util.isWelding();
|
|
final boolean welding = S7Util.isWelding();
|
|
|
- final boolean finishDetected = finish || (finish && !plc_finish_last);
|
|
|
|
|
plc_finish_last = finish;
|
|
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;
|
|
plc_finish_handled = true;
|
|
|
|
|
+ uploadCmtDataBatch();
|
|
|
SwingUtilities.invokeLater(new Runnable() {
|
|
SwingUtilities.invokeLater(new Runnable() {
|
|
|
@Override
|
|
@Override
|
|
|
public void run() {
|
|
public void run() {
|
|
@@ -474,14 +520,18 @@ public class MesClient extends JFrame {
|
|
|
setMenuStatus("设备加工完成,请提交结果", 0);
|
|
setMenuStatus("设备加工完成,请提交结果", 0);
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 未完成且焊接中:读取过程数据并上传
|
|
|
|
|
|
|
+ // 未完成且焊接中:读取并按 # 拼接,满 100 个上传一次
|
|
|
if (welding && !finish && !plc_finish_handled) {
|
|
if (welding && !finish && !plc_finish_handled) {
|
|
|
final float wireSpeed = S7Util.readWireSpeed();
|
|
final float wireSpeed = S7Util.readWireSpeed();
|
|
|
final float current = S7Util.readCurrent();
|
|
final float current = S7Util.readCurrent();
|
|
|
final float voltage = S7Util.readVoltage();
|
|
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() {
|
|
SwingUtilities.invokeLater(new Runnable() {
|
|
|
@Override
|
|
@Override
|
|
|
public void run() {
|
|
public void run() {
|
|
@@ -489,20 +539,15 @@ public class MesClient extends JFrame {
|
|
|
setMenuStatus("设备焊接中...", 0);
|
|
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) {
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- }, 500, 500);
|
|
|
|
|
|
|
+ }, 1000, 1000);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public static void stopPlcMonitor() {
|
|
public static void stopPlcMonitor() {
|