jingbo 3 týždňov pred
rodič
commit
58b9555083

+ 11 - 0
.project

@@ -14,4 +14,15 @@
 	<natures>
 		<nature>org.eclipse.jdt.core.javanature</nature>
 	</natures>
+	<filteredResources>
+		<filter>
+			<id>1772779588422</id>
+			<name></name>
+			<type>30</type>
+			<matcher>
+				<id>org.eclipse.core.resources.regexFilterMatcher</id>
+				<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
+			</matcher>
+		</filter>
+	</filteredResources>
 </projectDescription>

+ 2 - 5
src/com/mes/ui/LoginFarme.java

@@ -178,11 +178,6 @@ public class LoginFarme extends JFrame {
                     //启动timer心跳包
                     MesClient.startHeartBeatTimer();
 
-                    //初始化tcp连接,发送同步报文
-                    MesClient.initYgslTcpConnection();
-                    //启动timer心跳包
-                    MesClient.startYgslHeartBeatTimer();
-
                     //1操作工人,2管理员
                     //登录成功
                     MesClient.user_menu.setText(user_id);
@@ -204,6 +199,8 @@ public class LoginFarme extends JFrame {
                     }
 
                     MesClient.initWarehouseData();
+
+                    MesClient.initGunPanels();
                 }
 
             }

+ 402 - 329
src/com/mes/ui/MesClient.java

@@ -2,13 +2,13 @@ package com.mes.ui;
 
 import com.alibaba.fastjson2.JSON;
 import com.alibaba.fastjson2.JSONObject;
+import com.mes.component.GunPanel;
 import com.mes.component.MesRadio;
 import com.mes.component.MesWebView;
 import com.mes.netty.NettyClient;
 import com.mes.util.DateLocalUtils;
 import com.mes.util.JdbcUtils;
-import com.mes.ygsl.YgslClient;
-import com.mes.ygsl.YgslClient2;
+import com.mes.ygsl.YgslConfig;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
 import javafx.embed.swing.JFXPanel;
@@ -91,45 +91,13 @@ public class MesClient extends JFrame {
     public static Object[] columnNames = { "物料名称", "绑定批次", "剩余次数", "操作" };
     public static Object[][] rowData = null;
 
-    //TCP连接
-    public static YgslClient ygslClient;
-    //TCP连接状态
-    public static boolean ygsl_tcp_connect_flag = false;
-    //TCP连接请求
-    public static boolean ygsl_connect_request_flag = false;
-
-    //TCP连接
-    public static YgslClient2 ygslClient2;
-    //TCP连接状态
-    public static boolean ygsl_tcp_connect_flag2 = false;
-    //TCP连接请求
-    public static boolean ygsl_connect_request_flag2 = false;
-
-    public static Integer ygslNum = 1; // 1=单枪 2=双枪
-
-
-    public static String namea = "A"; // A枪名称 M5
-    public static Integer maxa = 12; // A枪任务数  360=12 290=89
-    public static Integer cura = 0; // A枪当前数
-    public static Integer resulta = 0; // A枪结果 0=NG 1=OK
-    public static List<String> atids = new ArrayList<>();
-    public static List<String> btids = new ArrayList<>();
-
-    public static String nameb = "B"; // B枪名称 M8
-    public static Integer maxb = 1; // B枪任务数
-    public static Integer curb = 0; // B枪当前数
-    public static Integer resultb = 0; // B枪结果 0=NG 1=OK
-    public static JLabel schedulea;
-    public static JLabel scheduleb;
-    public static JLabel torquea;
-    public static JLabel torqueb;
-    public static JLabel anglea;
-    public static JLabel angleb;
-
+    public static List<GunPanel> gunPanels = new ArrayList<>();
+    public static JPanel gunPanelContainer;
     public static JLabel pzlabel;
 
-    public static JButton ygslm8;
-    public static JButton ygslm6;
+    public static java.util.Timer submitCheckTimer;
+
+    public static boolean autoSubmitEnabled = true;
 
 
     public static void main(String[] args) {
@@ -163,6 +131,8 @@ public class MesClient extends JFrame {
 
                     checkpz();
 
+                    startSubmitCheckTimer();
+
                 }catch (Exception e){
                     e.printStackTrace();
                 }
@@ -170,6 +140,88 @@ public class MesClient extends JFrame {
         });
     }
 
