From 377e207801eec0014b806394166a68caa52561ab Mon Sep 17 00:00:00 2001
From: Junjie <DELL@qq.com>
Date: 星期三, 07 一月 2026 10:09:20 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/thread/impl/ZyStationThread.java |   60 ++++++++++++++++++++++++++++++++++++++----------------------
 1 files changed, 38 insertions(+), 22 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 3d932ea..be32eb0 100644
--- a/src/main/java/com/zy/core/thread/impl/ZyStationThread.java
+++ b/src/main/java/com/zy/core/thread/impl/ZyStationThread.java
@@ -20,6 +20,7 @@
 import com.zy.core.cache.OutputQueue;
 import com.zy.core.enums.RedisKeyType;
 import com.zy.core.enums.SlaveType;
+import com.zy.core.enums.StationCommandType;
 import com.zy.core.model.CommandResponse;
 import com.zy.core.model.Task;
 import com.zy.core.model.command.StationCommand;
@@ -57,12 +58,12 @@
         this.connect();
         deviceLogCollectTime = Utils.getDeviceLogCollectTime();
 
-        //璁惧璇诲彇
         Thread readThread = new Thread(() -> {
-            while (!Thread.currentThread().isInterrupted()) {
+            while (true) {
                 try {
+                    deviceLogCollectTime = Utils.getDeviceLogCollectTime();
                     readStatus();
-                    Thread.sleep(200);
+                    Thread.sleep(100);
                 } catch (Exception e) {
                     log.error("StationThread Fail", e);
                 }
@@ -70,25 +71,25 @@
         });
         readThread.start();
 
-        while (!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 (Exception e) {
-                e.printStackTrace();
             }
-        }
+        });
+        processThread.start();
     }
 
     private void readStatus() {
@@ -136,6 +137,7 @@
                     stationProtocol.setPalletHeight(statusEntity.getPalletHeight());
                     stationProtocol.setError(statusEntity.getError());
                     stationProtocol.setBarcode(statusEntity.getBarcode());
+                    stationProtocol.setRunBlock(statusEntity.isRunBlock());
                 }
             }
         }
@@ -159,14 +161,17 @@
 
     @Override
     public boolean connect() {
-        zyStationConnectDriver = new ZyStationConnectDriver(deviceConfig);
-        new Thread(zyStationConnectDriver).start();
+        zyStationConnectDriver = new ZyStationConnectDriver(deviceConfig, redisUtil);
+        zyStationConnectDriver.start();
         DeviceConnectPool.put(SlaveType.Devp, deviceConfig.getDeviceNo(), zyStationConnectDriver);
         return true;
     }
 
     @Override
     public void close() {
+        if (zyStationConnectDriver != null) {
+            zyStationConnectDriver.close();
+        }
     }
 
     @Override
@@ -175,12 +180,13 @@
     }
 
     @Override
-    public StationCommand getMoveCommand(Integer taskNo, Integer stationId, Integer targetStationId, Integer palletSize) {
+    public StationCommand getCommand(StationCommandType commandType, Integer taskNo, Integer stationId, Integer targetStationId, Integer palletSize) {
         StationCommand stationCommand = new StationCommand();
         stationCommand.setTaskNo(taskNo);
         stationCommand.setStationId(stationId);
         stationCommand.setTargetStaNo(targetStationId);
         stationCommand.setPalletSize(palletSize);
+        stationCommand.setCommandType(commandType);
         return stationCommand;
     }
 
@@ -231,4 +237,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