|
|
@@ -3,6 +3,8 @@ package com.mes.ui;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.mes.component.MesRadio;
|
|
|
import com.mes.component.MesWebView;
|
|
|
+import com.mes.controller.LaserController;
|
|
|
+import com.mes.device.LaserDevice;
|
|
|
import com.mes.netty.NettyClient;
|
|
|
import com.mes.netty.ProtocolParam;
|
|
|
import com.mes.util.*;
|
|
|
@@ -125,6 +127,22 @@ public class MesClient extends JFrame {
|
|
|
public static boolean timer_flag = false; // 开始计时标志 false=非工作开始计时 true=工件开始计时
|
|
|
public static long timer_nums = 0; // 秒数
|
|
|
|
|
|
+ // 激光切割设备
|
|
|
+ public static LaserDevice laserDevice;
|
|
|
+ public static com.mes.controller.LaserControllerDual laserController;
|
|
|
+ public static String laser_device_ip = ""; // 激光设备IP,从配置文件读取
|
|
|
+
|
|
|
+ // 双面UI组件
|
|
|
+ public static JTextField product_sn2; // B面工件码
|
|
|
+ public static JLabel pxstatus1; // A面状态
|
|
|
+ public static JLabel pxstatus2; // B面状态
|
|
|
+ public static JTextField param1; // A面进给速度
|
|
|
+ public static JTextField param2; // A面加工时间
|
|
|
+ public static JTextField param3; // A面零件数
|
|
|
+ public static JTextField param21; // B面进给速度
|
|
|
+ public static JTextField param22; // B面加工时间
|
|
|
+ public static JTextField param23; // B面零件数
|
|
|
+
|
|
|
public static void main(String[] args) {
|
|
|
|
|
|
if (LockUtil.getInstance().isAppActive() == true){
|
|
|
@@ -153,6 +171,12 @@ public class MesClient extends JFrame {
|
|
|
|
|
|
getMaterailData();
|
|
|
|
|
|
+ // 初始化激光设备
|
|
|
+ initLaserDevice();
|
|
|
+
|
|
|
+ // 启动激光定时器
|
|
|
+ startLaserTimers();
|
|
|
+
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
@@ -164,7 +188,7 @@ public class MesClient extends JFrame {
|
|
|
//读配置文件
|
|
|
private static void readProperty() throws IOException{
|
|
|
String enconding = "UTF-8";
|
|
|
- InputStream is = ClassLoader.getSystemResourceAsStream("resources/config/config.properties");
|
|
|
+ InputStream is = ClassLoader.getSystemResourceAsStream("config/config.properties");
|
|
|
Properties pro = new Properties();
|
|
|
BufferedReader br = new BufferedReader(new InputStreamReader(is, enconding));
|
|
|
pro.load(br);
|
|
|
@@ -174,9 +198,13 @@ public class MesClient extends JFrame {
|
|
|
mes_heart_beat_cycle = Integer.parseInt(pro.getProperty("mes.heart_beat_cycle"));
|
|
|
mes_line_sn = pro.getProperty("mes.line_sn");
|
|
|
|
|
|
+ // 读取激光设备IP
|
|
|
+ laser_device_ip = pro.getProperty("laser.device.ip", "192.168.1.100");
|
|
|
+
|
|
|
mes_gw_des = OprnoUtil.getGwDes(mes_line_sn,mes_gw);
|
|
|
|
|
|
log.info(mes_gw + ";" + mes_gw_des + ";" + mes_server_ip + ";" + mes_tcp_port + ";" + mes_heart_beat_cycle);
|
|
|
+ log.info("激光设备IP: " + laser_device_ip);
|
|
|
}
|
|
|
|
|
|
// 初始化TCP
|
|
|
@@ -280,17 +308,41 @@ public class MesClient extends JFrame {
|
|
|
check_quality_result = false;
|
|
|
MesClient.finish_ok_bt.setEnabled(false);
|
|
|
MesClient.finish_ng_bt.setEnabled(false);
|
|
|
-// product_sn.setText("000020015308-0100101425022500085");
|
|
|
product_sn.setText("");
|
|
|
MesClient.fxlabel.setVisible(false);
|
|
|
|
|
|
MesClient.f_scan_data_bt_1.setEnabled(true);
|
|
|
MesClient.status_menu.setText("请扫工件码");
|
|
|
|
|
|
+ // 清空参数显示
|
|
|
+ if(param1 != null) param1.setText("");
|
|
|
+ if(param2 != null) param2.setText("");
|
|
|
+ if(param3 != null) param3.setText("");
|
|
|
+ if(pxstatus1 != null) pxstatus1.setText("A");
|
|
|
+
|
|
|
+ // 复位激光控制器A面状态
|
|
|
+ if(laserController != null) {
|
|
|
+ laserController.manualResetA();
|
|
|
+ }
|
|
|
+
|
|
|
updateMaterailData();
|
|
|
shiftUserCheck();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void resetScanB() {
|
|
|
+ // B面复位逻辑
|
|
|
+ if(product_sn2 != null) product_sn2.setText("");
|
|
|
+ if(param21 != null) param21.setText("");
|
|
|
+ if(param22 != null) param22.setText("");
|
|
|
+ if(param23 != null) param23.setText("");
|
|
|
+ if(pxstatus2 != null) pxstatus2.setText("B");
|
|
|
+
|
|
|
+ // 复位激光控制器B面状态
|
|
|
+ if(laserController != null) {
|
|
|
+ laserController.manualResetB();
|
|
|
+ }
|
|
|
|
|
|
-// MesClient.setMenuStatus("设备报警停机",-1);
|
|
|
+ shiftUserCheck();
|
|
|
}
|
|
|
|
|
|
public static int userLoginHours;//用户登录所处小时
|
|
|
@@ -311,9 +363,6 @@ public class MesClient extends JFrame {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- public static void resetScanB() {
|
|
|
-
|
|
|
- }
|
|
|
|
|
|
//获取用户20位
|
|
|
public static void getUser() {
|
|
|
@@ -349,13 +398,7 @@ public class MesClient extends JFrame {
|
|
|
JOptionPane.showMessageDialog(mesClientFrame,"工作中,勿扫码","提示窗口", JOptionPane.INFORMATION_MESSAGE);
|
|
|
return;
|
|
|
}
|
|
|
- String scanBarcodeTitle = "";
|
|
|
- switch(scan_type) {
|
|
|
- case 1:
|
|
|
- product_sn.setText("");
|
|
|
- scanBarcodeTitle = "请扫工件码";
|
|
|
- break;
|
|
|
- }
|
|
|
+ String scanBarcodeTitle = "请扫工件码(A面或B面)";
|
|
|
|
|
|
//弹窗扫工件码
|
|
|
String scanBarcode = JOptionPane.showInputDialog(null, scanBarcodeTitle);
|
|
|
@@ -364,32 +407,53 @@ public class MesClient extends JFrame {
|
|
|
getUser();
|
|
|
//获取扫码内容36位
|
|
|
String barcode36 = getBarcode(scanBarcode);//处理36为码
|
|
|
- //工位号
|
|
|
- String gw = "";
|
|
|
- switch(scan_type) {
|
|
|
- case 1:
|
|
|
- product_sn.setText(scanBarcode);
|
|
|
- break;
|
|
|
+
|
|
|
+ // 判断A面还是B面(简单逻辑:询问用户)
|
|
|
+ String[] options = {"A面", "B面"};
|
|
|
+ int choice = JOptionPane.showOptionDialog(
|
|
|
+ mesClientFrame,
|
|
|
+ "请选择扫码面:",
|
|
|
+ "选择面",
|
|
|
+ JOptionPane.DEFAULT_OPTION,
|
|
|
+ JOptionPane.QUESTION_MESSAGE,
|
|
|
+ null,
|
|
|
+ options,
|
|
|
+ options[0]
|
|
|
+ );
|
|
|
+
|
|
|
+ String side = choice == 0 ? "A" : "B";
|
|
|
+
|
|
|
+ if(side.equals("A")) {
|
|
|
+ product_sn.setText(scanBarcode);
|
|
|
+ } else {
|
|
|
+ product_sn2.setText(scanBarcode);
|
|
|
}
|
|
|
+
|
|
|
//刷新界面
|
|
|
mesClientFrame.repaint();
|
|
|
|
|
|
if(!tcp_connect_flag) {
|
|
|
MesClient.setMenuStatus("设备未连接Mes服务器",-1);
|
|
|
-// JOptionPane.showMessageDialog(mesClientFrame,"设备未连接Mes服务器","提示窗口", JOptionPane.INFORMATION_MESSAGE);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- // 查询工件质量
|
|
|
- Boolean sendret = DataUtil.checkQuality(nettyClient,barcode36,user20);
|
|
|
+ // 查询工件质量(MES质检)
|
|
|
+ Boolean sendret = DataUtil.checkQuality(nettyClient,barcode36,user20,side);
|
|
|
if(!sendret){
|
|
|
MesClient.setMenuStatus("消息发送失败,请重试",-1);
|
|
|
-// JOptionPane.showMessageDialog(mesClientFrame,"消息发送失败,请重试","提示窗口", JOptionPane.INFORMATION_MESSAGE);
|
|
|
return;
|
|
|
}
|
|
|
+
|
|
|
+ // 扫码处理交给控制器
|
|
|
+ if(laserController != null) {
|
|
|
+ if(side.equals("A")) {
|
|
|
+ laserController.onScanCodeA(scanBarcode, user20);
|
|
|
+ } else {
|
|
|
+ laserController.onScanCodeB(scanBarcode, user20);
|
|
|
+ }
|
|
|
+ }
|
|
|
}else {
|
|
|
MesClient.setMenuStatus("请扫工件码,请重试",-1);
|
|
|
-// JOptionPane.showMessageDialog(mesClientFrame,"请扫工件码","提示窗口", JOptionPane.INFORMATION_MESSAGE);
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
@@ -556,109 +620,152 @@ public class MesClient extends JFrame {
|
|
|
tabbedPane.setFont(new Font("宋体", Font.BOLD, 22));
|
|
|
contentPane.add(tabbedPane);
|
|
|
|
|
|
- //首页
|
|
|
- JPanel indexPanelA = new CenteredPanel(972, 450);
|
|
|
+ //首页 - 双面布局(参考OP060)
|
|
|
+ JPanel indexPanelA = new CenteredPanel(972, 550);
|
|
|
indexScrollPaneA = new JScrollPane(indexPanelA);
|
|
|
indexPanelA.setLayout(null);
|
|
|
|
|
|
- product_sn = new JTextField();
|
|
|
- product_sn.setHorizontalAlignment(SwingConstants.CENTER);
|
|
|
- product_sn.setEditable(false);
|
|
|
- product_sn.setFont(new Font("微软雅黑", Font.PLAIN, 28));
|
|
|
- product_sn.setBounds(81, 70, 602, 70);
|
|
|
- indexPanelA.add(product_sn);
|
|
|
- product_sn.setColumns(10);
|
|
|
-
|
|
|
+ // 扫码按钮(居中)
|
|
|
f_scan_data_bt_1 = new JButton("扫码");
|
|
|
f_scan_data_bt_1.addActionListener(new ActionListener() {
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
- scan_type = 1;
|
|
|
scanBarcode();
|
|
|
}
|
|
|
});
|
|
|
f_scan_data_bt_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/scan_barcode.png")));
|
|
|
- f_scan_data_bt_1.setFont(new Font("微软雅黑", Font.PLAIN, 32));
|
|
|
- f_scan_data_bt_1.setBounds(693, 70, 198, 70);
|
|
|
+ f_scan_data_bt_1.setFont(new Font("微软雅黑", Font.PLAIN, 28));
|
|
|
+ f_scan_data_bt_1.setBounds(400, 10, 180, 60);
|
|
|
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);
|
|
|
+ // ========== A面区域 ==========
|
|
|
+ pxstatus1 = new JLabel("A面");
|
|
|
+ pxstatus1.setForeground(new Color(0, 128, 255));
|
|
|
+ pxstatus1.setHorizontalAlignment(SwingConstants.CENTER);
|
|
|
+ pxstatus1.setFont(new Font("微软雅黑", Font.BOLD, 22));
|
|
|
+ pxstatus1.setBounds(26, 80, 446, 35);
|
|
|
+ indexPanelA.add(pxstatus1);
|
|
|
+
|
|
|
+ product_sn = new JTextField();
|
|
|
+ product_sn.setHorizontalAlignment(SwingConstants.CENTER);
|
|
|
+ product_sn.setEditable(false);
|
|
|
+ product_sn.setFont(new Font("微软雅黑", Font.PLAIN, 20));
|
|
|
+ product_sn.setBounds(26, 120, 446, 60);
|
|
|
+ indexPanelA.add(product_sn);
|
|
|
|
|
|
- fxlabel = new JLabel("该工件为返修件,请仔细检查");
|
|
|
- fxlabel.setFont(new Font("微软雅黑", Font.PLAIN, 38));
|
|
|
- fxlabel.setBounds(81, 170, 810, 70);
|
|
|
+ JLabel lblSpeed1 = new JLabel("进给速度:");
|
|
|
+ lblSpeed1.setFont(new Font("微软雅黑", Font.PLAIN, 16));
|
|
|
+ lblSpeed1.setBounds(26, 200, 100, 30);
|
|
|
+ indexPanelA.add(lblSpeed1);
|
|
|
+
|
|
|
+ param1 = new JTextField();
|
|
|
+ param1.setEnabled(false);
|
|
|
+ param1.setEditable(false);
|
|
|
+ param1.setHorizontalAlignment(SwingConstants.CENTER);
|
|
|
+ param1.setFont(new Font("微软雅黑", Font.PLAIN, 16));
|
|
|
+ param1.setBounds(130, 200, 100, 30);
|
|
|
+ indexPanelA.add(param1);
|
|
|
+
|
|
|
+ JLabel lblTime1 = new JLabel("加工时间:");
|
|
|
+ lblTime1.setFont(new Font("微软雅黑", Font.PLAIN, 16));
|
|
|
+ lblTime1.setBounds(26, 240, 100, 30);
|
|
|
+ indexPanelA.add(lblTime1);
|
|
|
+
|
|
|
+ param2 = new JTextField();
|
|
|
+ param2.setEnabled(false);
|
|
|
+ param2.setEditable(false);
|
|
|
+ param2.setHorizontalAlignment(SwingConstants.CENTER);
|
|
|
+ param2.setFont(new Font("微软雅黑", Font.PLAIN, 16));
|
|
|
+ param2.setBounds(130, 240, 100, 30);
|
|
|
+ indexPanelA.add(param2);
|
|
|
+
|
|
|
+ JLabel lblCount1 = new JLabel("零件数:");
|
|
|
+ lblCount1.setFont(new Font("微软雅黑", Font.PLAIN, 16));
|
|
|
+ lblCount1.setBounds(26, 280, 100, 30);
|
|
|
+ indexPanelA.add(lblCount1);
|
|
|
+
|
|
|
+ param3 = new JTextField();
|
|
|
+ param3.setEnabled(false);
|
|
|
+ param3.setEditable(false);
|
|
|
+ param3.setHorizontalAlignment(SwingConstants.CENTER);
|
|
|
+ param3.setFont(new Font("微软雅黑", Font.PLAIN, 16));
|
|
|
+ param3.setBounds(130, 280, 100, 30);
|
|
|
+ indexPanelA.add(param3);
|
|
|
+
|
|
|
+ // ========== B面区域 ==========
|
|
|
+ JSeparator separator = new JSeparator();
|
|
|
+ separator.setOrientation(SwingConstants.VERTICAL);
|
|
|
+ separator.setBounds(495, 80, 2, 240);
|
|
|
+ indexPanelA.add(separator);
|
|
|
+
|
|
|
+ pxstatus2 = new JLabel("B面");
|
|
|
+ pxstatus2.setForeground(new Color(0, 128, 255));
|
|
|
+ pxstatus2.setHorizontalAlignment(SwingConstants.CENTER);
|
|
|
+ pxstatus2.setFont(new Font("微软雅黑", Font.BOLD, 22));
|
|
|
+ pxstatus2.setBounds(517, 80, 446, 35);
|
|
|
+ indexPanelA.add(pxstatus2);
|
|
|
+
|
|
|
+ product_sn2 = new JTextField();
|
|
|
+ product_sn2.setHorizontalAlignment(SwingConstants.CENTER);
|
|
|
+ product_sn2.setEditable(false);
|
|
|
+ product_sn2.setFont(new Font("微软雅黑", Font.PLAIN, 20));
|
|
|
+ product_sn2.setBounds(517, 120, 446, 60);
|
|
|
+ indexPanelA.add(product_sn2);
|
|
|
+
|
|
|
+ JLabel lblSpeed2 = new JLabel("进给速度:");
|
|
|
+ lblSpeed2.setFont(new Font("微软雅黑", Font.PLAIN, 16));
|
|
|
+ lblSpeed2.setBounds(517, 200, 100, 30);
|
|
|
+ indexPanelA.add(lblSpeed2);
|
|
|
+
|
|
|
+ param21 = new JTextField();
|
|
|
+ param21.setEnabled(false);
|
|
|
+ param21.setEditable(false);
|
|
|
+ param21.setHorizontalAlignment(SwingConstants.CENTER);
|
|
|
+ param21.setFont(new Font("微软雅黑", Font.PLAIN, 16));
|
|
|
+ param21.setBounds(621, 200, 100, 30);
|
|
|
+ indexPanelA.add(param21);
|
|
|
+
|
|
|
+ JLabel lblTime2 = new JLabel("加工时间:");
|
|
|
+ lblTime2.setFont(new Font("微软雅黑", Font.PLAIN, 16));
|
|
|
+ lblTime2.setBounds(517, 240, 100, 30);
|
|
|
+ indexPanelA.add(lblTime2);
|
|
|
+
|
|
|
+ param22 = new JTextField();
|
|
|
+ param22.setEnabled(false);
|
|
|
+ param22.setEditable(false);
|
|
|
+ param22.setHorizontalAlignment(SwingConstants.CENTER);
|
|
|
+ param22.setFont(new Font("微软雅黑", Font.PLAIN, 16));
|
|
|
+ param22.setBounds(621, 240, 100, 30);
|
|
|
+ indexPanelA.add(param22);
|
|
|
+
|
|
|
+ JLabel lblCount2 = new JLabel("零件数:");
|
|
|
+ lblCount2.setFont(new Font("微软雅黑", Font.PLAIN, 16));
|
|
|
+ lblCount2.setBounds(517, 280, 100, 30);
|
|
|
+ indexPanelA.add(lblCount2);
|
|
|
+
|
|
|
+ param23 = new JTextField();
|
|
|
+ param23.setEnabled(false);
|
|
|
+ param23.setEditable(false);
|
|
|
+ param23.setHorizontalAlignment(SwingConstants.CENTER);
|
|
|
+ param23.setFont(new Font("微软雅黑", Font.PLAIN, 16));
|
|
|
+ param23.setBounds(621, 280, 100, 30);
|
|
|
+ indexPanelA.add(param23);
|
|
|
+
|
|
|
+ // 返修标签(隐藏,需要时显示)
|
|
|
+ fxlabel = new JLabel("返修件,请仔细检查");
|
|
|
+ fxlabel.setFont(new Font("微软雅黑", Font.PLAIN, 28));
|
|
|
+ fxlabel.setBounds(300, 350, 400, 50);
|
|
|
fxlabel.setForeground(Color.RED);
|
|
|
fxlabel.setHorizontalAlignment(SwingConstants.CENTER);
|
|
|
fxlabel.setVisible(false);
|
|
|
indexPanelA.add(fxlabel);
|
|
|
|
|
|
+ // 占位按钮(隐藏)
|
|
|
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){
|
|
|
-
|
|
|
- String sn = getBarcode(product_sn.getText());
|
|
|
- if(sn.isEmpty()){
|
|
|
- MesClient.setMenuStatus("工件码为空,请重试",-1);
|
|
|
- return;
|
|
|
- }
|
|
|
- getUser();
|
|
|
-
|
|
|
- String qret = "OK";
|
|
|
- Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20);
|
|
|
- if(!sendret){
|
|
|
- MesClient.setMenuStatus("消息发送失败,请重试",-1);
|
|
|
- return;
|
|
|
- }else{
|
|
|
-// MesClient.resetScanA();
|
|
|
-// MesClient.scan_type = 1;
|
|
|
-// MesClient.scanBarcode();
|
|
|
-// MesClient.setMenuStatus("结果提交成功,请扫下一件",0);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- finish_ok_bt.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ok_bg.png")));
|
|
|
- finish_ok_bt.setFont(new Font("微软雅黑", Font.PLAIN, 32));
|
|
|
- finish_ok_bt.setBounds(185, 291, 240, 80);
|
|
|
- finish_ok_bt.setEnabled(false);
|
|
|
+ finish_ok_bt.setVisible(false);
|
|
|
indexPanelA.add(finish_ok_bt);
|
|
|
|
|
|
finish_ng_bt = new JButton("NG");
|
|
|
- finish_ng_bt.setEnabled(false);
|
|
|
- finish_ng_bt.addActionListener(new ActionListener() {
|
|
|
- public void actionPerformed(ActionEvent e) {
|
|
|
- if(work_status == 1 && check_quality_result){
|
|
|
-
|
|
|
- String sn = getBarcode(product_sn.getText());
|
|
|
- if(sn.isEmpty()){
|
|
|
- MesClient.setMenuStatus("工件码为空,请重试",-1);
|
|
|
- return;
|
|
|
- }
|
|
|
- getUser();
|
|
|
- String qret = "NG";
|
|
|
- Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20);
|
|
|
- if(!sendret){
|
|
|
- MesClient.setMenuStatus("消息发送失败,请重试",-1);
|
|
|
- return;
|
|
|
- }else{
|
|
|
-// MesClient.resetScanA();
|
|
|
-// MesClient.scan_type = 1;
|
|
|
-// MesClient.scanBarcode();
|
|
|
-// MesClient.setMenuStatus("结果提交成功,请扫下一件",0);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- finish_ng_bt.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ng_bg.png")));
|
|
|
- finish_ng_bt.setFont(new Font("微软雅黑", Font.PLAIN, 32));
|
|
|
- finish_ng_bt.setBounds(508, 291, 240, 80);
|
|
|
- finish_ng_bt.setEnabled(false);
|
|
|
+ finish_ng_bt.setVisible(false);
|
|
|
indexPanelA.add(finish_ng_bt);
|
|
|
|
|
|
tabbedPane.addTab("工作面板", new ImageIcon(MesClient.class.getResource("/bg/a_side.png")), indexScrollPaneA, null);
|
|
|
@@ -938,4 +1045,115 @@ public class MesClient extends JFrame {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 初始化激光设备
|
|
|
+ */
|
|
|
+ public static void initLaserDevice() {
|
|
|
+ try {
|
|
|
+ log.info("开始初始化激光设备...");
|
|
|
+
|
|
|
+ // 创建设备实例
|
|
|
+ laserDevice = new LaserDevice();
|
|
|
+
|
|
|
+ // 连接设备
|
|
|
+ boolean connected = laserDevice.connect(laser_device_ip);
|
|
|
+
|
|
|
+ if(connected) {
|
|
|
+ log.info("激光设备连接成功: {}", laser_device_ip);
|
|
|
+
|
|
|
+ // 创建双面控制器
|
|
|
+ laserController = new com.mes.controller.LaserControllerDual(laserDevice);
|
|
|
+
|
|
|
+ log.info("激光设备初始化完成");
|
|
|
+ } else {
|
|
|
+ log.error("激光设备连接失败: {}", laser_device_ip);
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("初始化激光设备异常", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 启动激光设备定时器
|
|
|
+ */
|
|
|
+ public static void startLaserTimers() {
|
|
|
+ try {
|
|
|
+ log.info("启动激光设备定时器...");
|
|
|
+
|
|
|
+ // 1. 状态检测定时器(1秒)
|
|
|
+ Timer laserStatusTimer = new Timer();
|
|
|
+ laserStatusTimer.schedule(new TimerTask() {
|
|
|
+ public void run() {
|
|
|
+ try {
|
|
|
+ if(laserController != null) {
|
|
|
+ laserController.checkStatus();
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("激光状态检测异常", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }, 1000, 1000);
|
|
|
+
|
|
|
+ // 2. 参数采集定时器(1秒)
|
|
|
+ Timer laserParamTimer = new Timer();
|
|
|
+ laserParamTimer.schedule(new TimerTask() {
|
|
|
+ public void run() {
|
|
|
+ try {
|
|
|
+ if(laserController != null) {
|
|
|
+ laserController.collectParams();
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("激光参数采集异常", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }, 1000, 1000);
|
|
|
+
|
|
|
+ // 3. 参数上传定时器(30秒)
|
|
|
+ Timer laserUploadTimer = new Timer();
|
|
|
+ laserUploadTimer.schedule(new TimerTask() {
|
|
|
+ public void run() {
|
|
|
+ try {
|
|
|
+ uploadLaserParams();
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("激光参数上传异常", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }, 10000, 30000);
|
|
|
+
|
|
|
+ log.info("激光设备定时器启动完成");
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("启动激光定时器异常", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 上传激光参数到MES
|
|
|
+ */
|
|
|
+ public static void uploadLaserParams() {
|
|
|
+ try {
|
|
|
+ List<LaserParamReq> params = JdbcUtils.getLaserParams();
|
|
|
+
|
|
|
+ if(params.size() > 0) {
|
|
|
+ log.info("开始上传激光参数,共{}条", params.size());
|
|
|
+
|
|
|
+ // TODO: 调用MES接口上传参数
|
|
|
+ // 参考OP60的upParams方法
|
|
|
+ // String url = "http://" + mes_server_ip + ":8980/js/a/mes/xxx";
|
|
|
+ // HttpUtils.sendPostRequestJson(url, JSON.toJSONString(params));
|
|
|
+
|
|
|
+ // 上传成功后标记为已同步
|
|
|
+ for(LaserParamReq param : params) {
|
|
|
+ JdbcUtils.updateLaserSync(param.getId(), 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("激光参数上传完成");
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("上传激光参数异常", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|