+    public static void initGunPanels() {
+        gunPanels.clear();
+
+        System.out.println("initGunPanels - gunPanelContainer: " + gunPanelContainer);
+
+        List<YgslConfig> configs = JdbcUtils.getEnabledYgslConfigs();
+        System.out.println("initGunPanels - 获取到配置: " + configs.size() + " 把枪");
+        for (YgslConfig config : configs) {
+            GunPanel gunPanel = new GunPanel(config);
+            gunPanel.setTaskCompletedListener(new GunPanel.OnTaskCompletedListener() {
+                @Override
+                public void onTaskCompleted(GunPanel panel) {
+                    checkAllGunsCompleted();
+                }
+            });
+            gunPanels.add(gunPanel);
+
+            if (gunPanelContainer != null) {
+                gunPanelContainer.add(gunPanel);
+                gunPanelContainer.revalidate();
+                gunPanelContainer.repaint();
+                gunPanel.connect();
+                System.out.println("已添加枪到容器: " + config.getGunName());
+            } else {
+                System.out.println("gunPanelContainer 为空,无法添加!");
+            }
+        }
+
+        System.out.println("已加载 " + gunPanels.size() + " 把扭力枪");
+    }
+
+    public static void startSubmitCheckTimer() {
+        if (submitCheckTimer != null) {
+            submitCheckTimer.cancel();
+        }
+        submitCheckTimer = new Timer();
+        submitCheckTimer.schedule(new TimerTask() {
+            @Override
+            public void run() {
+                checkAllGunsCompleted();
+            }
+        }, 1000, 1000);
+    }
+
+    private static void checkAllGunsCompleted() {
+        if (work_status != 1 || !check_quality_result) {
+            return;
+        }
+
+        if (!autoSubmitEnabled) {
+            return;
+        }
+
+        boolean allCompleted = true;
+        for (GunPanel panel : gunPanels) {
+            if (!panel.isTaskCompleted()) {
+                allCompleted = false;
+                break;
+            }
+        }
+
+        if (allCompleted) {
+            final boolean submitSuccess = submitQualityResult();
+            SwingUtilities.invokeLater(() -> {
+                if (submitSuccess) {
+                    setMenuStatus("所有任务完成,结果已提交", 0);
+                    resetScanA();
+                    scanBarcode();
+                } else {
+                    setMenuStatus("结果提交失败,请重试", -1);
+                }
+            });
+        }
+    }
+
+    private static boolean submitQualityResult() {
+        String sn = getBarcode(product_sn.getText());
+        getUser();
+        String qret = "OK";
+        return DataUtil.sendQuality(nettyClient, sn, qret, user20);
+    }
+
     //读配置文件
     private static void readProperty() throws IOException{
         String enconding = "UTF-8";
@@ -270,83 +322,7 @@ public class MesClient extends JFrame {
     }
 
 
-    // 初始化TCP
-    public static void initYgslTcpConnection() {
-        try {
-            if(ygslClient==null) {
-                //初始化TCP连接
-                ygslClient = new YgslClient();
-//                //TCP连接状态
-//                ygsl_tcp_connect_flag = false;
-//                //设置TCP请求状态
-//                ygsl_connect_request_flag = true;
-
-                try{
-                    ygslClient.run();
-                }catch (Exception e){
-                    e.printStackTrace();
-                }
-            }
-
-            if(MesClient.ygslNum == 2){
-                if(ygslClient2==null) {
-                    //初始化TCP连接
-                    ygslClient2 = new YgslClient2();
-//                    //TCP连接状态
-//                    ygsl_tcp_connect_flag2 = false;
-//                    //设置TCP请求状态
-//                    ygsl_connect_request_flag2 = true;
-
-                    try{
-                        ygslClient2.run();
-                    }catch (Exception e){
-                        e.printStackTrace();
-                    }
-                }
-            }
-        } catch (Exception e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        }
-    }
-
-    //启动心跳包程序
-    public static java.util.Timer heartYgslBeatTimer;
-    public static java.util.Timer heartYgslBeatIconTimer;
-    public static boolean iconYgslREDFlag = true;
     public static void startYgslHeartBeatTimer() {
-        if(heartYgslBeatTimer!=null) {
-            heartYgslBeatTimer.cancel();
-        }
-        heartYgslBeatTimer = new java.util.Timer();
-        heartYgslBeatTimer.schedule(new TimerTask() {
-            public void run() {
-                if(ygslClient!=null && ygsl_tcp_connect_flag) {
-                    System.out.println("发送心跳报文ygsl");
-                    YgslUtil.comHeart(ygslClient);
-                }else{
-                    System.out.println("发送心跳报文ygsl离线");
-                    MesClient.ygsl_tcp_connect_flag = false;
-                    MesClient.ygsl_connect_request_flag = true;
-                    MesClient.ygslClient = null;
-                    MesClient.initYgslTcpConnection();
-                }
-
-                if(MesClient.ygslNum == 2){
-                    if(ygslClient2!=null && ygsl_tcp_connect_flag2) {
-                        System.out.println("发送心跳报文ygsl2");
-                        YgslUtil2.comHeart(ygslClient2);
-                    }else{
-                        System.out.println("发送心跳报文ygsl2离线");
-
-                        MesClient.ygsl_tcp_connect_flag2 = false;
-                        MesClient.ygsl_connect_request_flag2 = true;
-                        MesClient.ygslClient2 = null;
-                        MesClient.initYgslTcpConnection();
-                    }
-                }
-            }
-        }, 100,3*1000);
     }
 
     //设置tcp连接状态显示
@@ -366,58 +342,6 @@ public class MesClient extends JFrame {
 
     public static java.util.Timer cjTimer5;
     public static void deviceOnline() {
-        if(cjTimer5!=null) {
-            cjTimer5.cancel();
-        }
-        cjTimer5 = new Timer();
-        cjTimer5.schedule(new TimerTask() {
-            public void run() {
-                try{
-                    if(ygslClient!=null && ygsl_tcp_connect_flag) {
-                        ygslm8.setText("扭力枪:在线");
-                        ygslm8.setBackground(Color.GREEN);
-                        ygslm8.setForeground(Color.WHITE);
-                    }else{
-                        ygslm8.setText("扭力枪:离线");
-                        ygslm8.setBackground(Color.RED);
-                        ygslm8.setForeground(Color.WHITE);
-                    }
-
-//                    if(ygslClient2!=null && ygsl_tcp_connect_flag2) {
-//                        ygslm6.setText("M8扭力枪:在线");
-//                        ygslm6.setBackground(Color.GREEN);
-//                        ygslm6.setForeground(Color.WHITE);
-//                    }else{
-//                        ygslm6.setText("M8扭力枪:离线");
-//                        ygslm6.setBackground(Color.RED);
-//                        ygslm6.setForeground(Color.WHITE);
-//                    }
-
-                    if(work_status == 1 && pz_status == 1){
-                        if(MesClient.cura >= MesClient.maxa){
-                            YgslUtil.disableTool(MesClient.ygslClient);
-                        }else{
-                            YgslUtil.enableTool(MesClient.ygslClient);
-                        }
-                        if(MesClient.ygslNum == 2){
-                            if(MesClient.curb >= MesClient.maxb){
-                                YgslUtil2.disableTool(MesClient.ygslClient2);
-                            }else{
-                                YgslUtil2.enableTool(MesClient.ygslClient2);
-                            }
-                        }
-                    }else{
-                        YgslUtil.disableTool(MesClient.ygslClient);
-                        if(MesClient.ygslNum == 2){
-                            YgslUtil2.disableTool(MesClient.ygslClient2);
-                        }
-                    }
-
-                }catch (Exception e){
-                    e.printStackTrace();
-                }
-            }
-        }, 1000,1000);
     }
 
     public static java.util.Timer cjTimer2;
@@ -487,28 +411,18 @@ public class MesClient extends JFrame {
         MesClient.f_scan_data_bt_1.setEnabled(true);
         MesClient.setMenuStatus("请扫工件码",0);
 
-        atids.clear();
-        btids.clear();
-
-        MesClient.cura = 0;
-        MesClient.curb = 0;
-        MesClient.torquea.setText("");
-        MesClient.torqueb.setText("");
-        MesClient.anglea.setText("");
-        MesClient.angleb.setText("");
-        MesClient.schedulea.setText(MesClient.cura+"/"+MesClient.maxa);
-        MesClient.scheduleb.setText(MesClient.curb+"/"+MesClient.maxb);
+        for (GunPanel panel : gunPanels) {
+            panel.reset();
+            panel.disableTool();
+        }
 
         pzlabel.setVisible(false);
         if(mes_gw.equals("OP290")){
-            pz_status = 0; // 拍照状态
+            pz_status = 0;
         }else{
-            pz_status = 1; // 拍照状态
+            pz_status = 1;
         }
 
-        YgslUtil.disableTool(ygslClient);
-        YgslUtil2.disableTool(ygslClient2);
-
         updateMaterailData();
         shiftUserCheck();
     }
@@ -859,152 +773,11 @@ public class MesClient extends JFrame {
         finish_ng_bt.setEnabled(false);
         indexPanelA.add(finish_ng_bt);
 
-
-        ygslm8 = new JButton("扭力枪:离线");
-        ygslm8.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent e) {
-//                YgslUtil.comStart(ygslClient);
-                MesClient.initYgslTcpConnection();
-
-            }
-        });
-        ygslm8.setFont(new Font("微软雅黑", Font.PLAIN, 16));
-        ygslm8.setBounds(30, 171, 160, 40);
-        ygslm8.setBackground(Color.RED);
-        ygslm8.setForeground(Color.WHITE);
-        indexPanelA.add(ygslm8);
-
-        ygslm6 = new JButton("M5扭力枪:离线");
-        ygslm6.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent e) {
-//                YgslUtil.comStart(ygslClient);
-                MesClient.initYgslTcpConnection();
-//                YgslUtil2.jobIdUpload(MesClient.ygslClient2);
-            }
-        });
-        ygslm6.setFont(new Font("微软雅黑", Font.PLAIN, 16));
-        ygslm6.setBounds(30, 221, 160, 40);
-        ygslm6.setBackground(Color.RED);
-        ygslm6.setForeground(Color.WHITE);
-//        indexPanelA.add(ygslm6);
-
-
-
-        JButton ygslstart = new JButton("comStart");
-        ygslstart.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent e) {
-//                YgslUtil.comStart(ygslClient);
-                YgslUtil.pSet(MesClient.ygslClient);
-            }
-        });
-        ygslstart.setFont(new Font("微软雅黑", Font.PLAIN, 16));
-        ygslstart.setBounds(250, 171, 140, 40);
-//        indexPanelA.add(ygslstart);
-
-        JButton ygslstop = new JButton("comStop");
-        ygslstop.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent e) {
-//                YgslUtil.comStop(ygslClient);
-                YgslUtil.jobIdUpload(MesClient.ygslClient);
-            }
-        });
-        ygslstop.setFont(new Font("微软雅黑", Font.PLAIN, 16));
-        ygslstop.setBounds(150, 221, 140, 40);
-//        indexPanelA.add(ygslstop);
-
-        JButton ygslenable = new JButton("enableTool");
-        ygslenable.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent e) {
-                YgslUtil.enableTool(ygslClient);
-            }
-        });
-        ygslenable.setFont(new Font("微软雅黑", Font.PLAIN, 16));
-        ygslenable.setBounds(50, 271, 140, 40);
-//        indexPanelA.add(ygslenable);
-
-        JButton ygsldisable = new JButton("disableTool");
-        ygsldisable.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent e) {
-                YgslUtil.disableTool(ygslClient);
-            }
-        });
-        ygsldisable.setFont(new Font("微软雅黑", Font.PLAIN, 16));
-        ygsldisable.setBounds(50, 321, 140, 40);
-//        indexPanelA.add(ygsldisable);
-
-        JButton ygsllast = new JButton("lastTightening");
-        ygsllast.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent e) {
-                YgslUtil.lastTighteningResultSubscribe(ygslClient);
-            }
-        });
-        ygsllast.setFont(new Font("微软雅黑", Font.PLAIN, 16));
-        ygsllast.setBounds(690, 171, 140, 40);
-//        indexPanelA.add(ygsllast);
-        
-        JLabel lblNewLabel = new JLabel("M6");
-        lblNewLabel.setHorizontalAlignment(SwingConstants.RIGHT);
-        lblNewLabel.setFont(new Font("微软雅黑", Font.PLAIN, 28));
-        lblNewLabel.setBounds(185, 180, 261, 30);
-        indexPanelA.add(lblNewLabel);
-        
-        schedulea = new JLabel("0/89");
-        schedulea.setHorizontalAlignment(SwingConstants.LEFT);
-        schedulea.setFont(new Font("微软雅黑", Font.PLAIN, 28));
-        schedulea.setBounds(474, 180, 203, 30);
-        indexPanelA.add(schedulea);
-        
-        JLabel lblB = new JLabel("M8");
-        lblB.setHorizontalAlignment(SwingConstants.RIGHT);
-        lblB.setFont(new Font("微软雅黑", Font.PLAIN, 28));
-        lblB.setBounds(185, 303, 261, 30);
-//        indexPanelA.add(lblB);
-        
-        scheduleb = new JLabel("1/1");
-        scheduleb.setHorizontalAlignment(SwingConstants.LEFT);
-        scheduleb.setFont(new Font("微软雅黑", Font.PLAIN, 28));
-        scheduleb.setBounds(474, 303, 203, 30);
-//        indexPanelA.add(scheduleb);
-        
-        JLabel lblNewLabel_2 = new JLabel("扭力:");
-        lblNewLabel_2.setFont(new Font("微软雅黑", Font.PLAIN, 22));
-        lblNewLabel_2.setBounds(311, 230, 67, 30);
-        indexPanelA.add(lblNewLabel_2);
-        
-        JLabel lblNewLabel_2_1 = new JLabel("角度:");
-        lblNewLabel_2_1.setFont(new Font("微软雅黑", Font.PLAIN, 22));
-        lblNewLabel_2_1.setBounds(495, 230, 72, 30);
-        indexPanelA.add(lblNewLabel_2_1);
-        
-        torquea = new JLabel("");
-        torquea.setFont(new Font("微软雅黑", Font.PLAIN, 22));
-        torquea.setBounds(370, 230, 115, 30);
-        indexPanelA.add(torquea);
-        
-        anglea = new JLabel("");
-        anglea.setFont(new Font("微软雅黑", Font.PLAIN, 22));
-        anglea.setBounds(555, 230, 115, 30);
-        indexPanelA.add(anglea);
-        
-        JLabel lblNewLabel_2_3 = new JLabel("扭力:");
-        lblNewLabel_2_3.setFont(new Font("微软雅黑", Font.PLAIN, 22));
-        lblNewLabel_2_3.setBounds(311, 342, 67, 30);
-//        indexPanelA.add(lblNewLabel_2_3);
-        
-        torqueb = new JLabel("");
-        torqueb.setFont(new Font("微软雅黑", Font.PLAIN, 22));
-        torqueb.setBounds(370, 342, 115, 30);
-//        indexPanelA.add(torqueb);
-        
-        JLabel lblNewLabel_2_1_1 = new JLabel("角度:");
-        lblNewLabel_2_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 22));
-        lblNewLabel_2_1_1.setBounds(495, 342, 72, 30);
-//        indexPanelA.add(lblNewLabel_2_1_1);
-        
-        angleb = new JLabel("");
-        angleb.setFont(new Font("微软雅黑", Font.PLAIN, 22));
-        angleb.setBounds(555, 342, 115, 30);
-//        indexPanelA.add(angleb);
+        gunPanelContainer = new JPanel();
+        gunPanelContainer.setLayout(new FlowLayout(FlowLayout.LEFT, 10, 10));
+        gunPanelContainer.setBounds(20, 160, 750, 220);
+        gunPanelContainer.setOpaque(false);
+        indexPanelA.add(gunPanelContainer);
 
         tabbedPane.addTab("工作面板", new ImageIcon(MesClient.class.getResource("/bg/a_side.png")), indexScrollPaneA, null);
         tabbedPane.setEnabledAt(0, true);
