jingbo 2 недель назад
Родитель
Сommit
a099cc78df

+ 6 - 0
src/com/mes/component/GunPanel.java

@@ -293,14 +293,20 @@ public class GunPanel extends JPanel {
     }
     }
 
 
     public void pSet() {
     public void pSet() {
+        System.out.println("GunPanel[" + gunIndex + "] pSet called, isOnline=" + isOnline + ", gunClient=" + (gunClient != null));
         if (gunClient != null && isOnline) {
         if (gunClient != null && isOnline) {
             YgslUtil.pSet(gunClient);
             YgslUtil.pSet(gunClient);
+        } else {
+            System.err.println("GunPanel[" + gunIndex + "] pSet skipped - not online!");
         }
         }
     }
     }
 
 
     public void startJob() {
     public void startJob() {
+        System.out.println("GunPanel[" + gunIndex + "] startJob called, isOnline=" + isOnline + ", gunClient=" + (gunClient != null));
         if (gunClient != null && isOnline) {
         if (gunClient != null && isOnline) {
             YgslUtil.selectJob(gunClient);
             YgslUtil.selectJob(gunClient);
+        } else {
+            System.err.println("GunPanel[" + gunIndex + "] startJob skipped - not online!");
         }
         }
     }
     }
 
 

+ 25 - 0
src/com/mes/ui/MesClient.java

@@ -342,6 +342,31 @@ public class MesClient extends JFrame {
 
 
     public static java.util.Timer cjTimer5;
     public static java.util.Timer cjTimer5;
     public static void deviceOnline() {
     public static void deviceOnline() {
+        if(cjTimer5 != null) {
+            cjTimer5.cancel();
+        }
+        cjTimer5 = new java.util.Timer();
+        cjTimer5.schedule(new java.util.TimerTask() {
+            public void run() {
+                try{
+                    for (GunPanel panel : gunPanels) {
+                        if (panel.isOnline()) {
+                            if (work_status == 1 && pz_status == 1) {
+                                if (panel.isTaskCompleted()) {
+                                    panel.disableTool();
+                                } else {
+                                    panel.enableTool();
+                                }
+                            } else {
+                                panel.disableTool();
+                            }
+                        }
+                    }
+                }catch (Exception e){
+                    e.printStackTrace();
+                }
+            }
+        }, 1000, 1000);
     }
     }
 
 
     public static java.util.Timer cjTimer2;
     public static java.util.Timer cjTimer2;

+ 1 - 1
src/com/mes/ui/MesRevice.java

@@ -59,7 +59,7 @@ public class MesRevice {
 
 
                 for (GunPanel panel : MesClient.gunPanels) {
                 for (GunPanel panel : MesClient.gunPanels) {
                     panel.pSet();
                     panel.pSet();
-                    panel.startJob();
+//                    panel.startJob();
                 }
                 }
             }
             }
         }catch (Exception e){
         }catch (Exception e){

+ 15 - 3
src/com/mes/ygsl/YgslClientHandler.java

@@ -1,5 +1,6 @@
 package com.mes.ygsl;
 package com.mes.ygsl;
 
 
+import com.mes.component.GunPanel;
 import com.mes.ui.YgslUtil;
 import com.mes.ui.YgslUtil;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.ByteBuf;
 import io.netty.channel.Channel;
 import io.netty.channel.Channel;
@@ -24,16 +25,27 @@ public class YgslClientHandler extends ChannelInboundHandlerAdapter {
     @Override
     @Override
     public void channelActive(ChannelHandlerContext ctx) throws Exception {
     public void channelActive(ChannelHandlerContext ctx) throws Exception {
         System.out.println("扭力枪" + gunIndex + "连接中:" + sdf.format(new Date()));
         System.out.println("扭力枪" + gunIndex + "连接中:" + sdf.format(new Date()));
+
+        if (gunClient != null) {
+            GunPanel panel = gunClient.getGunPanel();
+            if (panel != null) {
+                panel.setOnline(true);
+            }
+        }
     }
     }
 
 
     @Override
     @Override
     public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
     public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
         Channel channel = ctx.channel();
         Channel channel = ctx.channel();
-        System.err.println("关闭扭力枪" + gunIndex + " TCP连接, IP:" + channel.remoteAddress());
+        String remoteAddr = channel.remoteAddress() != null ? channel.remoteAddress().toString() : "未知";
+        System.err.println("扭力枪" + gunIndex + " 连接断开, IP:" + remoteAddr);
         channel.close();
         channel.close();
 
 
-        if (gunClient != null && gunClient.getGunPanel() != null) {
-            gunClient.getGunPanel().setOnline(false);
+        if (gunClient != null) {
+            GunPanel panel = gunClient.getGunPanel();
+            if (panel != null) {
+                panel.setOnline(false);
+            }
         }
         }
     }
     }