|
|
@@ -56,7 +56,7 @@ public class MesClient extends JFrame {
|
|
|
public static JScrollPane indexScrollPaneA;
|
|
|
public static JScrollPane searchScrollPane;
|
|
|
public static JScrollPane searchScrollPaneDj;
|
|
|
- public static SerialPortUtils serialPortUtils;
|
|
|
+ public static WeightSerialService serialPortService;
|
|
|
public static ParamConfig paramConfig;
|
|
|
public static Boolean check_quality_result = false;
|
|
|
public static Integer work_status = 0;
|
|
|
@@ -67,13 +67,10 @@ public class MesClient extends JFrame {
|
|
|
|
|
|
public static int scan_type = 0;
|
|
|
public static JButton finish_ok_bt;
|
|
|
- public static JButton batch_sn_bt;
|
|
|
public static JTextField product_sn;
|
|
|
public static JButton f_scan_data_bt_1;
|
|
|
- public static JButton is_js_btn;
|
|
|
public static String comboBoxValue = "COM1";
|
|
|
public static String user20 = "";
|
|
|
- public static String is_js_btn_val = "1";
|
|
|
|
|
|
public static JFrame welcomeWin;
|
|
|
|
|
|
@@ -116,14 +113,54 @@ public class MesClient extends JFrame {
|
|
|
}
|
|
|
|
|
|
public static void initComPort() {
|
|
|
- serialPortUtils = new SerialPortUtils();
|
|
|
- paramConfig = new ParamConfig((String) comboBox.getSelectedItem(), 1200, 0, 8, 1);
|
|
|
-// paramConfig = new ParamConfig("COM7", 1200, 0, 8, 1);
|
|
|
- System.out.println("串口号:"+(String) comboBox.getSelectedItem());
|
|
|
- //初始化串口
|
|
|
- serialPortUtils.init(paramConfig);
|
|
|
- System.out.println("初始化com串口结束...");
|
|
|
+ // 若已有旧实例,先关闭
|
|
|
+ if (serialPortService != null) {
|
|
|
+ serialPortService.close();
|
|
|
+ serialPortService = null;
|
|
|
+ }
|
|
|
+ serialPortService = new WeightSerialService();
|
|
|
+ // 默认波特率 9600(可通过 ParamConfig.DEFAULT_BAUD_RATE 修改)
|
|
|
+ paramConfig = new ParamConfig((String) comboBox.getSelectedItem(), ParamConfig.DEFAULT_BAUD_RATE);
|
|
|
+ System.out.println("串口号:" + comboBox.getSelectedItem() + " 波特率:" + paramConfig.getBaudRate());
|
|
|
+
|
|
|
+ // 注册重量数据监听器:收到数据时同步连接状态并更新 UI
|
|
|
+ serialPortService.addListener(new WeightSerialService.WeightDataListener() {
|
|
|
+ @Override
|
|
|
+ public void onWeightData(WeightData data) {
|
|
|
+ // 仅在"称重"状态下更新界面显示
|
|
|
+ SwingUtilities.invokeLater(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ if (weight_text != null) {
|
|
|
+ // 秤端发来的小数点位数比实际多1,导致值被多除以10,此处乘以10修正
|
|
|
+ weight_text.setText(String.valueOf(data.getValue() * 10));
|
|
|
+ }
|
|
|
+ System.out.println("收到重量数据: " + data);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
+ @Override
|
|
|
+ public void onConnectionChanged(boolean connected) {
|
|
|
+ com_connect_flag = connected;
|
|
|
+ System.out.println("串口连接状态: " + (connected ? "已连接" : "已断开"));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError(Throwable t) {
|
|
|
+ System.err.println("串口通信异常: " + t.getMessage());
|
|
|
+ t.printStackTrace();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ boolean ok = serialPortService.open(paramConfig);
|
|
|
+ if (ok) {
|
|
|
+ com_connect_flag = true;
|
|
|
+ System.out.println("com串口连接成功...");
|
|
|
+ } else {
|
|
|
+ com_connect_flag = false;
|
|
|
+ System.out.println("com串口连接失败...");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//定时任务重连吊秤
|
|
|
@@ -135,7 +172,7 @@ public class MesClient extends JFrame {
|
|
|
MesClient.cjTimer2.schedule(new TimerTask() {
|
|
|
public void run() {
|
|
|
try {
|
|
|
- if (!com_connect_flag) {
|
|
|
+ if (serialPortService == null || !serialPortService.isConnected()) {
|
|
|
System.out.println("吊秤断开连接,正在重连");
|
|
|
initComPort();
|
|
|
}
|
|
|
@@ -192,9 +229,7 @@ public class MesClient extends JFrame {
|
|
|
public static java.util.Timer heartBeatIconTimer;
|
|
|
public static boolean iconREDFlag = true;
|
|
|
public static JTextField weight_text;
|
|
|
- public static JTextField batch_sn_text;
|
|
|
public static JLabel lblNewLabel;
|
|
|
- public static JLabel lblNewLabel_1;
|
|
|
private static JComboBox comboBox;
|
|
|
public static JButton finish_ok_bt_1;
|
|
|
public static void startHeartBeatTimer() {
|
|
|
@@ -273,30 +308,15 @@ public class MesClient extends JFrame {
|
|
|
public static void resetScanA() {
|
|
|
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);
|
|
|
product_sn.setText("");
|
|
|
- batch_sn_text.setText("");
|
|
|
weight_text.setText("");
|
|
|
- batch_sn_bt.setEnabled(false);
|
|
|
weight_text.setEnabled(false);
|
|
|
- is_js_btn.setText("最后一台");
|
|
|
- is_js_btn_val = "1";
|
|
|
- is_js_btn.setBackground(null);
|
|
|
finish_ok_bt.setEnabled(false);
|
|
|
MesClient.finish_ok_bt_1.setText("称重");
|
|
|
-// MesClient.f_scan_data_bt_1.setEnabled(false);
|
|
|
|
|
|
MesClient.f_scan_data_bt_1.setEnabled(true);
|
|
|
-// DataUtil.stopWork(sessionid);
|
|
|
setMenuStatus("请扫工件码",0);
|
|
|
-// product_result_text.setText("");
|
|
|
-// work_status_text.setText("");
|
|
|
-// MesClient.setMenuStatus("涂胶已超过10分钟,已失效",-1);
|
|
|
-
|
|
|
-// updateMaterailData();
|
|
|
shiftUserCheck();
|
|
|
}
|
|
|
|
|
|
@@ -556,7 +576,9 @@ public class MesClient extends JFrame {
|
|
|
@Override
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
//修改串口时,先关闭资源,重新初始化
|
|
|
- serialPortUtils.closeSerialPort();
|
|
|
+ if (serialPortService != null) {
|
|
|
+ serialPortService.close();
|
|
|
+ }
|
|
|
MesClient.initComPort();
|
|
|
}
|
|
|
});
|
|
|
@@ -597,48 +619,21 @@ public class MesClient extends JFrame {
|
|
|
// mesRadioHj.setBounds(190,170,500,50);
|
|
|
// indexPanelA.add(mesRadioHj);
|
|
|
|
|
|
- finish_ok_bt = new JButton("打包");
|
|
|
+ finish_ok_bt = new JButton("OK");
|
|
|
finish_ok_bt.setEnabled(false);
|
|
|
finish_ok_bt.addActionListener(new ActionListener() {
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
if(work_status == 1 && check_quality_result) {
|
|
|
-
|
|
|
- if ( batch_sn_text.getText().equals("")){
|
|
|
- JOptionPane.showMessageDialog(mesClientFrame,"请先获取包装码!","提示窗口", JOptionPane.INFORMATION_MESSAGE);
|
|
|
+ // 调用bindWarehouse绑定重量并上传:wsn=重量, sn=工件码, craft=400006
|
|
|
+ String sn = getBarcode(product_sn.getText());
|
|
|
+ getUser();
|
|
|
+ String wsn = weight_text.getText();
|
|
|
+ Boolean sendret = DataUtil.bindWarehouse(nettyClient, sn, wsn, user20, "400006");
|
|
|
+ if (!sendret) {
|
|
|
+ JOptionPane.showMessageDialog(mesClientFrame, "消息发送失败,请重试", "提示窗口", JOptionPane.INFORMATION_MESSAGE);
|
|
|
+ return;
|
|
|
}
|
|
|
- String is_js = is_js_btn_val;
|
|
|
- String result = HttpUtils.sendRequest(
|
|
|
- "http://"+MesClient.mes_server_ip+":8980/js/a/mes/mesProductRecord/dp350?" +
|
|
|
- "sn=" + product_sn.getText() + "&oprno=" + mes_gw + "&batchSn=" +
|
|
|
- batch_sn_text.getText() + "&weight=" + weight_text.getText() + "&isJs=" + is_js);
|
|
|
-// batch_sn_text.getText() + "&weight=123" + "&isJs=" + is_js);
|
|
|
-// String result = HttpUtils.sendRequest(
|
|
|
-// "http://127.0.0.1:8980/js/a/mes/mesProductRecord/dp350?" +
|
|
|
-// "sn=" + product_sn.getText() + "&oprno=" + mes_gw + "&batchSn=" +
|
|
|
-// batch_sn_text.getText() + "&weight=" + weight_text.getText() + "&isJs=" + is_js);
|
|
|
- if (result != null && !result.equals("") && !result.equals("false")) {
|
|
|
- JSONObject ret = JSON.parseObject(result);
|
|
|
- if (ret.get("result").equals("true")) {
|
|
|
- MesClient.setMenuStatus("结果提交成功,请扫下一件",0);
|
|
|
- resetScanA();
|
|
|
-// cjTimer.cancel();
|
|
|
-// MesClient.weight_text.setText("");
|
|
|
- }else {
|
|
|
- JOptionPane.showMessageDialog(mesClientFrame, "结果提交失败,"+ret.get("message")+"!", "提示窗口", JOptionPane.INFORMATION_MESSAGE);
|
|
|
- MesClient.setMenuStatus("结果提交失败,请重试!",1);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-// 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;
|
|
|
-// }
|
|
|
-
|
|
|
+ MesClient.setMenuStatus("正在上传结果...", 0);
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
@@ -655,65 +650,6 @@ public class MesClient extends JFrame {
|
|
|
weight_text.setBounds(403, 300, 181, 70);
|
|
|
indexPanelA.add(weight_text);
|
|
|
|
|
|
- batch_sn_text = new JTextField();
|
|
|
- batch_sn_text.setEditable(false);
|
|
|
- batch_sn_text.setHorizontalAlignment(SwingConstants.CENTER);
|
|
|
- batch_sn_text.setFont(new Font("微软雅黑", Font.PLAIN, 28));
|
|
|
- batch_sn_text.setColumns(10);
|
|
|
- batch_sn_text.setBounds(403, 192, 280, 70);
|
|
|
- indexPanelA.add(batch_sn_text);
|
|
|
-
|
|
|
- batch_sn_bt = new JButton("生成包装码");
|
|
|
- batch_sn_bt.setEnabled(false);
|
|
|
- batch_sn_bt.addActionListener(new ActionListener() {
|
|
|
- public void actionPerformed(ActionEvent e) {
|
|
|
- //生成包装码
|
|
|
- try {
|
|
|
- String result = HttpUtils.sendRequest("http://"+MesClient.mes_server_ip+":8980/js/a/mes/mesBatchSn/createBatchSn?lineSn="+mes_line_sn);
|
|
|
- JSONObject ret = JSON.parseObject(result);
|
|
|
- String TF = ret.getString("result");
|
|
|
- if (Boolean.parseBoolean(TF)){
|
|
|
- String batchSn = ret.getJSONObject("data").getString("batchSn");
|
|
|
- //赋值 禁用生成按钮
|
|
|
- batch_sn_text.setText(batchSn);
|
|
|
- MesClient.batch_sn_bt.setEnabled(false);
|
|
|
- MesClient.finish_ok_bt.setEnabled(true);
|
|
|
- setMenuStatus("生成包装码成功",0);
|
|
|
- }else{
|
|
|
- JOptionPane.showMessageDialog(mesClientFrame,"生成包装码失败!,请重试","提示窗口", JOptionPane.INFORMATION_MESSAGE);
|
|
|
-
|
|
|
- }
|
|
|
- } catch (Exception ex) {
|
|
|
- ex.printStackTrace();
|
|
|
- JOptionPane.showMessageDialog(mesClientFrame,"生成包装码失败!,请重试","提示窗口", JOptionPane.INFORMATION_MESSAGE);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-// if (result!= null&&!result.equals("")&&!result.equals("false")) {
|
|
|
-// JSONObject ret = JSON.parseObject(result);
|
|
|
-// if (ret != null && ret.containsKey("data")) {
|
|
|
-// String batchSn = ret.getJSONObject("data").getString("batchSn");
|
|
|
-// if (batchSn == null || batchSn.equals("")) { // 包装码为null,激活生成包装码按钮
|
|
|
-// JOptionPane.showMessageDialog(mesClientFrame,"生成包装码失败!,请重试","提示窗口", JOptionPane.INFORMATION_MESSAGE);
|
|
|
-// }else{
|
|
|
-// //赋值 禁用生成按钮
|
|
|
-// batch_sn_text.setText(batchSn);
|
|
|
-// MesClient.batch_sn_bt.setEnabled(false);
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// }else{
|
|
|
-// JOptionPane.showMessageDialog(mesClientFrame,"生成包装码失败!,请重试","提示窗口", JOptionPane.INFORMATION_MESSAGE);
|
|
|
-// }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
- });
|
|
|
- batch_sn_bt.setFont(new Font("微软雅黑", Font.PLAIN, 30));
|
|
|
- batch_sn_bt.setBounds(693, 192, 198, 70);
|
|
|
- indexPanelA.add(batch_sn_bt);
|
|
|
-
|
|
|
lblNewLabel = new JLabel("重量");
|
|
|
lblNewLabel.setEnabled(false);
|
|
|
lblNewLabel.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
|
@@ -721,35 +657,6 @@ public class MesClient extends JFrame {
|
|
|
lblNewLabel.setBounds(238, 300, 117, 70);
|
|
|
indexPanelA.add(lblNewLabel);
|
|
|
|
|
|
- lblNewLabel_1 = new JLabel("包装码");
|
|
|
- lblNewLabel_1.setEnabled(false);
|
|
|
- lblNewLabel_1.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
|
- lblNewLabel_1.setFont(new Font("微软雅黑", Font.PLAIN, 30));
|
|
|
- lblNewLabel_1.setBounds(238, 192, 117, 70);
|
|
|
- indexPanelA.add(lblNewLabel_1);
|
|
|
-
|
|
|
- is_js_btn = new JButton("最后一台");
|
|
|
- is_js_btn.addActionListener(new ActionListener() {
|
|
|
- public void actionPerformed(ActionEvent e) {
|
|
|
-// if (is_js_btn.getText().equals("结束")){
|
|
|
-// is_js_btn.setText("开始");
|
|
|
-// }else if (is_js_btn.getText().equals("开始")){
|
|
|
-// is_js_btn.setText("结束");
|
|
|
-// }
|
|
|
- if (is_js_btn_val.equals("2")){
|
|
|
- is_js_btn.setBackground(null);
|
|
|
- is_js_btn_val = "1";
|
|
|
- }else{
|
|
|
-// is_js_btn.setText("结束");
|
|
|
- is_js_btn.setBackground(Color.GREEN);
|
|
|
- is_js_btn_val = "2";
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- is_js_btn.setFont(new Font("微软雅黑", Font.PLAIN, 32));
|
|
|
- is_js_btn.setBounds(693, 300, 198, 70);
|
|
|
- indexPanelA.add(is_js_btn);
|
|
|
-
|
|
|
finish_ok_bt_1 = new JButton("确定");
|
|
|
finish_ok_bt_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ok_bg.png")));
|
|
|
finish_ok_bt_1.addActionListener(new ActionListener() {
|