@@ -1024,6 +797,14 @@ public class MesClient extends JFrame {
 
 		tabbedPane.addTab("工作记录", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPane, null);
 
+        // 增加工具配置页面
+        JPanel indexConfigPanel = new JPanel();
+        indexConfigPanel.setLayout(null);
+        tabbedPane.addTab("工具配置", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), indexConfigPanel, null);
+
+        initGunConfigPanel(indexConfigPanel);
+
+
 
 		tabbedPane.addChangeListener(new ChangeListener() {
             @Override
@@ -1143,4 +924,296 @@ public class MesClient extends JFrame {
         indexPanelBB.setLayout(null);
         tabbedPane.addTab("绑定物料", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), indexScrollPaneB, null);
     }
+
+    private static JTable configTable;
+    private static JButton addGunButton;
+    private static JButton saveConfigButton;
+
+    public static void initGunConfigPanel(JPanel panel) {
+        JLabel titleLabel = new JLabel("扭力枪配置管理");
+        titleLabel.setFont(new Font("微软雅黑", Font.BOLD, 24));
+        titleLabel.setBounds(350, 20, 300, 40);
+        panel.add(titleLabel);
+
+        String[] columnNames = {"枪号", "名称", "IP地址", "端口", "任务数", "启用", "自动提交"};
+        List<YgslConfig> configs = JdbcUtils.getYgslConfigs();
+        Object[][] data = new Object[configs.size()][7];
+        for (int i = 0; i < configs.size(); i++) {
+            YgslConfig config = configs.get(i);
+            data[i][0] = config.getGunIndex();
+            data[i][1] = config.getGunName();
+            data[i][2] = config.getIpAddress();
+            data[i][3] = config.getPort();
+            data[i][4] = config.getTaskCount();
+            data[i][5] = config.getEnabled() == 1 ? "是" : "否";
+            data[i][6] = config.getAutoSubmit() == 1 ? "是" : "否";
+        }
+
+        configTable = new JTable(data, columnNames);
+        configTable.setRowHeight(35);
+        configTable.setFont(new Font("微软雅黑", Font.PLAIN, 14));
+        configTable.getTableHeader().setFont(new Font("微软雅黑", Font.BOLD, 14));
+
+        JScrollPane scrollPane = new JScrollPane(configTable);
+        scrollPane.setBounds(50, 70, 900, 400);
+        panel.add(scrollPane);
+
+        addGunButton = new JButton("添加枪");
+        addGunButton.setFont(new Font("微软雅黑", Font.PLAIN, 16));
+        addGunButton.setBounds(150, 490, 120, 40);
+        addGunButton.addActionListener(new ActionListener() {
+            @Override
+            public void actionPerformed(ActionEvent e) {
+                addNewGun(panel);
+            }
+        });
+        panel.add(addGunButton);
+
+        saveConfigButton = new JButton("保存配置");
+        saveConfigButton.setFont(new Font("微软雅黑", Font.PLAIN, 16));
+        saveConfigButton.setBounds(300, 490, 120, 40);
+        saveConfigButton.addActionListener(new ActionListener() {
+            @Override
+            public void actionPerformed(ActionEvent e) {
+                saveGunConfigs();
+            }
+        });
+        panel.add(saveConfigButton);
+
+        JButton deleteButton = new JButton("删除选中");
+        deleteButton.setFont(new Font("微软雅黑", Font.PLAIN, 16));
+        deleteButton.setBounds(450, 490, 120, 40);
+        deleteButton.addActionListener(new ActionListener() {
+            @Override
+            public void actionPerformed(ActionEvent e) {
+                int selectedRow = configTable.getSelectedRow();
+                if (selectedRow >= 0) {
+                    int confirm = JOptionPane.showConfirmDialog(mesClientFrame, "确定要删除选中的配置吗?", "确认删除", JOptionPane.YES_NO_OPTION);
+                    if (confirm == JOptionPane.YES_OPTION) {
+                        List<YgslConfig> allConfigs = JdbcUtils.getYgslConfigs();
+                        if (selectedRow < allConfigs.size()) {
+                            JdbcUtils.deleteYgslConfig(allConfigs.get(selectedRow).getId());
+                            reloadGunConfigs(panel);
+                        }
+                    }
+                } else {
+                    JOptionPane.showMessageDialog(mesClientFrame, "请先选中一行", "提示", JOptionPane.INFORMATION_MESSAGE);
+                }
+            }
+        });
+        panel.add(deleteButton);
+
+        configTable.addMouseListener(new MouseAdapter() {
+            public void mouseDoubleClick(MouseEvent e) {
+                int row = configTable.getSelectedRow();
+                if (row >= 0) {
+                    editGunConfig(row, panel);
+                }
+            }
+        });
+    }
+
+    private static void editGunConfig(int row, JPanel panel) {
+        List<YgslConfig> configs = JdbcUtils.getYgslConfigs();
+        if (row >= configs.size()) return;
+
+        YgslConfig config = configs.get(row);
+
+        JDialog dialog = new JDialog(mesClientFrame, "编辑扭力枪", true);
+        dialog.setSize(400, 400);
+        dialog.setLocationRelativeTo(mesClientFrame);
+        dialog.setLayout(null);
+
+        JLabel idLabel = new JLabel("ID: " + config.getId());
+        idLabel.setBounds(50, 20, 300, 30);
+        dialog.add(idLabel);
+
+        JLabel nameLabel = new JLabel("枪号:");
+        nameLabel.setBounds(50, 60, 80, 30);
+        dialog.add(nameLabel);
+        JTextField nameField = new JTextField(String.valueOf(config.getGunIndex()));
+        nameField.setBounds(140, 60, 180, 30);
+        dialog.add(nameField);
+
+        JLabel gunNameLabel = new JLabel("名称:");
+        gunNameLabel.setBounds(50, 100, 80, 30);
+        dialog.add(gunNameLabel);
+        JTextField gunNameField = new JTextField(config.getGunName());
+        gunNameField.setBounds(140, 100, 180, 30);
+        dialog.add(gunNameField);
+
+        JLabel ipLabel = new JLabel("IP地址:");
+        ipLabel.setBounds(50, 140, 80, 30);
+        dialog.add(ipLabel);
+        JTextField ipField = new JTextField(config.getIpAddress());
+        ipField.setBounds(140, 140, 180, 30);
+        dialog.add(ipField);
+
+        JLabel portLabel = new JLabel("端口:");
+        portLabel.setBounds(50, 180, 80, 30);
+        dialog.add(portLabel);
+        JTextField portField = new JTextField(String.valueOf(config.getPort()));
+        portField.setBounds(140, 180, 180, 30);
+        dialog.add(portField);
+
+        JLabel taskLabel = new JLabel("任务数:");
+        taskLabel.setBounds(50, 220, 80, 30);
+        dialog.add(taskLabel);
+        JTextField taskField = new JTextField(String.valueOf(config.getTaskCount()));
+        taskField.setBounds(140, 220, 180, 30);
+        dialog.add(taskField);
+
+        JLabel enabledLabel = new JLabel("启用:");
+        enabledLabel.setBounds(50, 260, 80, 30);
+        dialog.add(enabledLabel);
+        JComboBox<String> enabledBox = new JComboBox<>(new String[]{"否", "是"});
+        enabledBox.setBounds(140, 260, 180, 30);
+        enabledBox.setSelectedIndex(config.getEnabled() == 1 ? 1 : 0);
+        dialog.add(enabledBox);
+
+        JButton okButton = new JButton("保存");
+        okButton.setBounds(100, 310, 80, 30);
+        okButton.addActionListener(new ActionListener() {
+            @Override
+            public void actionPerformed(ActionEvent e) {
+                try {
+                    config.setGunIndex(Integer.parseInt(nameField.getText()));
+                    config.setGunName(gunNameField.getText());
+                    config.setIpAddress(ipField.getText());
+                    config.setPort(Integer.parseInt(portField.getText()));
+                    config.setTaskCount(Integer.parseInt(taskField.getText()));
+                    config.setEnabled(enabledBox.getSelectedIndex() == 1 ? 1 : 0);
+
+                    JdbcUtils.updateYgslConfig(config);
+                    dialog.dispose();
+                    reloadGunConfigs(panel);
+                } catch (Exception ex) {
+                    JOptionPane.showMessageDialog(dialog, "输入格式错误,请检查", "错误", JOptionPane.ERROR_MESSAGE);
+                }
+            }
+        });
+        dialog.add(okButton);
+
+        JButton cancelButton = new JButton("取消");
+        cancelButton.setBounds(200, 310, 80, 30);
+        cancelButton.addActionListener(new ActionListener() {
+            @Override
+            public void actionPerformed(ActionEvent e) {
+                dialog.dispose();
+            }
+        });
+        dialog.add(cancelButton);
+
+        dialog.setVisible(true);
+    }
+
+    private static void addNewGun(JPanel panel) {
+        JDialog dialog = new JDialog(mesClientFrame, "添加扭力枪", true);
+        dialog.setSize(400, 350);
+        dialog.setLocationRelativeTo(mesClientFrame);
+        dialog.setLayout(null);
+
+        JLabel nameLabel = new JLabel("枪号:");
+        nameLabel.setBounds(50, 30, 80, 30);
+        dialog.add(nameLabel);
+        JTextField nameField = new JTextField();
+        nameField.setBounds(140, 30, 180, 30);
+        dialog.add(nameField);
+
+        JLabel gunNameLabel = new JLabel("名称:");
+        gunNameLabel.setBounds(50, 80, 80, 30);
+        dialog.add(gunNameLabel);
+        JTextField gunNameField = new JTextField("M5");
+        gunNameField.setBounds(140, 80, 180, 30);
+        dialog.add(gunNameField);
+
+        JLabel ipLabel = new JLabel("IP地址:");
+        ipLabel.setBounds(50, 130, 80, 30);
+        dialog.add(ipLabel);
+        JTextField ipField = new JTextField("192.168.5.100");
+        ipField.setBounds(140, 130, 180, 30);
+        dialog.add(ipField);
+
+        JLabel portLabel = new JLabel("端口:");
+        portLabel.setBounds(50, 180, 80, 30);
+        dialog.add(portLabel);
+        JTextField portField = new JTextField("4545");
+        portField.setBounds(140, 180, 180, 30);
+        dialog.add(portField);
+
+        JLabel taskLabel = new JLabel("任务数:");
+        taskLabel.setBounds(50, 230, 80, 30);
+        dialog.add(taskLabel);
+        JTextField taskField = new JTextField("12");
+        taskField.setBounds(140, 230, 180, 30);
+        dialog.add(taskField);
+
+        JButton okButton = new JButton("确定");
+        okButton.setBounds(100, 280, 80, 30);
+        okButton.addActionListener(new ActionListener() {
+            @Override
+            public void actionPerformed(ActionEvent e) {
+                try {
+                    int gunIndex = Integer.parseInt(nameField.getText());
+                    String gunName = gunNameField.getText();
+                    String ip = ipField.getText();
+                    int port = Integer.parseInt(portField.getText());
+                    int taskCount = Integer.parseInt(taskField.getText());
+
+                    YgslConfig config = new YgslConfig(gunIndex, gunName, ip, port, taskCount);
+                    JdbcUtils.insertYgslConfig(config);
+
+                    dialog.dispose();
+                    reloadGunConfigs(panel);
+                } catch (Exception ex) {
+                    JOptionPane.showMessageDialog(dialog, "输入格式错误,请检查", "错误", JOptionPane.ERROR_MESSAGE);
+                }
+            }
+        });
+        dialog.add(okButton);
+
+        JButton cancelButton = new JButton("取消");
+        cancelButton.setBounds(200, 280, 80, 30);
+        cancelButton.addActionListener(new ActionListener() {
+            @Override
+            public void actionPerformed(ActionEvent e) {
+                dialog.dispose();
+            }
+        });
+        dialog.add(cancelButton);
+
+        dialog.setVisible(true);
+    }
+
+    private static void saveGunConfigs() {
+        try {
+            List<YgslConfig> configs = JdbcUtils.getYgslConfigs();
+            int rowCount = configTable.getRowCount();
+
+            for (int i = 0; i < rowCount && i < configs.size(); i++) {
+                YgslConfig config = configs.get(i);
+                config.setGunIndex((Integer) configTable.getValueAt(i, 0));
+                config.setGunName((String) configTable.getValueAt(i, 1));
+                config.setIpAddress((String) configTable.getValueAt(i, 2));
+                config.setPort((Integer) configTable.getValueAt(i, 3));
+                config.setTaskCount((Integer) configTable.getValueAt(i, 4));
+                config.setEnabled(((String) configTable.getValueAt(i, 5)).equals("是") ? 1 : 0);
+                config.setAutoSubmit(((String) configTable.getValueAt(i, 6)).equals("是") ? 1 : 0);
+
+                JdbcUtils.updateYgslConfig(config);
+            }
+
+            JOptionPane.showMessageDialog(mesClientFrame, "配置保存成功!重启后生效", "提示", JOptionPane.INFORMATION_MESSAGE);
+        } catch (Exception e) {
+            e.printStackTrace();
+            JOptionPane.showMessageDialog(mesClientFrame, "保存失败:" + e.getMessage(), "错误", JOptionPane.ERROR_MESSAGE);
+        }
+    }
+
+    private static void reloadGunConfigs(JPanel panel) {
+        panel.removeAll();
+        initGunConfigPanel(panel);
+        panel.revalidate();
+        panel.repaint();
+    }
 }

