|
|
@@ -5,6 +5,10 @@ import com.mes.component.MesRadio;
|
|
|
import com.mes.component.MesWebView;
|
|
|
import com.mes.netty.NettyClient;
|
|
|
import com.mes.util.*;
|
|
|
+import com.mes.util.ytnetty.YtNettyClient;
|
|
|
+import com.mes.util.ytnetty.YtUtil;
|
|
|
+import io.netty.buffer.ByteBuf;
|
|
|
+import io.netty.buffer.Unpooled;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
@@ -35,7 +39,7 @@ public class MesClient extends JFrame {
|
|
|
public static int mes_auth = 0; // 权限级别 0=无权限 1=操作工人 2=管理员
|
|
|
public static String mes_gw = ""; // 工位号
|
|
|
public static String mes_gw_des = ""; // 工位名称
|
|
|
- public static String mes_server_ip = ""; // 服务器IP地址
|
|
|
+ public static String mes_server_ip = ""; // 服务器、地址
|
|
|
public static int mes_tcp_port = 3000; // TCP服务端口
|
|
|
public static int mes_heart_beat_cycle = 10; // 心跳周期
|
|
|
public static int mes_heart_icon_cycle = 1;
|
|
|
@@ -75,6 +79,8 @@ public class MesClient extends JFrame {
|
|
|
|
|
|
public static String user20 = "";
|
|
|
|
|
|
+ public static boolean mes_enable = true; // true=MES开启
|
|
|
+
|
|
|
public static JFrame welcomeWin;
|
|
|
|
|
|
public static JPanel indexPanelB;
|
|
|
@@ -112,6 +118,7 @@ public class MesClient extends JFrame {
|
|
|
|
|
|
public static String tjFlagTextErr = "结果上传MES失败,请重试";
|
|
|
|
|
|
+ public static CommonQmDevice commonQmDevice;
|
|
|
public static SerialPortUtils serialPortUtils;
|
|
|
public static JTextField printSn2;
|
|
|
public static JTextField printTitle2;
|
|
|
@@ -121,6 +128,13 @@ public class MesClient extends JFrame {
|
|
|
public static Integer isConfigEdit = 0;
|
|
|
public static Integer mesStartFlag = 0;
|
|
|
public static Integer mesTjFlag = 0;
|
|
|
+ public static boolean qm_tcp_flag = false;
|
|
|
+ /** 本轮实时压强/泄漏(与气密仪 RS 一致),提交时优先于 4353 旧协议解析值 */
|
|
|
+ public static String lastQmPressure = "";
|
|
|
+ public static String lastQmLeak = "";
|
|
|
+
|
|
|
+ //TCP连接
|
|
|
+ public static YtNettyClient ytClient;
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
EventQueue.invokeLater(new Runnable() {
|
|
|
@@ -142,14 +156,26 @@ public class MesClient extends JFrame {
|
|
|
formatConfigEdit(false);
|
|
|
formatConfigData();
|
|
|
|
|
|
- serialPortUtils=new SerialPortUtils(configParam.getSerialPort(),"","",configParam.getDevice());
|
|
|
-// getMaterailData();
|
|
|
+ commonQmDevice = new CommonQmDevice(configParam);
|
|
|
+
|
|
|
+// serialPortUtils=new SerialPortUtils(configParam.getSerialPort(),"","",configParam.getDevice());
|
|
|
+
|
|
|
+// initYgslTcpConnection();
|
|
|
//
|
|
|
-// startUpdateQualityTimer(); // 开启提交结果的定时任务
|
|
|
+
|
|
|
+// nettyClient.future.channel().writeAndFlush("5354"); // 启动
|
|
|
+
|
|
|
+ // 初始化MES TCP连接与心跳(质量检查用)
|
|
|
+ if(mes_enable){
|
|
|
+ initTcpConnection();
|
|
|
+ startHeartBeatTimer();
|
|
|
+ }
|
|
|
+
|
|
|
startDateTimer();
|
|
|
|
|
|
textFocus();
|
|
|
|
|
|
+ monitorDevice();
|
|
|
resetScanA();
|
|
|
}catch (Exception e){
|
|
|
log.error(e.getMessage());
|
|
|
@@ -173,6 +199,36 @@ public class MesClient extends JFrame {
|
|
|
}, 1000,1000);
|
|
|
}
|
|
|
|
|
|
+ public static Timer cjTimerText2;
|
|
|
+ public static void monitorDevice() {
|
|
|
+ if(cjTimerText2!=null) {
|
|
|
+ cjTimerText2.cancel();
|
|
|
+ }
|
|
|
+ // 空闲时不再主动读实时/结果,避免未扫码时把设备历史结果写入本地库
|
|
|
+ // 测试中的轮询由 CommonQmDevice.workTimerTask 在 work_status==1 时负责
|
|
|
+ }
|
|
|
+
|
|
|
+ // 初始化TCP
|
|
|
+ public static void initYgslTcpConnection() {
|
|
|
+ try {
|
|
|
+ if(ytClient==null) {
|
|
|
+ String ip = MesClient.configParam.getSerialPort();
|
|
|
+ String port = MesClient.configParam.getBaudRate();
|
|
|
+ //初始化TCP连接
|
|
|
+ ytClient = new YtNettyClient();
|
|
|
+ try{
|
|
|
+ ytClient.run(ip,Integer.parseInt(port));
|
|
|
+// ytClient.run("192.168.0.253",3036);
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ // TODO Auto-generated catch block
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public static java.util.Timer dateBeatTimer;
|
|
|
public static void startDateTimer() {
|
|
|
if (dateBeatTimer != null) {
|
|
|
@@ -329,6 +385,21 @@ public class MesClient extends JFrame {
|
|
|
// MesClient.result.setForeground(Color.GRAY);
|
|
|
}
|
|
|
|
|
|
+ /** 保留工件码并复位标志,便于同一工件连续多次测试 */
|
|
|
+ public static void resetForRetestKeepSn() {
|
|
|
+ work_status = 0;
|
|
|
+ check_quality_result = false;
|
|
|
+ MesClient.finish_ok_bt.setEnabled(false);
|
|
|
+ MesClient.finish_ng_bt.setEnabled(false);
|
|
|
+ product_sn.setEditable(true);
|
|
|
+ tjFlag = 0;
|
|
|
+ mesStartFlag = 0;
|
|
|
+ mesTjFlag = 0;
|
|
|
+ lastQmPressure = "";
|
|
|
+ lastQmLeak = "";
|
|
|
+ MesClient.setMenuStatus("已保存,同件回车可再测,或扫下一件",0);
|
|
|
+ }
|
|
|
+
|
|
|
public static int userLoginHours;//用户登录所处小时
|
|
|
public static JTextField param1;
|
|
|
public static JTextField param2;
|
|
|
@@ -590,19 +661,113 @@ public class MesClient extends JFrame {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ // MES开启:先质量检查,通过后再进入测试(参照 OP-qm)
|
|
|
+ if(MesClient.mes_enable){
|
|
|
+ if(!tcp_connect_flag || nettyClient == null){
|
|
|
+ MesClient.setMenuStatus("未连接MES服务器,请检查网络后重试",-1);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ getUser();
|
|
|
+ MesClient.setMenuStatus("质量检查中...",0);
|
|
|
+ Boolean sendret = DataUtil.checkQuality(nettyClient, scanBarcode, user20);
|
|
|
+ if(!sendret){
|
|
|
+ MesClient.setMenuStatus("质量检查发送失败,请重试",-1);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // MES关闭:本地直接进入测试
|
|
|
+ beginTestAfterScan();
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 扫码/质量检查通过后进入测试状态 */
|
|
|
+ public static void beginTestAfterScan() {
|
|
|
work_status = 1;
|
|
|
-// f_scan_data_bt_1.setEnabled(false);
|
|
|
MesClient.tjFlag = 1;
|
|
|
- MesClient.setMenuStatus("扫码成功,等待测试",0);
|
|
|
+ MesClient.mesStartFlag = 0;
|
|
|
+ MesClient.mesTjFlag = 0;
|
|
|
+ MesClient.lastQmPressure = "";
|
|
|
+ MesClient.lastQmLeak = "";
|
|
|
+ MesClient.check_quality_result = true;
|
|
|
+ MesClient.setMenuStatus("该工件可以测试,等待测试",0);
|
|
|
product_sn.setEditable(false);
|
|
|
if(MesClient.configParam.getStartMode().equals("自动启动")){
|
|
|
- MesClient.serialPortUtils.start();
|
|
|
+ MesClient.commonQmDevice.start();
|
|
|
}
|
|
|
MesClient.result.setText("等待结果");
|
|
|
MesClient.result.setForeground(Color.GRAY);
|
|
|
-// f_scan_data_bt_1.setIcon(null);
|
|
|
-// f_scan_data_bt_1.setText("启动");
|
|
|
+ }
|
|
|
|
|
|
+ /**
|
|
|
+ * 本地存库后提交MES(HTTP直传 qmresult,参照 OP-qm),成功则复位。
|
|
|
+ * @return true=可继续后续(含打印),false=MES上传失败已拦截
|
|
|
+ */
|
|
|
+ public static boolean afterTestSaveAndUpload(TestParam testParam) {
|
|
|
+ String testDate = testParam.getCreateTime();
|
|
|
+ if(testDate == null || testDate.isEmpty()){
|
|
|
+ testDate = DateLocalUtils.getCurrentTime();
|
|
|
+ testParam.setCreateTime(testDate);
|
|
|
+ }
|
|
|
+ // 本地库仍用合并后的压力/泄漏便于列表展示
|
|
|
+ TestParam localParam = new TestParam();
|
|
|
+ localParam.setSn(testParam.getSn());
|
|
|
+ localParam.setOprno(testParam.getOprno() != null ? testParam.getOprno() : "");
|
|
|
+ localParam.setParam1((testParam.getParam1() != null ? testParam.getParam1() : "")
|
|
|
+ + (testParam.getParam2() != null ? testParam.getParam2() : ""));
|
|
|
+ localParam.setParam2((testParam.getParam3() != null ? testParam.getParam3() : "")
|
|
|
+ + (testParam.getParam4() != null ? testParam.getParam4() : ""));
|
|
|
+ localParam.setParam3("");
|
|
|
+ localParam.setParam4("");
|
|
|
+ localParam.setResult(testParam.getResult());
|
|
|
+ JdbcUtils.insertTestRecord(localParam);
|
|
|
+
|
|
|
+ if(mes_enable){
|
|
|
+ JSONObject retObj = DataUtil.qmResultData(testParam);
|
|
|
+ if(retObj != null && retObj.get("result") != null && retObj.get("result").toString().equalsIgnoreCase("true")) {
|
|
|
+ if(MesClient.configParam.getPrintLabel().equals("是") && "OK".equals(testParam.getResult())){
|
|
|
+ PrintUtil.printLabel(testParam.getSn(),
|
|
|
+ (testParam.getParam1() != null ? testParam.getParam1() : "") + (testParam.getParam2() != null ? testParam.getParam2() : ""),
|
|
|
+ (testParam.getParam3() != null ? testParam.getParam3() : "") + (testParam.getParam4() != null ? testParam.getParam4() : ""),
|
|
|
+ testDate);
|
|
|
+ }
|
|
|
+ MesClient.resetForRetestKeepSn();
|
|
|
+ MesClient.setMenuStatus("测试结果上传成功,同件回车可再测,或扫下一件",0);
|
|
|
+ try { JdbcUtils.getTestData(); } catch (Exception ignore) {}
|
|
|
+ return true;
|
|
|
+ }else{
|
|
|
+ MesClient.mesStartFlag = 0;
|
|
|
+ MesClient.mesTjFlag = 0;
|
|
|
+ MesClient.setMenuStatus("测试结果上传失败,请重试(可直接再测本件)",-1);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ if(MesClient.configParam.getPrintLabel().equals("是") && "OK".equals(testParam.getResult())){
|
|
|
+ PrintUtil.printLabel(testParam.getSn(),
|
|
|
+ (testParam.getParam1() != null ? testParam.getParam1() : "") + (testParam.getParam2() != null ? testParam.getParam2() : ""),
|
|
|
+ (testParam.getParam3() != null ? testParam.getParam3() : "") + (testParam.getParam4() != null ? testParam.getParam4() : ""),
|
|
|
+ testDate);
|
|
|
+ }
|
|
|
+ MesClient.resetForRetestKeepSn();
|
|
|
+ try { JdbcUtils.getTestData(); } catch (Exception ignore) {}
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 填充MES上传公共字段 */
|
|
|
+ public static void fillMesTestMeta(TestParam testParam) {
|
|
|
+ getUser();
|
|
|
+ testParam.setOprno(mes_gw);
|
|
|
+ testParam.setOprnoTitle(mes_gw_des);
|
|
|
+ testParam.setLineSn(mes_line_sn);
|
|
|
+ testParam.setUcode(user_menu != null ? user_menu.getText().trim() : "");
|
|
|
+ testParam.setParam5(programNo != null ? programNo.getText().trim() : "");
|
|
|
+ if(configParam != null){
|
|
|
+ testParam.setDeviceType(configParam.getDevice());
|
|
|
+ }
|
|
|
+ if(testParam.getRemark() == null){
|
|
|
+ testParam.setRemark("");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public static void scanBarcodeOld() {
|
|
|
@@ -849,7 +1014,16 @@ public class MesClient extends JFrame {
|
|
|
f_scan_data_bt_1.addActionListener(new ActionListener() {
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
scan_type = 1;
|
|
|
- scanBarcode();
|
|
|
+ System.out.println("点击启动");
|
|
|
+ if(work_status != 1){
|
|
|
+ MesClient.setMenuStatus("请先扫码并通过质量检查",-1);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if(commonQmDevice != null){
|
|
|
+ commonQmDevice.start();
|
|
|
+ }else{
|
|
|
+ MesClient.setMenuStatus("设备未初始化",-1);
|
|
|
+ }
|
|
|
}
|
|
|
});
|
|
|
// f_scan_data_bt_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/scan_barcode.png")));
|
|
|
@@ -1176,7 +1350,7 @@ public class MesClient extends JFrame {
|
|
|
startMode.setBounds(140, 71, 200, 30);
|
|
|
indexPanelD.add(startMode);
|
|
|
|
|
|
- JLabel lblNewLabel_3_1_1 = new JLabel("串口号");
|
|
|
+ JLabel lblNewLabel_3_1_1 = new JLabel("串口号/IP");
|
|
|
lblNewLabel_3_1_1.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
|
lblNewLabel_3_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 16));
|
|
|
lblNewLabel_3_1_1.setBounds(10, 123, 120, 30);
|
|
|
@@ -1188,7 +1362,7 @@ public class MesClient extends JFrame {
|
|
|
serialPort.setBounds(140, 123, 200, 30);
|
|
|
indexPanelD.add(serialPort);
|
|
|
|
|
|
- JLabel lblNewLabel_3_1_1_1 = new JLabel("波特率");
|
|
|
+ JLabel lblNewLabel_3_1_1_1 = new JLabel("波特率/端口");
|
|
|
lblNewLabel_3_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
|
lblNewLabel_3_1_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 16));
|
|
|
lblNewLabel_3_1_1_1.setBounds(10, 176, 120, 30);
|
|
|
@@ -1374,8 +1548,8 @@ public class MesClient extends JFrame {
|
|
|
isConfigEdit = 0;
|
|
|
|
|
|
formatConfigData();
|
|
|
- serialPortUtils.closePort();
|
|
|
- serialPortUtils = new SerialPortUtils(configParam.getSerialPort(),"","",configParam.getDevice());
|
|
|
+
|
|
|
+ commonQmDevice.reconnect();
|
|
|
}
|
|
|
|
|
|
}
|
|
|
@@ -1424,7 +1598,7 @@ public class MesClient extends JFrame {
|
|
|
indexPanelD.add(lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1_1_2);
|
|
|
|
|
|
device = new JComboBox();
|
|
|
- device.setModel(new DefaultComboBoxModel(new String[] {"innomatec", "ateq"}));
|
|
|
+ device.setModel(new DefaultComboBoxModel(new String[] {"innomatec", "ateq", "中皖英泰"}));
|
|
|
device.setFont(new Font("微软雅黑", Font.PLAIN, 16));
|
|
|
device.setBounds(536, 445, 200, 30);
|
|
|
indexPanelD.add(device);
|
|
|
@@ -1487,4 +1661,20 @@ public class MesClient extends JFrame {
|
|
|
}
|
|
|
MesClient.status_menu.setText(msg);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 将字符串消息转为ByteBuf
|
|
|
+ * 16进制字符串转二进制
|
|
|
+ * @param hex 字符串消息
|
|
|
+ */
|
|
|
+ public static ByteBuf getSendByteBuf(String hex) {
|
|
|
+ byte[] bytes = new byte[hex.length() / 2];
|
|
|
+ for (int i = 0; i < hex.length(); i += 2) {
|
|
|
+ int value = Integer.parseInt(hex.substring(i, i + 2), 16);
|
|
|
+ bytes[i/2] = (byte)(value & 0xFF);
|
|
|
+ }
|
|
|
+ return Unpooled.wrappedBuffer(bytes);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|