|
|
@@ -71,6 +71,13 @@ public class MesClient extends JFrame {
|
|
|
public static JTextField product_sn;
|
|
|
public static JButton f_scan_data_bt_1;
|
|
|
|
|
|
+ public static JLabel wire_speed_label;
|
|
|
+ public static JLabel current_label;
|
|
|
+ public static JLabel voltage_label;
|
|
|
+ public static JLabel wire_speed_value;
|
|
|
+ public static JLabel current_value;
|
|
|
+ public static JLabel voltage_value;
|
|
|
+
|
|
|
public static String user20 = "";
|
|
|
|
|
|
public static JFrame welcomeWin;
|
|
|
@@ -89,6 +96,10 @@ public class MesClient extends JFrame {
|
|
|
|
|
|
public static SerialPort serialPort; // 串口对象
|
|
|
|
|
|
+ public static String mes_plc_ip = "192.168.6.40";
|
|
|
+ public static Timer plcMonitorTimer;
|
|
|
+ public static boolean plc_finish_handled = false;
|
|
|
+
|
|
|
public static void main(String[] args) {
|
|
|
EventQueue.invokeLater(new Runnable() {
|
|
|
@Override
|
|
|
@@ -110,6 +121,8 @@ public class MesClient extends JFrame {
|
|
|
|
|
|
serialPort = ModbusRtu.connect();
|
|
|
|
|
|
+ S7Util.init(mes_plc_ip);
|
|
|
+
|
|
|
startJsTimer();
|
|
|
|
|
|
}catch (Exception e){
|
|
|
@@ -133,10 +146,13 @@ public class MesClient extends JFrame {
|
|
|
mes_tcp_port = Integer.parseInt(pro.getProperty("mes.tcp_port"));
|
|
|
mes_heart_beat_cycle = Integer.parseInt(pro.getProperty("mes.heart_beat_cycle"));
|
|
|
mes_line_sn = pro.getProperty("mes.line_sn");
|
|
|
+ if (pro.getProperty("mes.plc_ip") != null) {
|
|
|
+ mes_plc_ip = pro.getProperty("mes.plc_ip").trim();
|
|
|
+ }
|
|
|
|
|
|
mes_gw_des = OprnoUtil.getGwDes(mes_line_sn,mes_gw);
|
|
|
|
|
|
- System.out.println(mes_gw + ";" + mes_gw_des + ";" + mes_server_ip + ";" + mes_tcp_port + ";" + mes_heart_beat_cycle);
|
|
|
+ System.out.println(mes_gw + ";" + mes_gw_des + ";" + mes_server_ip + ";" + mes_tcp_port + ";" + mes_heart_beat_cycle + ";" + mes_plc_ip);
|
|
|
}
|
|
|
|
|
|
// 初始化TCP
|
|
|
@@ -296,26 +312,23 @@ public class MesClient extends JFrame {
|
|
|
}
|
|
|
|
|
|
public static void resetScanA() {
|
|
|
+ stopPlcMonitor();
|
|
|
+ S7Util.setQualityOk(false);
|
|
|
+ plc_finish_handled = false;
|
|
|
+
|
|
|
work_status = 0;
|
|
|
check_quality_result = false;
|
|
|
-// MesClient.start_work_bt.setVisible(false);
|
|
|
-// MesClient.finish_ng_bt.setVisible(false);
|
|
|
-// MesClient.finish_ok_bt.setVisible(false);
|
|
|
MesClient.finish_ok_bt.setEnabled(false);
|
|
|
MesClient.finish_ng_bt.setEnabled(false);
|
|
|
product_sn.setText("");
|
|
|
+ clearProcessDataUI();
|
|
|
|
|
|
MesClient.f_scan_data_bt_1.setEnabled(true);
|
|
|
-// DataUtil.stopWork(sessionid);
|
|
|
MesClient.status_menu.setText("请扫工件码");
|
|
|
-// product_result_text.setText("");
|
|
|
-// work_status_text.setText("");
|
|
|
-// MesClient.setMenuStatus("上件牙套数据个数不符合要求",-1);
|
|
|
|
|
|
MesClient.checkState = false;
|
|
|
MesClient.jsFlag = 0;
|
|
|
MesClient.jsCount = 0;
|
|
|
-// MesClient.formatDeviceState();
|
|
|
ModbusRtu.closeDevice(serialPort);
|
|
|
updateMaterailData();
|
|
|
}
|
|
|
@@ -366,40 +379,134 @@ public class MesClient extends JFrame {
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
- //弹窗扫工件码
|
|
|
- String scanBarcode = JOptionPane.showInputDialog(null, scanBarcodeTitle);
|
|
|
+ final String scanBarcode = JOptionPane.showInputDialog(null, scanBarcodeTitle);
|
|
|
if(scanBarcode!=null&&!scanBarcode.equalsIgnoreCase("")) {
|
|
|
- //获取用户
|
|
|
getUser();
|
|
|
- //获取扫码内容36位
|
|
|
- String barcode36 = getBarcode(scanBarcode);//处理36为码
|
|
|
- //工位号
|
|
|
- String gw = "";
|
|
|
switch(scan_type) {
|
|
|
case 1:
|
|
|
product_sn.setText(scanBarcode);
|
|
|
break;
|
|
|
}
|
|
|
- //刷新界面
|
|
|
mesClientFrame.repaint();
|
|
|
|
|
|
- if(!tcp_connect_flag) {
|
|
|
- JOptionPane.showMessageDialog(mesClientFrame,"设备未连接Mes服务器","提示窗口", JOptionPane.INFORMATION_MESSAGE);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- // 查询工件质量
|
|
|
- Boolean sendret = DataUtil.checkQuality(nettyClient,barcode36,user20);
|
|
|
- if(!sendret){
|
|
|
- JOptionPane.showMessageDialog(mesClientFrame,"消息发送失败,请重试","提示窗口", JOptionPane.INFORMATION_MESSAGE);
|
|
|
- return;
|
|
|
- }
|
|
|
+ setMenuStatus("正在质量校验...", 0);
|
|
|
+ f_scan_data_bt_1.setEnabled(false);
|
|
|
+
|
|
|
+ new Thread(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ final JSONObject retObj = DataUtil.checkQualityHttp(scanBarcode, 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) {
|
|
|
+ onQualityCheckPassed();
|
|
|
+ } else {
|
|
|
+ f_scan_data_bt_1.setEnabled(true);
|
|
|
+ setMenuStatus(message, -1);
|
|
|
+ JOptionPane.showMessageDialog(mesClientFrame, message, "提示窗口", JOptionPane.INFORMATION_MESSAGE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }).start();
|
|
|
}else {
|
|
|
JOptionPane.showMessageDialog(mesClientFrame,"请扫工件码","提示窗口", JOptionPane.INFORMATION_MESSAGE);
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /** 质量校验通过:置位 DB17.8.0,启动 PLC 监控 */
|
|
|
+ public static void onQualityCheckPassed() {
|
|
|
+ check_quality_result = true;
|
|
|
+ work_status = 1;
|
|
|
+ plc_finish_handled = false;
|
|
|
+ finish_ok_bt.setEnabled(false);
|
|
|
+ finish_ng_bt.setEnabled(false);
|
|
|
+ f_scan_data_bt_1.setEnabled(false);
|
|
|
+ clearProcessDataUI();
|
|
|
+
|
|
|
+ S7Util.setQualityOk(true);
|
|
|
+ setMenuStatus("质量校验通过,等待设备焊接", 0);
|
|
|
+ startPlcMonitor();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void startPlcMonitor() {
|
|
|
+ stopPlcMonitor();
|
|
|
+ plcMonitorTimer = new Timer();
|
|
|
+ plcMonitorTimer.schedule(new TimerTask() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ try {
|
|
|
+ if (work_status != 1) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 焊接中:每秒读取送丝速度/电流/电压
|
|
|
+ if (S7Util.isWelding()) {
|
|
|
+ final int wireSpeed = S7Util.readWireSpeed();
|
|
|
+ final int current = S7Util.readCurrent();
|
|
|
+ final int voltage = S7Util.readVoltage();
|
|
|
+ SwingUtilities.invokeLater(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ updateProcessDataUI(wireSpeed, current, voltage);
|
|
|
+ setMenuStatus("设备焊接中...", 0);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ // 完成信号:点亮 OK/NG
|
|
|
+ if (!plc_finish_handled && S7Util.isFinish()) {
|
|
|
+ plc_finish_handled = true;
|
|
|
+ SwingUtilities.invokeLater(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ finish_ok_bt.setEnabled(true);
|
|
|
+ finish_ng_bt.setEnabled(true);
|
|
|
+ setMenuStatus("设备加工完成,请提交结果", 0);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }, 1000, 1000);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void stopPlcMonitor() {
|
|
|
+ if (plcMonitorTimer != null) {
|
|
|
+ plcMonitorTimer.cancel();
|
|
|
+ plcMonitorTimer = null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void updateProcessDataUI(int wireSpeed, int current, int voltage) {
|
|
|
+ if (wire_speed_value != null) {
|
|
|
+ wire_speed_value.setText(String.valueOf(wireSpeed));
|
|
|
+ }
|
|
|
+ if (current_value != null) {
|
|
|
+ current_value.setText(String.valueOf(current));
|
|
|
+ }
|
|
|
+ if (voltage_value != null) {
|
|
|
+ voltage_value.setText(String.valueOf(voltage));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void clearProcessDataUI() {
|
|
|
+ updateProcessDataUI(0, 0, 0);
|
|
|
+ }
|
|
|
+
|
|
|
public static void logoff() {
|
|
|
// welcomeWin.setVisible(true);
|
|
|
mesClientFrame.setVisible(false);
|
|
|
@@ -574,12 +681,32 @@ public class MesClient extends JFrame {
|
|
|
f_scan_data_bt_1.setBounds(693, 70, 198, 70);
|
|
|
indexPanelA.add(f_scan_data_bt_1);
|
|
|
|
|
|
-// String[] hjtitles = new String[]{"焊机1","焊机2","焊机3"};
|
|
|
-// String[] hjvals = new String[]{"HJ001","HJ002","HJ003"};
|
|
|
-// mesRadioHj = new MesRadio(hjtitles,hjvals);
|
|
|
-// mesRadioHj.setSize(500,50);
|
|
|
-// mesRadioHj.setBounds(190,170,500,50);
|
|
|
-// indexPanelA.add(mesRadioHj);
|
|
|
+ wire_speed_label = new JLabel("送丝速度:");
|
|
|
+ wire_speed_label.setFont(new Font("微软雅黑", Font.PLAIN, 22));
|
|
|
+ wire_speed_label.setBounds(81, 160, 130, 40);
|
|
|
+ indexPanelA.add(wire_speed_label);
|
|
|
+ wire_speed_value = new JLabel("0");
|
|
|
+ wire_speed_value.setFont(new Font("微软雅黑", Font.BOLD, 22));
|
|
|
+ wire_speed_value.setBounds(210, 160, 120, 40);
|
|
|
+ indexPanelA.add(wire_speed_value);
|
|
|
+
|
|
|
+ current_label = new JLabel("电流:");
|
|
|
+ current_label.setFont(new Font("微软雅黑", Font.PLAIN, 22));
|
|
|
+ current_label.setBounds(360, 160, 80, 40);
|
|
|
+ indexPanelA.add(current_label);
|
|
|
+ current_value = new JLabel("0");
|
|
|
+ current_value.setFont(new Font("微软雅黑", Font.BOLD, 22));
|
|
|
+ current_value.setBounds(440, 160, 120, 40);
|
|
|
+ indexPanelA.add(current_value);
|
|
|
+
|
|
|
+ voltage_label = new JLabel("电压:");
|
|
|
+ voltage_label.setFont(new Font("微软雅黑", Font.PLAIN, 22));
|
|
|
+ voltage_label.setBounds(590, 160, 80, 40);
|
|
|
+ indexPanelA.add(voltage_label);
|
|
|
+ voltage_value = new JLabel("0");
|
|
|
+ voltage_value.setFont(new Font("微软雅黑", Font.BOLD, 22));
|
|
|
+ voltage_value.setBounds(670, 160, 120, 40);
|
|
|
+ indexPanelA.add(voltage_value);
|
|
|
|
|
|
finish_ok_bt = new JButton("OK");
|
|
|
finish_ok_bt.setEnabled(false);
|