+ 4 - 6
src/com/mes/ui/MesRevice.java

@@ -1,6 +1,7 @@
 package com.mes.ui;
 
 import com.mes.netty.ProtocolParam;
+import com.mes.component.GunPanel;
 import com.mes.component.MyDialog;
 import com.mes.util.ErrorMsg;
 
@@ -56,13 +57,10 @@ public class MesRevice {
                 MesClient.work_status = 1;
                 MesClient.f_scan_data_bt_1.setEnabled(false);
 
-                YgslUtil.pSet(MesClient.ygslClient);
-                if(MesClient.ygslNum == 2){
-                    YgslUtil2.pSet(MesClient.ygslClient2);
+                for (GunPanel panel : MesClient.gunPanels) {
+                    panel.pSet();
+                    panel.startJob();
                 }
-
-                MesClient.btids.clear();
-                MesClient.atids.clear();
             }
         }catch (Exception e){
             e.printStackTrace();

+ 0 - 181
src/com/mes/ui/YgslUtil2.java

@@ -1,181 +0,0 @@
-package com.mes.ui;
-
-import com.mes.ygsl.YgslClient;
-import com.mes.ygsl.YgslClient2;
-import io.netty.buffer.ByteBuf;
-import io.netty.buffer.Unpooled;
-
-public class YgslUtil2 {
-
-    // 心跳
-    public static Boolean comHeart(YgslClient2 ygslClient){
-        try{
-            String synr_str = "002099990010        ";
-            ygslClient.future.channel().writeAndFlush(getSendByteBuf(stringToHex(synr_str)));
-            return true;
-        }catch (Exception e){
-            e.printStackTrace();
-            return false;
-        }
-    }
-
-    // 通讯启动  对应回复 0002 通讯启动确认
-    public static Boolean comStart(YgslClient2 ygslClient){
-        try{
-            String synr_str = "002000010050        ";
-            ygslClient.future.channel().writeAndFlush(getSendByteBuf(stringToHex(synr_str)));
-            return true;
-        }catch (Exception e){
-            e.printStackTrace();
-            return false;
-        }
-    }
-
-    // 通讯停止 对应回复 0005 命令被接受   0004 命令错误
-    public static Boolean comStop(YgslClient2 ygslClient){
-        try{
-            String synr_str = "002000030050        ";
-            ygslClient.future.channel().writeAndFlush(getSendByteBuf(stringToHex(synr_str)));
-            return true;
-        }catch (Exception e){
-            e.printStackTrace();
-            return false;
-        }
-    }
-
-    // 使能工具 回复 0004/0005
-    public static Boolean enableTool(YgslClient2 ygslClient){
-        try{
-            String synr_str = "00200043000         ";
-            ygslClient.future.channel().writeAndFlush(getSendByteBuf(stringToHex(synr_str)));
-            return true;
-        }catch (Exception e){
-            e.printStackTrace();
-            return false;
-        }
-    }
-
-    // 禁用工具 回复 0004/0005
-    public static Boolean disableTool(YgslClient2 ygslClient){
-        try{
-            String synr_str = "00200042000         ";
-            ygslClient.future.channel().writeAndFlush(getSendByteBuf(stringToHex(synr_str)));
-            return true;
-        }catch (Exception e){
-            e.printStackTrace();
-            return false;
-        }
-    }
-
-    // 设置setId  对应回复 0010 pset
-    public static Boolean pSet(YgslClient2 ygslClient){
-        try{
-            String synr_str = "002000100010        ";
-            System.out.println("pSet2:"+synr_str);
-            ygslClient.future.channel().writeAndFlush(getSendByteBuf(stringToHex(synr_str)));
-            return true;
-        }catch (Exception e){
-            e.printStackTrace();
-            return false;
-        }
-    }
-
-    // 选择 setId   0018 pset
-    public static Boolean selectSet(YgslClient2 ygslClient){
-        try{
-            String synr_str = "002300180010        002";
-            System.out.println("selectSet2:"+synr_str);
-            ygslClient.future.channel().writeAndFlush(getSendByteBuf(stringToHex(synr_str)));
-            return true;
-        }catch (Exception e){
-            e.printStackTrace();
-            return false;
-        }
-    }
-
-    //上次拧紧结果数据订阅   0061 拧紧数据上报
-    public static Boolean lastTighteningResultSubscribe(YgslClient2 ygslClient){
-        try{
-            String synr_str = "002000600010        ";
-            System.out.println(stringToHex(synr_str));
-            ygslClient.future.channel().writeAndFlush(getSendByteBuf(stringToHex(synr_str)));
-            return true;
-        }catch (Exception e){
-            e.printStackTrace();
-            return false;
-        }
-    }
-
-    // 接收到订阅拧紧数据后回复
-    public static Boolean lastTighteningResultDataAcknowledge(YgslClient2 ygslClient){
-        try{
-            String synr_str = "0020006200010       ";
-            ygslClient.future.channel().writeAndFlush(getSendByteBuf(stringToHex(synr_str)));
-            return true;
-        }catch (Exception e){
-            e.printStackTrace();
-            return false;
-        }
-    }
-
-    public static Boolean jobIdUpload(YgslClient2 ygslClient){
-        try{
-            String synr_str = "002000300010        ";
-            System.out.println("jobIdUpload2:"+synr_str);
-            ygslClient.future.channel().writeAndFlush(getSendByteBuf(stringToHex(synr_str)));
-            return true;
-        }catch (Exception e){
-            e.printStackTrace();
-            return false;
-        }
-    }
-
-    public static Boolean selectJob(YgslClient2 ygslClient){
-        try{
-            String synr_str = "002000380010        02";
-            System.out.println("selectJob2:"+synr_str);
-            ygslClient.future.channel().writeAndFlush(getSendByteBuf(stringToHex(synr_str)));
-            return true;
-        }catch (Exception e){
-            e.printStackTrace();
-            return false;
-        }
-    }
-
-    public static Boolean restartJob(YgslClient2 ygslClient){
-        try{
-            String synr_str = "002000390010        01";
-            System.out.println("restartJob2:"+synr_str);
-            ygslClient.future.channel().writeAndFlush(getSendByteBuf(stringToHex(synr_str)));
-            return true;
-        }catch (Exception e){
-            e.printStackTrace();
-            return false;
-        }
-    }
-
-    public static String stringToHex(String input) {
-        StringBuilder hexString = new StringBuilder();
-
-        for (char ch : input.toCharArray()) {
-            hexString.append(Integer.toHexString((int) ch));
-        }
-
-        return hexString.toString();
-    }
-
-    /**
-     * 将字符串消息转为ByteBuf
-     * 16进制字符串转二进制
-     * @param hex 字符串消息
-     */
-    public static ByteBuf getSendByteBuf(String hex) {
-        hex = hex + "00";
-        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);
-    }
-}

