From 4b97844365fddeeb66a00f4ac42389cadb545bcf Mon Sep 17 00:00:00 2001
From: Junjie <DELL@qq.com>
Date: 星期二, 06 一月 2026 09:02:21 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/thread/impl/ZyStationThread.java |   72 ++++++++++++++++-------------------
 1 files changed, 33 insertions(+), 39 deletions(-)

diff --git a/src/main/java/com/zy/core/thread/impl/ZyStationThread.java b/src/main/java/com/zy/core/thread/impl/ZyStationThread.java
index 6eb4b94..df9af2a 100644
--- a/src/main/java/com/zy/core/thread/impl/ZyStationThread.java
+++ b/src/main/java/com/zy/core/thread/impl/ZyStationThread.java
@@ -28,6 +28,7 @@
 
 import java.text.MessageFormat;
 import java.util.*;
+import java.util.concurrent.ScheduledExecutorService;
 
 import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
@@ -45,9 +46,6 @@
     private ZyStationConnectDriver zyStationConnectDriver;
     private int deviceLogCollectTime = 200;
     private long deviceDataLogTime = System.currentTimeMillis();
-    private volatile boolean closed = false;
-    private Thread mainThread;
-    private Thread readThread;
 
     public ZyStationThread(DeviceConfig deviceConfig, RedisUtil redisUtil) {
         this.deviceConfig = deviceConfig;
@@ -59,16 +57,13 @@
     public void run() {
         this.connect();
         deviceLogCollectTime = Utils.getDeviceLogCollectTime();
-        mainThread = Thread.currentThread();
 
-        readThread = new Thread(() -> {
-            while (!closed && !Thread.currentThread().isInterrupted()) {
+        Thread readThread = new Thread(() -> {
+            while (true) {
                 try {
+                    deviceLogCollectTime = Utils.getDeviceLogCollectTime();
                     readStatus();
-                    Thread.sleep(200);
-                } catch (InterruptedException ie) {
-                    Thread.currentThread().interrupt();
-                    break;
+                    Thread.sleep(100);
                 } catch (Exception e) {
                     log.error("StationThread Fail", e);
                 }
@@ -76,28 +71,25 @@
         });
         readThread.start();
 
-        while (!closed && !Thread.currentThread().isInterrupted()) {
-            try {
-                int step = 1;
-                Task task = MessageQueue.poll(SlaveType.Devp, deviceConfig.getDeviceNo());
-                if (task != null) {
-                    step = task.getStep();
-                }
-                switch (step) {
-                    case 2:
+        Thread processThread = new Thread(() -> {
+            while (true) {
+                try {
+                    int step = 1;
+                    Task task = MessageQueue.poll(SlaveType.Devp, deviceConfig.getDeviceNo());
+                    if (task != null) {
+                        step = task.getStep();
+                    }
+                    if (step == 2) {
                         sendCommand((StationCommand) task.getData());
-                        break;
-                    default:
-                        break;
+                    }
+
+                    Thread.sleep(100);
+                } catch (Exception e) {
+                    log.error("StationProcess Fail", e);
                 }
-                Thread.sleep(200);
-            } catch (InterruptedException ie) {
-                Thread.currentThread().interrupt();
-                break;
-            } catch (Exception e) {
-                e.printStackTrace();
             }
-        }
+        });
+        processThread.start();
     }
 
     private void readStatus() {
@@ -145,6 +137,7 @@
                     stationProtocol.setPalletHeight(statusEntity.getPalletHeight());
                     stationProtocol.setError(statusEntity.getError());
                     stationProtocol.setBarcode(statusEntity.getBarcode());
+                    stationProtocol.setRunBlock(statusEntity.isRunBlock());
                 }
             }
         }
@@ -168,7 +161,7 @@
 
     @Override
     public boolean connect() {
-        zyStationConnectDriver = new ZyStationConnectDriver(deviceConfig);
+        zyStationConnectDriver = new ZyStationConnectDriver(deviceConfig, redisUtil);
         zyStationConnectDriver.start();
         DeviceConnectPool.put(SlaveType.Devp, deviceConfig.getDeviceNo(), zyStationConnectDriver);
         return true;
@@ -176,15 +169,6 @@
 
     @Override
     public void close() {
-        closed = true;
-        Thread t = mainThread;
-        if (t != null) {
-            try { t.interrupt(); } catch (Exception ignore) {}
-        }
-        Thread rt = readThread;
-        if (rt != null) {
-            try { rt.interrupt(); } catch (Exception ignore) {}
-        }
         if (zyStationConnectDriver != null) {
             zyStationConnectDriver.close();
         }
@@ -252,4 +236,14 @@
         }
         return map;
     }
+
+    @Override
+    public CommandResponse sendOriginCommand(String address, short[] data) {
+        return zyStationConnectDriver.sendOriginCommand(address, data);
+    }
+
+    @Override
+    public byte[] readOriginCommand(String address, int length) {
+        return zyStationConnectDriver.readOriginCommand(address, length);
+    }
 }

--
Gitblit v1.9.1