|
@@ -99,6 +99,7 @@ public class MesClient extends JFrame {
|
|
|
public static String mes_plc_ip = "192.168.6.40";
|
|
public static String mes_plc_ip = "192.168.6.40";
|
|
|
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 void main(String[] args) {
|
|
public static void main(String[] args) {
|
|
|
EventQueue.invokeLater(new Runnable() {
|
|
EventQueue.invokeLater(new Runnable() {
|
|
@@ -315,6 +316,7 @@ public class MesClient extends JFrame {
|
|
|
stopPlcMonitor();
|
|
stopPlcMonitor();
|
|
|
S7Util.setQualityOk(false);
|
|
S7Util.setQualityOk(false);
|
|
|
plc_finish_handled = false;
|
|
plc_finish_handled = false;
|
|
|
|
|
+ plc_finish_last = false;
|
|
|
|
|
|
|
|
work_status = 0;
|
|
work_status = 0;
|
|
|
check_quality_result = false;
|
|
check_quality_result = false;
|
|
@@ -427,7 +429,7 @@ public class MesClient extends JFrame {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /** 质量校验通过:置位 DB17.8.0,启动 PLC 监控 */
|
|
|
|
|
|
|
+ /** 质量校验通过:置位 DB17.14.0,启动 PLC 监控 */
|
|
|
public static void onQualityCheckPassed() {
|
|
public static void onQualityCheckPassed() {
|
|
|
check_quality_result = true;
|
|
check_quality_result = true;
|
|
|
work_status = 1;
|
|
work_status = 1;
|
|
@@ -444,6 +446,7 @@ public class MesClient extends JFrame {
|
|
|
|
|
|
|
|
public static void startPlcMonitor() {
|
|
public static void startPlcMonitor() {
|
|
|
stopPlcMonitor();
|
|
stopPlcMonitor();
|
|
|
|
|
+ plc_finish_last = false;
|
|
|
plcMonitorTimer = new Timer();
|
|
plcMonitorTimer = new Timer();
|
|
|
plcMonitorTimer.schedule(new TimerTask() {
|
|
plcMonitorTimer.schedule(new TimerTask() {
|
|
|
@Override
|
|
@Override
|
|
@@ -452,36 +455,54 @@ public class MesClient extends JFrame {
|
|
|
if (work_status != 1) {
|
|
if (work_status != 1) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- // 焊接中:每秒读取送丝速度/电流/电压
|
|
|
|
|
- if (S7Util.isWelding()) {
|
|
|
|
|
- final int wireSpeed = S7Util.readWireSpeed();
|
|
|
|
|
- final int current = S7Util.readCurrent();
|
|
|
|
|
- final int voltage = S7Util.readVoltage();
|
|
|
|
|
|
|
+
|
|
|
|
|
+ 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);
|
|
|
|
|
+
|
|
|
|
|
+ // 完成信号 DB17.0.0 为 true:停止上传并点亮 OK/NG
|
|
|
|
|
+ if (finishDetected && !plc_finish_handled) {
|
|
|
|
|
+ plc_finish_handled = true;
|
|
|
SwingUtilities.invokeLater(new Runnable() {
|
|
SwingUtilities.invokeLater(new Runnable() {
|
|
|
@Override
|
|
@Override
|
|
|
public void run() {
|
|
public void run() {
|
|
|
- updateProcessDataUI(wireSpeed, current, voltage);
|
|
|
|
|
- setMenuStatus("设备焊接中...", 0);
|
|
|
|
|
|
|
+ finish_ok_bt.setEnabled(true);
|
|
|
|
|
+ finish_ng_bt.setEnabled(true);
|
|
|
|
|
+ setMenuStatus("设备加工完成,请提交结果", 0);
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
- // 完成信号:点亮 OK/NG
|
|
|
|
|
- if (!plc_finish_handled && S7Util.isFinish()) {
|
|
|
|
|
- plc_finish_handled = true;
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // 未完成且焊接中:读取过程数据并上传
|
|
|
|
|
+ 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();
|
|
|
SwingUtilities.invokeLater(new Runnable() {
|
|
SwingUtilities.invokeLater(new Runnable() {
|
|
|
@Override
|
|
@Override
|
|
|
public void run() {
|
|
public void run() {
|
|
|
- finish_ok_bt.setEnabled(true);
|
|
|
|
|
- finish_ng_bt.setEnabled(true);
|
|
|
|
|
- setMenuStatus("设备加工完成,请提交结果", 0);
|
|
|
|
|
|
|
+ updateProcessDataUI(wireSpeed, current, voltage);
|
|
|
|
|
+ setMenuStatus("设备焊接中...", 0);
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
+ if (!sn.isEmpty()) {
|
|
|
|
|
+ new Thread(new Runnable() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void run() {
|
|
|
|
|
+ DataUtil.saveCmtDataHttp(sn, wireSpeed, current, voltage);
|
|
|
|
|
+ }
|
|
|
|
|
+ }).start();
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- }, 1000, 1000);
|
|
|
|
|
|
|
+ }, 500, 500);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public static void stopPlcMonitor() {
|
|
public static void stopPlcMonitor() {
|
|
@@ -491,20 +512,73 @@ public class MesClient extends JFrame {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public static void updateProcessDataUI(int wireSpeed, int current, int voltage) {
|
|
|
|
|
|
|
+ public static void updateProcessDataUI(float wireSpeed, float current, float voltage) {
|
|
|
if (wire_speed_value != null) {
|
|
if (wire_speed_value != null) {
|
|
|
- wire_speed_value.setText(String.valueOf(wireSpeed));
|
|
|
|
|
|
|
+ wire_speed_value.setText(String.format("%.2f", wireSpeed));
|
|
|
}
|
|
}
|
|
|
if (current_value != null) {
|
|
if (current_value != null) {
|
|
|
- current_value.setText(String.valueOf(current));
|
|
|
|
|
|
|
+ current_value.setText(String.format("%.2f", current));
|
|
|
}
|
|
}
|
|
|
if (voltage_value != null) {
|
|
if (voltage_value != null) {
|
|
|
- voltage_value.setText(String.valueOf(voltage));
|
|
|
|
|
|
|
+ voltage_value.setText(String.format("%.2f", voltage));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public static void clearProcessDataUI() {
|
|
public static void clearProcessDataUI() {
|
|
|
- updateProcessDataUI(0, 0, 0);
|
|
|
|
|
|
|
+ updateProcessDataUI(0f, 0f, 0f);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /** 点击 OK/NG 提交本工位结果 */
|
|
|
|
|
+ public static void submitResult(final String qret) {
|
|
|
|
|
+ if (work_status != 1 || !check_quality_result) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!plc_finish_handled) {
|
|
|
|
|
+ JOptionPane.showMessageDialog(mesClientFrame, "设备尚未完成,无法提交", "提示窗口", JOptionPane.INFORMATION_MESSAGE);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ final String sn = product_sn.getText().trim();
|
|
|
|
|
+ if (sn.isEmpty()) {
|
|
|
|
|
+ JOptionPane.showMessageDialog(mesClientFrame, "工件码为空,无法提交", "提示窗口", JOptionPane.INFORMATION_MESSAGE);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ finish_ok_bt.setEnabled(false);
|
|
|
|
|
+ finish_ng_bt.setEnabled(false);
|
|
|
|
|
+ setMenuStatus("正在提交结果...", 0);
|
|
|
|
|
+
|
|
|
|
|
+ new Thread(new Runnable() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void run() {
|
|
|
|
|
+ final JSONObject retObj = DataUtil.submitResultHttp(sn, qret, user_menu.getText());
|
|
|
|
|
+ SwingUtilities.invokeLater(new Runnable() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void run() {
|
|
|
|
|
+ boolean ok = false;
|
|
|
|
|
+ String message = "结果提交失败,请重试";
|
|
|
|
|
+ if (retObj != null) {
|
|
|
|
|
+ Object result = retObj.get("result");
|
|
|
|
|
+ if (result != null && ("true".equalsIgnoreCase(String.valueOf(result)) || Boolean.TRUE.equals(result))) {
|
|
|
|
|
+ ok = true;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (retObj.getString("message") != null && !retObj.getString("message").isEmpty()) {
|
|
|
|
|
+ message = retObj.getString("message");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (ok) {
|
|
|
|
|
+ resetScanA();
|
|
|
|
|
+ setMenuStatus("结果提交成功,请扫下一件", 0);
|
|
|
|
|
+ scan_type = 1;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ finish_ok_bt.setEnabled(true);
|
|
|
|
|
+ finish_ng_bt.setEnabled(true);
|
|
|
|
|
+ setMenuStatus(message, -1);
|
|
|
|
|
+ JOptionPane.showMessageDialog(mesClientFrame, message, "提示窗口", JOptionPane.INFORMATION_MESSAGE);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ }).start();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public static void logoff() {
|
|
public static void logoff() {
|
|
@@ -712,18 +786,7 @@ public class MesClient extends JFrame {
|
|
|
finish_ok_bt.setEnabled(false);
|
|
finish_ok_bt.setEnabled(false);
|
|
|
finish_ok_bt.addActionListener(new ActionListener() {
|
|
finish_ok_bt.addActionListener(new ActionListener() {
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
- if(work_status == 1 && check_quality_result){
|
|
|
|
|
-
|
|
|
|
|
- String sn = getBarcode(product_sn.getText());
|
|
|
|
|
- getUser();
|
|
|
|
|
-
|
|
|
|
|
- String qret = "OK";
|
|
|
|
|
- Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20);
|
|
|
|
|
- if(!sendret){
|
|
|
|
|
- JOptionPane.showMessageDialog(mesClientFrame,"消息发送失败,请重试","提示窗口", JOptionPane.INFORMATION_MESSAGE);
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ submitResult("OK");
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
finish_ok_bt.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ok_bg.png")));
|
|
finish_ok_bt.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ok_bg.png")));
|
|
@@ -736,17 +799,7 @@ public class MesClient extends JFrame {
|
|
|
finish_ng_bt.setEnabled(false);
|
|
finish_ng_bt.setEnabled(false);
|
|
|
finish_ng_bt.addActionListener(new ActionListener() {
|
|
finish_ng_bt.addActionListener(new ActionListener() {
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
- if(work_status == 1 && check_quality_result){
|
|
|
|
|
-
|
|
|
|
|
- String sn = getBarcode(product_sn.getText());
|
|
|
|
|
- getUser();
|
|
|
|
|
- String qret = "NG";
|
|
|
|
|
- Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20);
|
|
|
|
|
- if(!sendret){
|
|
|
|
|
- JOptionPane.showMessageDialog(mesClientFrame,"消息发送失败,请重试","提示窗口", JOptionPane.INFORMATION_MESSAGE);
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ submitResult("NG");
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
finish_ng_bt.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ng_bg.png")));
|
|
finish_ng_bt.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ng_bg.png")));
|