|
|
@@ -133,7 +133,10 @@ public class MesClient extends JFrame {
|
|
|
public static List<TaskParam> taskParamList = new ArrayList<>();
|
|
|
public static TaskParam curTaskParam = null;
|
|
|
|
|
|
- public static TCPClient tcpClient1 = new TCPClient("192.168.18.182",9004);
|
|
|
+ //OP260扫码枪
|
|
|
+ public static TCPClient tcpClient1 = new TCPClient("192.168.17.50",9004);
|
|
|
+ //OP350扫码枪
|
|
|
+// public static TCPClient tcpClient1 = new TCPClient("192.168.17.52",9004);
|
|
|
public static int scanFlag1 = 0;
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
@@ -338,15 +341,28 @@ public class MesClient extends JFrame {
|
|
|
mesStartFlag = 0;
|
|
|
curTaskName.setText("");
|
|
|
|
|
|
-// f_scan_data_bt_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/scan_barcode.png")));
|
|
|
-// f_scan_data_bt_1.setText("扫码");
|
|
|
-// MesClient.f_scan_data_bt_1.setEnabled(true);
|
|
|
+ setScanButtonText("扫码");
|
|
|
MesClient.setMenuStatus("请扫工件码",0);
|
|
|
|
|
|
// MesClient.result.setText("等待结果");
|
|
|
// MesClient.result.setForeground(Color.GRAY);
|
|
|
}
|
|
|
|
|
|
+ public static void setScanButtonText(String text) {
|
|
|
+ if(f_scan_data_bt_1 == null){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Runnable update = () -> {
|
|
|
+ f_scan_data_bt_1.setIcon(null);
|
|
|
+ f_scan_data_bt_1.setText(text);
|
|
|
+ };
|
|
|
+ if(SwingUtilities.isEventDispatchThread()){
|
|
|
+ update.run();
|
|
|
+ }else{
|
|
|
+ SwingUtilities.invokeLater(update);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public static int userLoginHours;//用户登录所处小时
|
|
|
public static JTextField param1;
|
|
|
public static JTextField param2;
|
|
|
@@ -618,64 +634,57 @@ public class MesClient extends JFrame {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /** 输入框回车 / 键盘楔入式扫码枪:使用输入框内容,不触发 TCP 扫码 */
|
|
|
+ public static void scanBarcodeFromInput() {
|
|
|
+ if(work_status == 1){
|
|
|
+ MesClient.serialPortUtils.start();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ handleProductSn(product_sn.getText().trim());
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 扫码按钮:空闲时 TCP 扫码;已扫码等待时执行启动 */
|
|
|
public static void scanBarcode2() {
|
|
|
if(work_status == 1){
|
|
|
-// MesClient.serialPortUtils.sendData("START");
|
|
|
+ MesClient.serialPortUtils.start();
|
|
|
return;
|
|
|
}
|
|
|
-// String scanBarcode = product_sn.getText().trim();
|
|
|
- String scanBarcode = MesClient.scanQrcode();
|
|
|
+ // 扫码在后台线程执行,避免阻塞 Swing 界面线程导致卡顿
|
|
|
+ if(scanFlag1 == 1){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ setMenuStatus("正在扫码,请对准条码...", 0);
|
|
|
+ if(f_scan_data_bt_1 != null){
|
|
|
+ f_scan_data_bt_1.setEnabled(false);
|
|
|
+ }
|
|
|
+ new Thread(() -> {
|
|
|
+ String scanBarcode = MesClient.scanQrcode();
|
|
|
+ SwingUtilities.invokeLater(() -> {
|
|
|
+ if(f_scan_data_bt_1 != null){
|
|
|
+ f_scan_data_bt_1.setEnabled(true);
|
|
|
+ }
|
|
|
+ String sn = scanBarcode == null ? "" : scanBarcode.trim();
|
|
|
+ if(sn.isEmpty()){
|
|
|
+ setMenuStatus("扫码超时或未识别,请重试", 1);
|
|
|
+ product_sn.setText("");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ handleProductSn(sn);
|
|
|
+ });
|
|
|
+ }, "tcp-barcode-scan").start();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void handleProductSn(String scanBarcode) {
|
|
|
//刷新界面
|
|
|
mesClientFrame.repaint();
|
|
|
|
|
|
- if(scanBarcode.isEmpty()){
|
|
|
+ if(scanBarcode == null || scanBarcode.isEmpty()){
|
|
|
MesClient.setMenuStatus("工件码不能为空",1);
|
|
|
product_sn.setText("");
|
|
|
return;
|
|
|
}
|
|
|
MesClient.product_sn.setText(scanBarcode);
|
|
|
|
|
|
-// // 验证工件码前缀
|
|
|
-// if(MesClient.configParam.getProductSnPre() != null && !MesClient.configParam.getProductSnPre().trim().isEmpty()) {
|
|
|
-// int preLen = MesClient.configParam.getProductSnPre().trim().length();
|
|
|
-// if(preLen > scanBarcode.length()){
|
|
|
-// MesClient.setMenuStatus("工件码前缀不符合要求",-1);
|
|
|
-// product_sn.setText("");
|
|
|
-// return;
|
|
|
-// }else{
|
|
|
-// String pre = scanBarcode.substring(0,preLen);
|
|
|
-// if(!pre.equals(MesClient.configParam.getProductSnPre().trim())){
|
|
|
-// MesClient.setMenuStatus("工件码前缀不符合要求",-1);
|
|
|
-// product_sn.setText("");
|
|
|
-// return;
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// //验证工件码长度
|
|
|
-// int snLen = MesClient.configParam.getProductSnLength() != null && MesClient.configParam.getProductSnLength().trim().isEmpty() ? 0 : Integer.valueOf(MesClient.configParam.getProductSnLength());
|
|
|
-// if(snLen > 0 && snLen != scanBarcode.length()) {
|
|
|
-// MesClient.setMenuStatus("工件码长度不符合要求",-1);
|
|
|
-// product_sn.setText("");
|
|
|
-// return;
|
|
|
-// }
|
|
|
-
|
|
|
-// // 验证NG
|
|
|
-// int isCheck = JdbcUtils.checkSnTimer(scanBarcode,configParam);
|
|
|
-// System.err.println("isCheck:" + isCheck);
|
|
|
-// if(isCheck == 1){
|
|
|
-// int ngTime = Integer.valueOf(configParam.getNgTime());
|
|
|
-// MesClient.setMenuStatus("工件码测试NG必须间隔"+ngTime+"分钟",-1);
|
|
|
-// product_sn.setText("");
|
|
|
-// return;
|
|
|
-// } else if(isCheck == 2){
|
|
|
-// int ngUpgradeTime = Integer.valueOf(configParam.getNgUpgradeTime());
|
|
|
-// int ngNumber = Integer.valueOf(configParam.getNgNumber());
|
|
|
-// MesClient.setMenuStatus("工件码测试NG"+ngNumber+"次,必须间隔"+ngUpgradeTime+"分钟",-1);
|
|
|
-// product_sn.setText("");
|
|
|
-// return;
|
|
|
-// }
|
|
|
-
|
|
|
if(checkProductSn(scanBarcode.trim())){
|
|
|
serialPortUtils.changeProgram(); // 切换程序
|
|
|
if(MesClient.mes_enable){
|
|
|
@@ -691,6 +700,7 @@ public class MesClient extends JFrame {
|
|
|
MesClient.tjFlag = 1;
|
|
|
MesClient.setMenuStatus("扫码成功,等待测试",0);
|
|
|
product_sn.setEditable(false);
|
|
|
+ setScanButtonText("启动");
|
|
|
if(MesClient.configParam.getStartMode().equals("自动启动")){
|
|
|
MesClient.serialPortUtils.start();
|
|
|
}
|
|
|
@@ -698,9 +708,6 @@ public class MesClient extends JFrame {
|
|
|
MesClient.result.setForeground(Color.GRAY);
|
|
|
}
|
|
|
}
|
|
|
-// f_scan_data_bt_1.setIcon(null);
|
|
|
-// f_scan_data_bt_1.setText("启动");
|
|
|
-
|
|
|
}
|
|
|
|
|
|
public static void scanBarcodeOld() {
|
|
|
@@ -944,7 +951,7 @@ public class MesClient extends JFrame {
|
|
|
product_sn.addActionListener(new ActionListener() {
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
scan_type = 1;
|
|
|
- scanBarcode2();
|
|
|
+ scanBarcodeFromInput();
|
|
|
}
|
|
|
});
|
|
|
|
|
|
@@ -953,7 +960,6 @@ public class MesClient extends JFrame {
|
|
|
f_scan_data_bt_1.addActionListener(new ActionListener() {
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
scan_type = 1;
|
|
|
-// scanBarcode();
|
|
|
scanBarcode2();
|
|
|
}
|
|
|
});
|