From 84026ccb613df98417ab3063a6e7ac2a9151487f Mon Sep 17 00:00:00 2001
From: DELL <DELL@qq.com>
Date: 星期五, 28 十一月 2025 15:16:58 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/core/thread/impl/ZyStationThread.java | 81 +++++++++++++++++++++++++++++++---------
1 files changed, 63 insertions(+), 18 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 fb56ee4..ea8e40f 100644
--- a/src/main/java/com/zy/core/thread/impl/ZyStationThread.java
+++ b/src/main/java/com/zy/core/thread/impl/ZyStationThread.java
@@ -1,7 +1,5 @@
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;
@@ -13,11 +11,13 @@
import com.core.common.SpringUtils;
import com.zy.asrs.entity.DeviceConfig;
import com.zy.asrs.entity.DeviceDataLog;
-import com.zy.asrs.service.DeviceDataLogService;
+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.model.CommandResponse;
import com.zy.core.model.Task;
@@ -26,10 +26,7 @@
import com.zy.core.network.entity.ZyStationStatusEntity;
import java.text.MessageFormat;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
@@ -56,6 +53,20 @@
@SuppressWarnings("InfiniteLoopStatement")
public void run() {
this.connect();
+
+ //璁惧璇诲彇
+ Thread readThread = new Thread(() -> {
+ while (true) {
+ try {
+ readStatus();
+ Thread.sleep(200);
+ } catch (Exception e) {
+ log.error("StationThread Fail", e);
+ }
+ }
+ });
+ readThread.start();
+
while (true) {
try {
int step = 1;
@@ -64,10 +75,6 @@
step = task.getStep();
}
switch (step) {
- // 璇绘暟鎹�
- case 1:
- readStatus();
- break;
case 2:
sendCommand((StationCommand) task.getData());
break;
@@ -128,17 +135,15 @@
OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛",DateUtils.convert(new Date()), deviceConfig.getDeviceNo()));
if (System.currentTimeMillis() - deviceDataLogTime > 1000 * 1) {
- //閲囬泦鏃堕棿瓒呰繃1s锛屼繚瀛樹竴娆℃暟鎹褰�
//淇濆瓨鏁版嵁璁板綍
- DeviceDataLogService deviceDataLogService = SpringUtils.getBean(DeviceDataLogService.class);
DeviceDataLog deviceDataLog = new DeviceDataLog();
deviceDataLog.setOriginData(JSON.toJSONString(zyStationStatusEntities));
deviceDataLog.setWcsData(JSON.toJSONString(statusList));
deviceDataLog.setType(String.valueOf(SlaveType.Devp));
deviceDataLog.setDeviceNo(deviceConfig.getDeviceNo());
deviceDataLog.setCreateTime(new Date());
- deviceDataLogService.insert(deviceDataLog);
+ redisUtil.set(RedisKeyType.DEVICE_LOG_KEY.key + System.currentTimeMillis(), deviceDataLog, 60 * 60 * 24);
//鏇存柊閲囬泦鏃堕棿
deviceDataLogTime = System.currentTimeMillis();
}
@@ -146,8 +151,7 @@
@Override
public boolean connect() {
- SiemensS7Net siemensS7Net = new SiemensS7Net(SiemensPLCS.S1200, deviceConfig.getIp());
- zyStationConnectDriver = new ZyStationConnectDriver(siemensS7Net, deviceConfig);
+ zyStationConnectDriver = new ZyStationConnectDriver(deviceConfig);
new Thread(zyStationConnectDriver).start();
DeviceConnectPool.put(SlaveType.Devp, deviceConfig.getDeviceNo(), zyStationConnectDriver);
return true;
@@ -174,8 +178,49 @@
@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;
+ }
}
--
Gitblit v1.9.1