+ 153 - 0
src/com/mes/util/JdbcUtils.java

@@ -1,6 +1,7 @@
 package com.mes.util;
 
 import com.mes.ui.YgslResp;
+import com.mes.ygsl.YgslConfig;
 
 import java.sql.*;
 import java.util.ArrayList;
@@ -18,6 +19,7 @@ public class JdbcUtils {
             System.out.println("连接到SQLite数据库成功!");
             create_bw_record();//初始化结构表
             create_bw_tightening();//初始化
+            create_ygsl_config();//初始化扭力枪配置表
         } catch (Exception e) {
             // TODO Auto-generated catch block
         	close();//关闭数据库连接
@@ -241,6 +243,157 @@ public class JdbcUtils {
 		return prods;
 	}
 
+	public static void create_ygsl_config() throws SQLException {
+		Statement statement = conn.createStatement();
+		String sql = "CREATE TABLE if not exists ygsl_config("
+				+ "id INTEGER PRIMARY KEY AUTOINCREMENT,"
+				+ "gun_index INTEGER,"
+				+ "gun_name VARCHAR(20),"
+				+ "ip_address VARCHAR(50),"
+				+ "port INTEGER,"
+				+ "task_count INTEGER,"
+				+ "enabled INTEGER DEFAULT 1,"
+				+ "auto_submit INTEGER DEFAULT 1,"
+				+ "create_time DATETIME,"
+				+ "update_time DATETIME)";
+		statement.executeUpdate(sql);
+		System.out.println("扭力枪配置表创建成功!");
+
+		ResultSet rs = statement.executeQuery("SELECT count(*) FROM ygsl_config");
+		int count = 0;
+		if (rs.next()) {
+			count = rs.getInt(1);
+		}
+		statement.close();
+
+		if (count == 0) {
+			initDefaultYgslConfig();
+		}
+	}
+
+	private static void initDefaultYgslConfig() throws SQLException {
+		Statement statement = conn.createStatement();
+		String now = DateLocalUtils.getCurrentTime();
+		statement.executeUpdate("INSERT INTO ygsl_config (gun_index, gun_name, ip_address, port, task_count, enabled, auto_submit, create_time, update_time) VALUES "
+				+ "(1, 'M5', '192.168.5.100', 4545, 12, 1, 1, '" + now + "', '" + now + "')");
+		statement.executeUpdate("INSERT INTO ygsl_config (gun_index, gun_name, ip_address, port, task_count, enabled, auto_submit, create_time, update_time) VALUES "
+				+ "(2, 'M8', '192.168.5.101', 4545, 1, 1, 1, '" + now + "', '" + now + "')");
+		System.out.println("默认扭力枪配置初始化完成!");
+		statement.close();
+	}
+
+	public static List<YgslConfig> getYgslConfigs() {
+		List<YgslConfig> configs = new ArrayList<>();
+		try {
+			if (conn == null || conn.isClosed()) {
+				openConnection();
+			}
+			Statement statement = conn.createStatement();
+			ResultSet rs = statement.executeQuery("SELECT id, gun_index, gun_name, ip_address, port, task_count, enabled, auto_submit FROM ygsl_config ORDER BY gun_index");
+			while (rs.next()) {
+				YgslConfig config = new YgslConfig();
+				config.setId(rs.getInt("id"));
+				config.setGunIndex(rs.getInt("gun_index"));
+				config.setGunName(rs.getString("gun_name"));
+				config.setIpAddress(rs.getString("ip_address"));
+				config.setPort(rs.getInt("port"));
+				config.setTaskCount(rs.getInt("task_count"));
+				config.setEnabled(rs.getInt("enabled"));
+				config.setAutoSubmit(rs.getInt("auto_submit"));
+				configs.add(config);
+			}
+			statement.close();
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		return configs;
+	}
+
+	public static List<YgslConfig> getEnabledYgslConfigs() {
+		List<YgslConfig> configs = new ArrayList<>();
+		try {
+			if (conn == null || conn.isClosed()) {
+				openConnection();
+			}
+			Statement statement = conn.createStatement();
+			ResultSet rs = statement.executeQuery("SELECT id, gun_index, gun_name, ip_address, port, task_count, enabled, auto_submit FROM ygsl_config WHERE enabled = 1 ORDER BY gun_index");
+			while (rs.next()) {
+				YgslConfig config = new YgslConfig();
+				config.setId(rs.getInt("id"));
+				config.setGunIndex(rs.getInt("gun_index"));
+				config.setGunName(rs.getString("gun_name"));
+				config.setIpAddress(rs.getString("ip_address"));
+				config.setPort(rs.getInt("port"));
+				config.setTaskCount(rs.getInt("task_count"));
+				config.setEnabled(rs.getInt("enabled"));
+				config.setAutoSubmit(rs.getInt("auto_submit"));
+				configs.add(config);
+			}
+			statement.close();
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		return configs;
+	}
+
+	public static boolean updateYgslConfig(YgslConfig config) {
+		boolean ret = false;
+		try {
+			if (conn == null || conn.isClosed()) {
+				openConnection();
+			}
+			String now = DateLocalUtils.getCurrentTime();
+			Statement statement = conn.createStatement();
+			statement.executeUpdate("UPDATE ygsl_config SET gun_name = '" + config.getGunName() + "', "
+					+ "ip_address = '" + config.getIpAddress() + "', "
+					+ "port = " + config.getPort() + ", "
+					+ "task_count = " + config.getTaskCount() + ", "
+					+ "enabled = " + config.getEnabled() + ", "
+					+ "auto_submit = " + config.getAutoSubmit() + ", "
+					+ "update_time = '" + now + "' "
+					+ "WHERE id = " + config.getId());
+			statement.close();
+			ret = true;
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		return ret;
+	}
+
+	public static boolean insertYgslConfig(YgslConfig config) {
+		boolean ret = false;
+		try {
+			if (conn == null || conn.isClosed()) {
+				openConnection();
+			}
+			String now = DateLocalUtils.getCurrentTime();
+			Statement statement = conn.createStatement();
+			statement.executeUpdate("INSERT INTO ygsl_config (gun_index, gun_name, ip_address, port, task_count, enabled, auto_submit, create_time, update_time) VALUES ("
+					+ config.getGunIndex() + ", '" + config.getGunName() + "', '" + config.getIpAddress() + "', " + config.getPort() + ", " + config.getTaskCount() + ", " + config.getEnabled() + ", " + config.getAutoSubmit() + ", '" + now + "', '" + now + "')");
+			statement.close();
+			ret = true;
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		return ret;
+	}
+
+	public static boolean deleteYgslConfig(int id) {
+		boolean ret = false;
+		try {
+			if (conn == null || conn.isClosed()) {
+				openConnection();
+			}
+			Statement statement = conn.createStatement();
+			statement.executeUpdate("DELETE FROM ygsl_config WHERE id = " + id);
+			statement.close();
+			ret = true;
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		return ret;
+	}
+
 }
  
 

+ 63 - 40
src/com/mes/ygsl/YgslClient.java

@@ -1,7 +1,6 @@
 package com.mes.ygsl;
 
-import com.mes.netty.XDecoder;
-import com.mes.ui.MesClient;
+import com.mes.component.GunPanel;
 import com.mes.ui.YgslUtil;
 import io.netty.bootstrap.Bootstrap;
 import io.netty.buffer.ByteBuf;
@@ -14,65 +13,89 @@ import io.netty.handler.codec.DelimiterBasedFrameDecoder;
 import io.netty.handler.codec.string.StringEncoder;
 import io.netty.util.CharsetUtil;
 
-import java.util.concurrent.TimeUnit;
-
 public class YgslClient {
-    public SocketChannel socketChannel;
-    public static ChannelFuture future;
-    public static String serverIp = "192.168.5.100"; // M6
+    private SocketChannel socketChannel;
+    public ChannelFuture future;
+    private String serverIp;
+    private int serverPort;
+    private int gunIndex;
+    private GunPanel gunPanel;
+    private EventLoopGroup group;
+    private boolean connected = false;
+
+    public YgslClient(String ip, int port, int gunIndex) {
+        this.serverIp = ip;
+        this.serverPort = port;
+        this.gunIndex = gunIndex;
+    }
+
+    public void setGunPanel(GunPanel gunPanel) {
+        this.gunPanel = gunPanel;
+    }
 
-    public  void run(){
-        //配置线程组
-        EventLoopGroup group = new NioEventLoopGroup();
-        //创建服务启动器
+    public void run() {
+        group = new NioEventLoopGroup();
         Bootstrap bootstrap = new Bootstrap();
 
-        //配置参数
         bootstrap.group(group)
                 .channel(NioSocketChannel.class)
-                .option(ChannelOption.TCP_NODELAY,true)
+                .option(ChannelOption.TCP_NODELAY, true)
                 .handler(new ChannelInitializer<SocketChannel>() {
                     protected void initChannel(SocketChannel socketChannel) throws Exception {
-                        ByteBuf delimiter = Unpooled.copiedBuffer(new byte[]{0x00}); // 空位作为分隔符
+                        ByteBuf delimiter = Unpooled.copiedBuffer(new byte[]{0x00});
                         socketChannel.pipeline()
                                 .addLast(new DelimiterBasedFrameDecoder(1024, delimiter))
                                 .addLast("encoder", new StringEncoder(CharsetUtil.UTF_8))
-                                .addLast(new YgslClientHandler());
+                                .addLast(new YgslClientHandler(gunIndex, YgslClient.this));
                     }
                 })
-                .remoteAddress(serverIp,4545);
+                .remoteAddress(serverIp, serverPort);
 
-        //连接
         future = bootstrap.connect();
-        System.out.println("Ygsl客户端正在连接服务端...");
-        //客户端断线重连逻辑
+        System.out.println("扭力枪" + gunIndex + "客户端正在连接: " + serverIp + ":" + serverPort);
+
         future.addListener((ChannelFutureListener) future1 -> {
             if (future1.isSuccess()) {
-                //tcp连接成功
-                MesClient.ygsl_tcp_connect_flag = true;
-                //设置TCP请求状态
-                MesClient.ygsl_connect_request_flag = false;
-                System.out.println("连接Ygsl服务端成功");
-                YgslUtil.comStart(MesClient.ygslClient);
+                connected = true;
+                System.out.println("连接扭力枪" + gunIndex + "服务端成功: " + serverIp + ":" + serverPort);
+                if (gunPanel != null) {
+                    gunPanel.setOnline(true);
+                }
+                YgslUtil.comStart(this);
             } else {
-                //tcp连接失败
-                MesClient.ygslClient = null;
-                MesClient.ygsl_tcp_connect_flag = false;
-                MesClient.ygsl_connect_request_flag = true;
-                System.out.println("连接Ygsl失败,进行断线重连");
-
-                // 延迟重连
-                new Thread(() -> {
-                    try {
-                        Thread.sleep(100); // 延迟0.5秒
-                        MesClient.initYgslTcpConnection();
-                    } catch (InterruptedException e) {
-                        Thread.currentThread().interrupt();
-                    }
-                }).start();
+                connected = false;
+                System.out.println("连接扭力枪" + gunIndex + "失败: " + serverIp + ":" + serverPort);
+                if (gunPanel != null) {
+                    gunPanel.setOnline(false);
+                }
             }
         });
         socketChannel = (SocketChannel) future.channel();
+    }
+
+    public void close() {
+        try {
+            connected = false;
+            if (future != null) {
+                future.channel().close();
+            }
+            if (group != null) {
+                group.shutdownGracefully();
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    public boolean isConnected() {
+        return connected;
+    }
+
+    public int getGunIndex() {
+        return gunIndex;
+    }
 
+    public GunPanel getGunPanel() {
+        return gunPanel;
     }
 }

+ 0 - 76
src/com/mes/ygsl/YgslClient2.java

@@ -1,76 +0,0 @@
-package com.mes.ygsl;
-
-import com.mes.ui.MesClient;
-import com.mes.ui.YgslUtil;
-import com.mes.ui.YgslUtil2;
-import io.netty.bootstrap.Bootstrap;
-import io.netty.buffer.ByteBuf;
-import io.netty.buffer.Unpooled;
-import io.netty.channel.*;
-import io.netty.channel.nio.NioEventLoopGroup;
-import io.netty.channel.socket.SocketChannel;
-import io.netty.channel.socket.nio.NioSocketChannel;
-import io.netty.handler.codec.DelimiterBasedFrameDecoder;
-import io.netty.handler.codec.string.StringEncoder;
-import io.netty.util.CharsetUtil;
-
-public class YgslClient2 {
-    public SocketChannel socketChannel;
-    public static ChannelFuture future;
-    public static String serverIp = "192.168.5.101"; // M8
-
-    public  void run(){
-        //配置线程组
-        EventLoopGroup group = new NioEventLoopGroup();
-        //创建服务启动器
-        Bootstrap bootstrap = new Bootstrap();
-
-        //配置参数
-        bootstrap.group(group)
-                .channel(NioSocketChannel.class)
-                .option(ChannelOption.TCP_NODELAY,true)
-                .handler(new ChannelInitializer<SocketChannel>() {
-                    protected void initChannel(SocketChannel socketChannel) throws Exception {
-                        ByteBuf delimiter = Unpooled.copiedBuffer(new byte[]{0x00}); // 空位作为分隔符
-                        socketChannel.pipeline()
-                                .addLast(new DelimiterBasedFrameDecoder(1024, delimiter))
-                                .addLast("encoder", new StringEncoder(CharsetUtil.UTF_8))
-                                .addLast(new YgslClientHandler2());
-                    }
-                })
-                .remoteAddress(serverIp,4545);
-
-        //连接
-        future = bootstrap.connect();
-        System.out.println("Ygsl2客户端正在连接服务端"+serverIp+"...");
-        //客户端断线重连逻辑
-        future.addListener((ChannelFutureListener) future1 -> {
-            if (future1.isSuccess()) {
-                //tcp连接成功
-                MesClient.ygsl_tcp_connect_flag2 = true;
-                //设置TCP请求状态
-                MesClient.ygsl_connect_request_flag2 = false;
-                System.out.println("连接Ygsl2服务端成功");
-                YgslUtil2.comStart(MesClient.ygslClient2);
-            } else {
-                //tcp连接失败
-                MesClient.ygsl_tcp_connect_flag2 = false;
-                MesClient.ygsl_connect_request_flag2 = true;
-                System.out.println("连接Ygsl2失败,进行断线重连");
-//                future1.channel().eventLoop().schedule(() -> run(), 1, TimeUnit.SECONDS);
-
-                // 延迟重连
-                new Thread(() -> {
-                    try {
-                        Thread.sleep(100); // 延迟0.5秒
-                        MesClient.initYgslTcpConnection();
-                    } catch (InterruptedException e) {
-                        Thread.currentThread().interrupt();
-                    }
-                }).start();
-            }
-        });
-        socketChannel = (SocketChannel) future.channel();
-
-    }
-}

+ 39 - 184
src/com/mes/ygsl/YgslClientHandler.java

@@ -1,21 +1,11 @@
 package com.mes.ygsl;
 
-import com.mes.netty.MesMsgUtils;
-import com.mes.netty.ProtocolParam;
-import com.mes.ui.DataUtil;
-import com.mes.ui.MesClient;
-import com.mes.ui.MesRevice;
 import com.mes.ui.YgslUtil;
-import com.mes.util.JdbcUtils;
 import io.netty.buffer.ByteBuf;
-import io.netty.buffer.ByteBufUtil;
 import io.netty.channel.Channel;
 import io.netty.channel.ChannelHandlerContext;
 import io.netty.channel.ChannelInboundHandlerAdapter;
 
-import javax.swing.*;
-import java.awt.*;
-import java.nio.ByteBuffer;
 import java.nio.charset.StandardCharsets;
 import java.text.SimpleDateFormat;
 import java.util.Date;
@@ -23,222 +13,87 @@ import java.util.Date;
 public class YgslClientHandler extends ChannelInboundHandlerAdapter {
 
     private final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-    public static byte[] responseByte;
+    private final int gunIndex;
+    private YgslClient gunClient;
+
+    public YgslClientHandler(int gunIndex, YgslClient gunClient) {
+        this.gunIndex = gunIndex;
+        this.gunClient = gunClient;
+    }
 
     @Override
     public void channelActive(ChannelHandlerContext ctx) throws Exception {
-        System.out.println("mes connecting:" + sdf.format(new Date()));
+        System.out.println("扭力枪" + gunIndex + "连接中:" + sdf.format(new Date()));
     }
 
     @Override
     public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
         Channel channel = ctx.channel();
-        System.err.println("close ygsl tcp, ip:" + channel.remoteAddress());
-        // 关闭通道
+        System.err.println("关闭扭力枪" + gunIndex + " TCP连接, IP:" + channel.remoteAddress());
         channel.close();
 
-        //初始化TCP连接
-        MesClient.ygslClient = null;
-        //TCP连接状态
-        MesClient.ygsl_tcp_connect_flag = false;
-        //设置TCP请求状态
-        MesClient.ygsl_connect_request_flag = true;
+        if (gunClient != null && gunClient.getGunPanel() != null) {
+            gunClient.getGunPanel().setOnline(false);
+        }
     }
 
     @Override
     public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
-        try{
-//            System.out.println("msg1111111:"+msg);
+        try {
             if (msg instanceof ByteBuf) {
                 ByteBuf buf = (ByteBuf) msg;
-                // 你的处理逻辑
                 String content = buf.toString(StandardCharsets.UTF_8);
-                System.out.println("msg:"+content);
-                System.out.println("msg-size:"+content.length());
+                System.out.println("扭力枪" + gunIndex + " 收到消息:" + content);
 
                 String mid = YgslParam.getMid(content);
-                System.out.println("MID:"+mid);
-                switch (mid){
+                System.out.println("MID:" + mid);
+
+                switch (mid) {
                     case "0002":
-                        YgslUtil.lastTighteningResultSubscribe(MesClient.ygslClient);
-//                        YgslUtil.pSet(MesClient.ygslClient);
+                        YgslUtil.lastTighteningResultSubscribe(gunClient);
                         break;
                     case "0011":
-                        YgslUtil.selectSet(MesClient.ygslClient);
+                        YgslUtil.selectSet(gunClient);
                         break;
                     case "0031":
-                        YgslUtil.selectJob(MesClient.ygslClient);
-//                        YgslUtil.restartJob(MesClient.ygslClient);
+                        YgslUtil.selectJob(gunClient);
                         break;
-                    case "0004": // 错误信息
-                        System.out.println("MID:"+YgslParam.getReplyMid(content)+";ErrorCode:"+YgslParam.getErrCode(content));
+                    case "0004":
+                        System.out.println("错误信息 - MID:" + YgslParam.getReplyMid(content) + ", ErrorCode:" + YgslParam.getErrCode(content));
                         break;
-                    case "0005": // 命令被接受
-                        System.out.println("命令被接受:"+YgslParam.getReplyMid(content));
+                    case "0005":
+                        System.out.println("命令被接受 - MID:" + YgslParam.getReplyMid(content));
                         break;
-                    case "0061": // 拧紧数据
-
-
-                        if(MesClient.work_status == 1){
-                            String tighteningStatus = YgslParam.getTighteningStatus(content);
-                            String torqueStatus = YgslParam.getTorqueStatus(content);
-                            String angleStatus = YgslParam.getAngleStatus(content);
-                            String torqueMin = YgslParam.getTorqueMinLimit(content);
-                            String torqueMax = YgslParam.getTorqueMaxLimit(content);
-                            String torqueFinal = YgslParam.getTorqueFinalTarget(content);
-                            String torque = YgslParam.getTorque(content);
-                            String angleMin = YgslParam.getAngleMin(content);
-                            String angleMax = YgslParam.getAngleMax(content);
-                            String angleFinal = YgslParam.getFinalAngleTarget(content);
-                            String angle = YgslParam.getAngle(content);
-                            String jobID = YgslParam.getJobID(content);
-                            String tighteningID = YgslParam.getTighteningID(content);
-                            if(!tighteningID.isEmpty() && !MesClient.atids.contains(tighteningID)){
-                                MesClient.atids.add(tighteningID);
-//                                if(Float.valueOf(torque) > Float.valueOf(torqueMin) && Float.valueOf(torque) < Float.valueOf(torqueMax)){
-//                                    torqueStatus = "1";
-//                                }else if(Float.valueOf(torque) <= Float.valueOf(torqueMin)){
-//                                    torqueStatus = "0";
-//                                }else{
-//                                    torqueStatus = "2";
-//                                }
-//                                if(Float.valueOf(angle) > Float.valueOf(angleMin) && Float.valueOf(angle) < Float.valueOf(angleMax)){
-//                                    angleStatus = "1";
-//                                }else if(Float.valueOf(angle) <= Float.valueOf(angleMin)){
-//                                    angleStatus = "0";
-//                                }else{
-//                                    angleStatus = "2";
-//                                }
-//
-//                                if(angleStatus.equals("1") && torqueStatus.equals("1")){
-//                                    tighteningStatus = "1";
-//                                }else{
-//                                    tighteningStatus = "0";
-//                                }
-
-                                String pos = "A";
-
-                                Boolean checkRet = JdbcUtils.checkTighteningById(tighteningID,pos,jobID);
-                                if(!checkRet){
-
-                                    if(tighteningStatus.equals("0")){ // NG
-                                        if(torqueStatus.equals("1")){
-                                            MesClient.torquea.setForeground(Color.BLACK);
-                                        }else{
-                                            MesClient.torquea.setForeground(Color.RED);
-                                        }
-                                        if(angleStatus.equals("1")){
-                                            MesClient.anglea.setForeground(Color.BLACK);
-                                        }else{
-                                            MesClient.anglea.setForeground(Color.RED);
-                                        }
-                                    }else{
-                                        MesClient.torquea.setForeground(Color.BLACK);
-                                        MesClient.anglea.setForeground(Color.BLACK);
-                                        if(pos.equals("A") && tighteningStatus.equals("1")){
-                                            MesClient.cura++;
-                                        }
-                                        if(pos.equals("B") && tighteningStatus.equals("1")){
-                                            MesClient.curb++;
-                                        }
-                                    }
-
-                                    String serialNumber =  String.valueOf(MesClient.cura);
-                                    if(!tighteningStatus.equals("1")){
-                                        serialNumber =  String.valueOf(MesClient.cura + 1);
-                                    }
-
-                                    MesClient.torquea.setText(torque);
-                                    MesClient.anglea.setText(angle);
-
-                                    if(MesClient.cura >= MesClient.maxa){
-                                        YgslUtil.disableTool(MesClient.ygslClient);
-                                    }
-
-                                    MesClient.schedulea.setText(MesClient.cura+"/"+MesClient.maxa);
-
-                                    JdbcUtils.insertTighteningData(
-                                            MesClient.mes_gw,MesClient.mes_line_sn,MesClient.product_sn.getText(),
-                                            tighteningStatus,torqueStatus,angleStatus,torqueMin,torqueMax,torqueFinal,torque,
-                                            angleMin,angleMax,angleFinal,angle,tighteningID,jobID,serialNumber,
-                                            pos,MesClient.user_menu.getText()
-                                    );
-                                }
-                            }
-
-
-
-                            YgslUtil.lastTighteningResultDataAcknowledge(MesClient.ygslClient);
-
-                            if(MesClient.ygslNum == 1){
-                                if(MesClient.cura >= MesClient.maxa){ // 提交质量
-                                    MesClient.finish_ok_bt.setEnabled(true);
-                                    MesClient.finish_ng_bt.setEnabled(true);
-                                    if(MesClient.work_status == 1 && MesClient.check_quality_result){
-
-                                        String sn = MesClient.product_sn.getText();
-                                        MesClient.getUser();
-
-                                        String qret = "OK";
-                                        Boolean sendret = DataUtil.sendQuality(MesClient.nettyClient,sn,qret,MesClient.user20);
-                                        if(!sendret){
-                                            MesClient.setMenuStatus("结果上传MES失败,请重试",-1);
-                                        }
-                                    }
-                                }
-                            }else{
-                                if(MesClient.cura >= MesClient.maxa && MesClient.curb >= MesClient.maxb){ // 提交质量
-                                    MesClient.finish_ok_bt.setEnabled(true);
-                                    MesClient.finish_ng_bt.setEnabled(true);
-                                    if(MesClient.work_status == 1 && MesClient.check_quality_result){
-                                        String sn = MesClient.product_sn.getText();
-                                        MesClient.getUser();
-
-                                        String qret = "OK";
-                                        Boolean sendret = DataUtil.sendQuality(MesClient.nettyClient,sn,qret,MesClient.user20);
-                                        if(!sendret){
-                                            MesClient.setMenuStatus("结果上传MES失败,请重试",-1);
-                                        }
-                                    }
-                                }
-                            }
-                        }else{
-                            YgslUtil.lastTighteningResultDataAcknowledge(MesClient.ygslClient);
+                    case "0061":
+                        if (gunClient != null && gunClient.getGunPanel() != null) {
+                            gunClient.getGunPanel().processTighteningData(content);
                         }
-
                         break;
                     default:
                         break;
                 }
-
-            }else{
-
             }
-//            System.out.println("msg:"+msg);
-        }catch (Exception e){
+        } catch (Exception e) {
             e.printStackTrace();
         }
-
     }
 
     @Override
     public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
-        System.out.println("mes exceptionCaught:" + sdf.format(new Date()));
+        System.out.println("扭力枪" + gunIndex + " 异常:" + sdf.format(new Date()));
+        cause.printStackTrace();
         ctx.close();
 
-        MesClient.ygslClient = null;
-        MesClient.initYgslTcpConnection();
+        if (gunClient != null && gunClient.getGunPanel() != null) {
+            gunClient.getGunPanel().setOnline(false);
+        }
     }
 
-    // 16字符串转Ascii
-    private String hexStringToAscii(String hexString) {
-        StringBuilder sbuilder = new StringBuilder();
-        for (int i = 0; i < hexString.length(); i += 2) {
-            String hexByte = hexString.substring(i, i + 2);
-            int byteValue = Integer.parseInt(hexByte, 16);
-            char c = (char) byteValue;
-            sbuilder.append(c);
-        }
-        return sbuilder.toString();
+    public void setGunClient(YgslClient gunClient) {
+        this.gunClient = gunClient;
+    }
+
+    public int getGunIndex() {
+        return gunIndex;
     }
 }

+ 0 - 270
src/com/mes/ygsl/YgslClientHandler2.java

@@ -1,270 +0,0 @@
-package com.mes.ygsl;
-
-import com.mes.ui.DataUtil;
-import com.mes.ui.MesClient;
-import com.mes.ui.YgslUtil;
-import com.mes.ui.YgslUtil2;
-import com.mes.util.JdbcUtils;
-import io.netty.buffer.ByteBuf;
-import io.netty.channel.Channel;
-import io.netty.channel.ChannelHandlerContext;
-import io.netty.channel.ChannelInboundHandlerAdapter;
-
-import java.awt.*;
-import java.nio.charset.StandardCharsets;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
-public class YgslClientHandler2 extends ChannelInboundHandlerAdapter {
-
-    private final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-    public static byte[] responseByte;
-
-    @Override
-    public void channelActive(ChannelHandlerContext ctx) throws Exception {
-        System.out.println("mes connecting:" + sdf.format(new Date()));
-    }
-
-    @Override
-    public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
-        Channel channel = ctx.channel();
-        System.err.println("close ygsl2 tcp, ip:" + channel.remoteAddress());
-        // 关闭通道
-        channel.close();
-
-        //初始化TCP连接
-        MesClient.ygslClient2 = null;
-        //TCP连接状态
-        MesClient.ygsl_tcp_connect_flag2 = false;
-        //设置TCP请求状态
-        MesClient.ygsl_connect_request_flag2 = true;
-    }
-
-    @Override
-    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
-        try{
-//            System.out.println("msg1111111:"+msg);
-            if (msg instanceof ByteBuf) {
-                ByteBuf buf = (ByteBuf) msg;
-                // 你的处理逻辑
-                String content = buf.toString(StandardCharsets.UTF_8);
-                System.out.println("msg2:"+content);
-
-                String mid = YgslParam.getMid(content);
-                System.out.println("MID2:"+mid);
-                switch (mid){
-                    case "0002":
-                        YgslUtil2.lastTighteningResultSubscribe(MesClient.ygslClient2);
-//                        YgslUtil2.pSet(MesClient.ygslClient2);
-                        break;
-                    case "0011":
-                        YgslUtil2.selectSet(MesClient.ygslClient2);
-                        break;
-                    case "0031":
-                        YgslUtil2.selectJob(MesClient.ygslClient2);
-//                        YgslUtil2.restartJob(MesClient.ygslClient2);
-                        break;
-                    case "0004": // 错误信息
-                        System.out.println("MID:"+YgslParam.getReplyMid(content)+";ErrorCode:"+YgslParam.getErrCode(content));
-                        break;
-                    case "0005": // 命令被接受
-                        System.out.println("命令被接受:"+YgslParam.getReplyMid(content));
-                        break;
-                    case "0061": // 拧紧数据
-                        System.out.println("YgslB:");
-                        System.out.println("getTorqueControllerName:"+YgslParam.getTorqueControllerName(content));
-                        System.out.println("getTighteningStatus:"+YgslParam.getTighteningStatus(content));
-                        System.out.println("getTorqueStatus:"+YgslParam.getTorqueStatus(content));
-                        System.out.println("getAngleStatus:"+YgslParam.getAngleStatus(content));
-                        System.out.println("getTighteningID:"+YgslParam.getTighteningID(content));
-                        System.out.println("getJobID:"+YgslParam.getJobID(content));
-                        System.out.println("getTorqueMinLimit:"+YgslParam.getTorqueMinLimit(content));
-                        System.out.println("getTorqueMaxLimit:"+YgslParam.getTorqueMaxLimit(content));
-                        System.out.println("getTorqueFinalTarget:"+YgslParam.getTorqueFinalTarget(content));
-                        System.out.println("getTorque:"+YgslParam.getTorque(content));
-                        System.out.println("getAngleMin:"+YgslParam.getAngleMin(content));
-                        System.out.println("getAngleMax:"+YgslParam.getAngleMax(content));
-                        System.out.println("getFinalAngleTarget:"+YgslParam.getFinalAngleTarget(content));
-                        System.out.println("getAngle:"+YgslParam.getAngle(content));
-                        System.out.println("getTimeStamp:"+YgslParam.getTimeStamp(content));
-                        System.out.println("getBatchStatus:"+YgslParam.getBatchStatus(content));
-                        System.out.println("getBatchSize:"+YgslParam.getBatchSize(content));
-                        System.out.println("getBatchCounter:"+YgslParam.getBatchCounter(content));
-                        YgslUtil2.lastTighteningResultDataAcknowledge(MesClient.ygslClient2);
-                        if(MesClient.work_status == 1){
-                            String tighteningStatus = YgslParam.getTighteningStatus(content);
-                            String torqueStatus = YgslParam.getTorqueStatus(content);
-                            String angleStatus = YgslParam.getAngleStatus(content);
-                            String torqueMin = YgslParam.getTorqueMinLimit(content);
-                            String torqueMax = YgslParam.getTorqueMaxLimit(content);
-                            String torqueFinal = YgslParam.getTorqueFinalTarget(content);
-                            String torque = YgslParam.getTorque(content);
-                            String angleMin = YgslParam.getAngleMin(content);
-                            String angleMax = YgslParam.getAngleMax(content);
-                            String angleFinal = YgslParam.getFinalAngleTarget(content);
-                            String angle = YgslParam.getAngle(content);
-                            String jobID = YgslParam.getJobID(content);
-                            String tighteningID = YgslParam.getTighteningID(content);
-
-                            if(!tighteningID.isEmpty() && !MesClient.btids.contains(tighteningID)){
-                                MesClient.btids.add(tighteningID);
-//                                if(Float.valueOf(torque) > Float.valueOf(torqueMin) && Float.valueOf(torque) < Float.valueOf(torqueMax)){
-//                                    torqueStatus = "1";
-//                                }else if(Float.valueOf(torque) <= Float.valueOf(torqueMin)){
-//                                    torqueStatus = "0";
-//                                }else{
-//                                    torqueStatus = "2";
-//                                }
-//                                if(Float.valueOf(angle) > Float.valueOf(angleMin) && Float.valueOf(angle) < Float.valueOf(angleMax)){
-//                                    angleStatus = "1";
-//                                }else if(Float.valueOf(angle) <= Float.valueOf(angleMin)){
-//                                    angleStatus = "0";
-//                                }else{
-//                                    angleStatus = "2";
-//                                }
-//
-//                                if(angleStatus.equals("1") && torqueStatus.equals("1")){
-//                                    tighteningStatus = "1";
-//                                }else{
-//                                    tighteningStatus = "0";
-//                                }
-
-                                String pos = "B";
-                                System.out.println("getTorqueControllerName:"+YgslParam.getTorqueControllerName(content));
-                                System.out.println("getTighteningStatus:"+YgslParam.getTighteningStatus(content));
-                                System.out.println("getTorqueStatus:"+YgslParam.getTorqueStatus(content));
-                                System.out.println("getAngleStatus:"+YgslParam.getAngleStatus(content));
-                                System.out.println("getTorqueMinLimit:"+YgslParam.getTorqueMinLimit(content));
-                                System.out.println("getTorqueMaxLimit:"+YgslParam.getTorqueMaxLimit(content));
-                                System.out.println("getTorqueFinalTarget:"+YgslParam.getTorqueFinalTarget(content));
-                                System.out.println("getTorque:"+YgslParam.getTorque(content));
-                                System.out.println("getAngleMin:"+YgslParam.getAngleMin(content));
-                                System.out.println("getAngleMax:"+YgslParam.getAngleMax(content));
-                                System.out.println("getFinalAngleTarget:"+YgslParam.getFinalAngleTarget(content));
-                                System.out.println("getAngle:"+YgslParam.getAngle(content));
-                                System.out.println("getTighteningID:"+YgslParam.getTighteningID(content));
-                                System.out.println("getTimeStamp:"+YgslParam.getTimeStamp(content));
-                                System.out.println("getBatchStatus:"+YgslParam.getBatchStatus(content));
-                                System.out.println("getBatchSize:"+YgslParam.getBatchSize(content));
-                                System.out.println("getBatchCounter:"+YgslParam.getBatchCounter(content));
-                                System.out.println("getJobID:"+YgslParam.getJobID(content));
-
-                                Boolean checkRet = JdbcUtils.checkTighteningById(tighteningID,pos,jobID);
-                                if(!checkRet){
-
-                                    if(tighteningStatus.equals("0")){ // NG
-                                        if(torqueStatus.equals("1")){
-                                            MesClient.torqueb.setForeground(Color.BLACK);
-                                        }else{
-                                            MesClient.torqueb.setForeground(Color.RED);
-                                        }
-                                        if(angleStatus.equals("1")){
-                                            MesClient.angleb.setForeground(Color.BLACK);
-                                        }else{
-                                            MesClient.angleb.setForeground(Color.RED);
-                                        }
-                                    }else{
-                                        MesClient.torqueb.setForeground(Color.BLACK);
-                                        MesClient.angleb.setForeground(Color.BLACK);
-                                        if(pos.equals("A") && tighteningStatus.equals("1")){
-                                            MesClient.cura++;
-                                        }
-                                        if(pos.equals("B") && tighteningStatus.equals("1")){
-                                            MesClient.curb++;
-                                        }
-                                    }
-
-                                    String serialNumber =  String.valueOf(MesClient.cura);
-                                    if(!tighteningStatus.equals("1")){
-                                        serialNumber =  String.valueOf(MesClient.cura + 1);
-                                    }
-
-                                    MesClient.torqueb.setText(torque);
-                                    MesClient.angleb.setText(angle);
-
-                                    if(MesClient.curb >= MesClient.maxb){
-                                        YgslUtil2.disableTool(MesClient.ygslClient2);
-                                    }
-
-                                    MesClient.scheduleb.setText(MesClient.curb+"/"+MesClient.maxb);
-
-                                    JdbcUtils.insertTighteningData(
-                                            MesClient.mes_gw,MesClient.mes_line_sn,MesClient.product_sn.getText(),
-                                            tighteningStatus,torqueStatus,angleStatus,torqueMin,torqueMax,torqueFinal,torque,
-                                            angleMin,angleMax,angleFinal,angle,tighteningID,jobID,serialNumber,
-                                            pos,MesClient.user_menu.getText()
-                                    );
-                                }
-
-
-                                if(MesClient.ygslNum == 1){
-                                    if(MesClient.cura >= MesClient.maxa){ // 提交质量
-                                        MesClient.finish_ok_bt.setEnabled(true);
-                                        MesClient.finish_ng_bt.setEnabled(true);
-                                        if(MesClient.work_status == 1 && MesClient.check_quality_result){
-
-                                            String sn = MesClient.product_sn.getText();
-                                            MesClient.getUser();
-
-                                            String qret = "OK";
-                                            Boolean sendret = DataUtil.sendQuality(MesClient.nettyClient,sn,qret,MesClient.user20);
-                                            if(!sendret){
-                                                MesClient.setMenuStatus("结果上传MES失败,请重试",-1);
-                                            }
-                                        }
-                                    }
-                                }else{
-                                    if(MesClient.cura >= MesClient.maxa && MesClient.curb >= MesClient.maxb){ // 提交质量
-                                        MesClient.finish_ok_bt.setEnabled(true);
-                                        MesClient.finish_ng_bt.setEnabled(true);
-                                        if(MesClient.work_status == 1 && MesClient.check_quality_result){
-                                            String sn = MesClient.product_sn.getText();
-                                            MesClient.getUser();
-
-                                            String qret = "OK";
-                                            Boolean sendret = DataUtil.sendQuality(MesClient.nettyClient,sn,qret,MesClient.user20);
-                                            if(!sendret){
-                                                MesClient.setMenuStatus("结果上传MES失败,请重试",-1);
-                                            }
-                                        }
-                                    }
-                                }
-                            }
-                        }
-
-                        break;
-                    default:
-                        break;
-                }
-
-            }else{
-
-            }
-//            System.out.println("msg:"+msg);
-        }catch (Exception e){
-            e.printStackTrace();
-        }
-
-    }
-
-    @Override
-    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
-        System.out.println("mes exceptionCaught:" + sdf.format(new Date()));
-        ctx.close();
-
-        MesClient.ygslClient2 = null;
-        MesClient.initYgslTcpConnection();
-    }
-
-    // 16字符串转Ascii
-    private String hexStringToAscii(String hexString) {
-        StringBuilder sbuilder = new StringBuilder();
-        for (int i = 0; i < hexString.length(); i += 2) {
-            String hexByte = hexString.substring(i, i + 2);
-            int byteValue = Integer.parseInt(hexByte, 16);
-            char c = (char) byteValue;
-            sbuilder.append(c);
-        }
-        return sbuilder.toString();
-    }
-}

+ 2 - 2
src/resources/config/config.properties

@@ -1,7 +1,7 @@
 mes.gw=OP430A
 #mes.gw=OP290
-mes.server_ip=127.0.0.1
-#mes.server_ip=192.168.21.99
+#mes.server_ip=127.0.0.1
+mes.server_ip=192.168.21.99
 mes.tcp_port=3000
 mes.heart_beat_cycle=60
 mes.line_sn=XT