From 6d99081f3f6e0363b0bd28053e545a8e4589b979 Mon Sep 17 00:00:00 2001
From: Junjie <DELL@qq.com>
Date: 星期五, 09 一月 2026 08:50:11 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/core/thread/impl/ZyStationThread.java | 143 ++++++++++++++++++++++++++++++++++++-----------
1 files changed, 109 insertions(+), 34 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 5c0d73c..62ea5a9 100644
--- a/src/main/java/com/zy/core/thread/impl/ZyStationThread.java
+++ b/src/main/java/com/zy/core/thread/impl/ZyStationThread.java
@@ -1,11 +1,10 @@
package com.zy.core.thread.impl;
-import HslCommunication.Profinet.Siemens.SiemensPLCS;
-import HslCommunication.Profinet.Siemens.SiemensS7Net;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.zy.asrs.entity.BasDevp;
import com.zy.asrs.service.BasDevpService;
+import com.zy.asrs.utils.Utils;
import com.zy.core.network.DeviceConnectPool;
import com.zy.core.thread.StationThread;
import com.alibaba.fastjson.JSON;
@@ -13,12 +12,15 @@
import com.core.common.SpringUtils;
import com.zy.asrs.entity.DeviceConfig;
import com.zy.asrs.entity.DeviceDataLog;
+import com.zy.asrs.entity.BasStationOpt;
+import com.zy.asrs.service.BasStationOptService;
import com.zy.common.utils.RedisUtil;
import com.zy.core.network.ZyStationConnectDriver;
import com.zy.core.cache.MessageQueue;
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;
@@ -26,9 +28,7 @@
import com.zy.core.network.entity.ZyStationStatusEntity;
import java.text.MessageFormat;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
@@ -44,6 +44,7 @@
private DeviceConfig deviceConfig;
private RedisUtil redisUtil;
private ZyStationConnectDriver zyStationConnectDriver;
+ private int deviceLogCollectTime = 200;
private long deviceDataLogTime = System.currentTimeMillis();
public ZyStationThread(DeviceConfig deviceConfig, RedisUtil redisUtil) {
@@ -55,29 +56,40 @@
@SuppressWarnings("InfiniteLoopStatement")
public void run() {
this.connect();
- while (true) {
- try {
- int step = 1;
- Task task = MessageQueue.poll(SlaveType.Devp, deviceConfig.getDeviceNo());
- if (task != null) {
- step = task.getStep();
+ deviceLogCollectTime = Utils.getDeviceLogCollectTime();
+
+ Thread readThread = new Thread(() -> {
+ while (true) {
+ try {
+ deviceLogCollectTime = Utils.getDeviceLogCollectTime();
+ readStatus();
+ Thread.sleep(100);
+ } catch (Exception e) {
+ log.error("StationThread Fail", e);
}
- switch (step) {
- // 璇绘暟鎹�
- case 1:
- readStatus();
- break;
- case 2:
- sendCommand((StationCommand) task.getData());
- break;
- default:
- break;
- }
- Thread.sleep(200);
- } catch (Exception e) {
- e.printStackTrace();
}
- }
+ });
+ readThread.start();
+
+ 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());
+ }
+
+ Thread.sleep(100);
+ } catch (Exception e) {
+ log.error("StationProcess Fail", e);
+ }
+ }
+ });
+ processThread.start();
}
private void readStatus() {
@@ -86,7 +98,12 @@
}
if(statusList.isEmpty()) {
- BasDevpService basDevpService = SpringUtils.getBean(BasDevpService.class);
+ BasDevpService basDevpService = null;
+ try {
+ basDevpService = SpringUtils.getBean(BasDevpService.class);
+ } catch (Exception e) {
+
+ }
if (basDevpService == null) {
return;
}
@@ -119,14 +136,18 @@
stationProtocol.setFullPlt(statusEntity.isFullPlt());
stationProtocol.setPalletHeight(statusEntity.getPalletHeight());
stationProtocol.setError(statusEntity.getError());
+ stationProtocol.setErrorMsg(statusEntity.getErrorMsg());
stationProtocol.setBarcode(statusEntity.getBarcode());
+ stationProtocol.setRunBlock(statusEntity.isRunBlock());
+ stationProtocol.setEnableIn(statusEntity.isEnableIn());
+ stationProtocol.setWeight(statusEntity.getWeight());
}
}
}
OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛",DateUtils.convert(new Date()), deviceConfig.getDeviceNo()));
- if (System.currentTimeMillis() - deviceDataLogTime > 1000 * 1) {
+ if (System.currentTimeMillis() - deviceDataLogTime > deviceLogCollectTime) {
//淇濆瓨鏁版嵁璁板綍
DeviceDataLog deviceDataLog = new DeviceDataLog();
deviceDataLog.setOriginData(JSON.toJSONString(zyStationStatusEntities));
@@ -143,15 +164,17 @@
@Override
public boolean connect() {
- SiemensS7Net siemensS7Net = new SiemensS7Net(SiemensPLCS.S1200, deviceConfig.getIp());
- zyStationConnectDriver = new ZyStationConnectDriver(siemensS7Net, 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
@@ -160,19 +183,71 @@
}
@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;
}
@Override
public CommandResponse sendCommand(StationCommand command) {
- CommandResponse commandResponse = zyStationConnectDriver.sendCommand(command);
- return commandResponse;
+ CommandResponse commandResponse = null;
+ try {
+ commandResponse = zyStationConnectDriver.sendCommand(command);
+ return commandResponse;
+ } finally {
+ BasStationOptService optService = SpringUtils.getBean(BasStationOptService.class);
+ List<ZyStationStatusEntity> statusListEntity = zyStationConnectDriver.getStatus();
+ ZyStationStatusEntity matched = null;
+ if (statusListEntity != null) {
+ for (ZyStationStatusEntity e : statusListEntity) {
+ if (e.getStationId() != null && e.getStationId().equals(command.getStationId())) {
+ matched = e;
+ break;
+ }
+ }
+ }
+ BasStationOpt basStationOpt = new BasStationOpt(
+ command.getTaskNo(),
+ command.getStationId(),
+ new Date(),
+ "MOVE",
+ command.getStationId(),
+ command.getTargetStaNo(),
+ null,
+ null,
+ null,
+ JSON.toJSONString(command),
+ JSON.toJSONString(matched),
+ 1,
+ JSON.toJSONString(commandResponse)
+ );
+ if (optService != null) {
+ optService.insert(basStationOpt);
+ }
+ }
}
+ @Override
+ public Map<Integer, StationProtocol> getStatusMap() {
+ Map<Integer, StationProtocol> map = new HashMap<>();
+ for (StationProtocol stationProtocol : statusList) {
+ map.put(stationProtocol.getStationId(), stationProtocol);
+ }
+ 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