From 449e4e9df08162b1e7e04ac0d4e05a1387298171 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期二, 08 七月 2025 16:48:16 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/core/thread/impl/LfdZyForkLiftSlaveThread.java | 113 +++++++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 90 insertions(+), 23 deletions(-)
diff --git a/src/main/java/com/zy/core/thread/impl/LfdZyForkLiftSlaveThread.java b/src/main/java/com/zy/core/thread/impl/LfdZyForkLiftSlaveThread.java
index ac67184..82bb5aa 100644
--- a/src/main/java/com/zy/core/thread/impl/LfdZyForkLiftSlaveThread.java
+++ b/src/main/java/com/zy/core/thread/impl/LfdZyForkLiftSlaveThread.java
@@ -30,10 +30,7 @@
import lombok.extern.slf4j.Slf4j;
import java.text.MessageFormat;
-import java.util.ArrayList;
-import java.util.Base64;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
@Slf4j
@SuppressWarnings("all")
@@ -43,7 +40,6 @@
private ForkLiftSlave slave;
private ForkLiftProtocol forkLiftProtocol;
private RedisUtil redisUtil;
- private SiemensS7Net siemensS7Net;
private List<ForkLiftStaProtocol> forkLiftStaProtocols = new ArrayList<>();
private LfdZyForkLiftMasterThread masterThread;
@@ -70,7 +66,6 @@
if(masterThread != null) {
result = true;
this.masterThread = masterThread;
- this.siemensS7Net = masterThread.getSiemensS7Net();
}
return result;
}
@@ -92,7 +87,7 @@
}
read();
- Thread.sleep(200);
+ Thread.sleep(300);
execute();
} catch (Exception e) {
e.printStackTrace();
@@ -101,7 +96,10 @@
}
private void execute() {
- ForkLiftAction forkLiftAction = SpringUtils.getBean(ForkLiftAction.class);
+ ForkLiftAction forkLiftAction = null;
+ try {
+ forkLiftAction = SpringUtils.getBean(ForkLiftAction.class);
+ }catch (Exception e){}
if (forkLiftAction == null) {
return;
}
@@ -137,10 +135,7 @@
try {
//鑾峰彇鎻愬崌鏈烘暟鎹�
OperateResultExOne<byte[]> result1 = this.masterThread.read(this.slave.getId(), "status");
- if (result1 == null) {
- OutputQueue.FORKLIFT.offer(MessageFormat.format("銆恵0}銆憑1}璇诲彇璐у弶鎻愬崌鏈虹姸鎬佷俊鎭け璐�", DateUtils.convert(new Date()), slave.getId()));
- }
-
+ SiemensS7Net siemensS7Net = this.masterThread.getSiemensS7Net();
if (result1.IsSuccess) {
if (null == forkLiftProtocol) {
forkLiftProtocol = new ForkLiftProtocol();
@@ -167,6 +162,8 @@
forkLiftProtocol.setIOMode((int) siemensS7Net.getByteTransform().TransInt16(result1.Content, 12));
//鏁呴殰鐮�
forkLiftProtocol.setErrorCode((int) siemensS7Net.getByteTransform().TransInt16(result1.Content, 14));
+ //褰撳墠灞�
+ forkLiftProtocol.setLev((int) siemensS7Net.getByteTransform().TransInt16(result1.Content, 16));
//************琛ュ厖鎵╁睍瀛楁*************
InnerForkLiftExtend forkLiftExtend = (InnerForkLiftExtend) forkLiftProtocol.getExtend();
@@ -176,7 +173,7 @@
OutputQueue.FORKLIFT.offer(MessageFormat.format("銆恵0}銆憑1}璇诲彇璐у弶鎻愬崌鏈虹姸鎬佷俊鎭け璐�", DateUtils.convert(new Date()), slave.getId()));
}
- OperateResultExOne<byte[]> result2 = this.masterThread.read(this.slave.getId(), "staStatus");
+ OperateResultExOne<byte[]> result2 = this.masterThread.read(this.slave.getId(), "staStatusTray");
if (result2.IsSuccess) {
for (int i = 0; i < this.slave.getSta().size(); i++) {
ForkLiftSlave.Sta sta = this.slave.getSta().get(i);
@@ -184,10 +181,23 @@
continue;
}
+ short val = siemensS7Net.getByteTransform().TransInt16(result2.Content, i * 2);
ForkLiftStaProtocol forkLiftStaProtocol = forkLiftStaProtocols.get(i);
- boolean[] status1 = siemensS7Net.getByteTransform().TransBool(result2.Content, i * 2, 2);
- forkLiftStaProtocol.setHasTray(status1[0]);
- forkLiftStaProtocol.setHasCar(status1[1]);
+ forkLiftStaProtocol.setHasTray(val == 1);
+ }
+ }
+
+ OperateResultExOne<byte[]> result3 = this.masterThread.read(this.slave.getId(), "staStatusCar");
+ if (result3.IsSuccess) {
+ for (int i = 0; i < this.slave.getSta().size(); i++) {
+ ForkLiftSlave.Sta sta = this.slave.getSta().get(i);
+ if (forkLiftStaProtocols.isEmpty()) {
+ continue;
+ }
+
+ short val = siemensS7Net.getByteTransform().TransInt16(result3.Content, i * 2);
+ ForkLiftStaProtocol forkLiftStaProtocol = forkLiftStaProtocols.get(i);
+ forkLiftStaProtocol.setHasCar(val == 1);
}
}
@@ -202,6 +212,15 @@
deviceDataLog.setDeviceNo(forkLiftProtocol.getLiftNo());
deviceDataLog.setCreateTime(new Date());
deviceDataLogService.insert(deviceDataLog);
+
+ //淇濆瓨鏁版嵁璁板綍
+ DeviceDataLog deviceDataLog2 = new DeviceDataLog();
+ deviceDataLog2.setOriginData(Base64.getEncoder().encodeToString(result2.Content));
+ deviceDataLog2.setWcsData(JSON.toJSONString(forkLiftStaProtocols));
+ deviceDataLog2.setType("forkLiftStaProtocols");
+ deviceDataLog2.setDeviceNo(forkLiftProtocol.getLiftNo());
+ deviceDataLog2.setCreateTime(new Date());
+ deviceDataLogService.insert(deviceDataLog2);
//鏇存柊閲囬泦鏃堕棿
forkLiftProtocol.setDeviceDataLog(System.currentTimeMillis());
@@ -290,6 +309,24 @@
}
@Override
+ public CommandResponse move(ForkLiftCommand command) {
+ CommandResponse response = new CommandResponse(false);
+
+ short[] array = new short[4];
+ array[0] = command.getTaskNo();//浠诲姟鍙�
+ array[1] = command.getMode();//浠诲姟妯″紡
+ array[2] = command.getPut();//鏀捐揣鏁版嵁
+ OperateResult result = this.masterThread.write(this.slave.getId(), "write", array);
+ if (result.IsSuccess) {
+ OperateResult result2 = this.masterThread.write(this.slave.getId(), "writeConfirm", command.getConfirm());
+ if (result2.IsSuccess) {
+ response.setResult(true);
+ }
+ }
+ return response;
+ }
+
+ @Override
public CommandResponse reset() {
CommandResponse response = new CommandResponse(false);
OperateResult result = this.masterThread.write(this.slave.getId(), "confirm", (short) 1);
@@ -305,6 +342,7 @@
if (this.forkLiftProtocol.getTaskNo() == null
|| this.forkLiftProtocol.getProtocolStatus() == null
|| this.forkLiftProtocol.getModel() == null
+ || this.forkLiftProtocol.getErrorCode() == null
) {
return false;
}
@@ -312,7 +350,9 @@
boolean res = this.forkLiftProtocol.getProtocolStatus() == ForkLiftProtocolStatusType.IDLE.id
&& this.forkLiftProtocol.getWrkNo() == 0
&& this.forkLiftProtocol.getTaskNo() == 0
- && this.forkLiftProtocol.getModel() == 2;
+ && this.forkLiftProtocol.getModel() == 2
+ && this.forkLiftProtocol.getErrorCode() == 0
+ ;
return res;
}
@@ -333,13 +373,16 @@
if (this.forkLiftProtocol.getTaskNo() == null
|| this.forkLiftProtocol.getProtocolStatus() == null
|| this.forkLiftProtocol.getModel() == null
+ || this.forkLiftProtocol.getErrorCode() == null
) {
return false;
}
boolean res = this.forkLiftProtocol.getProtocolStatus() == ForkLiftProtocolStatusType.IDLE.id
&& this.forkLiftProtocol.getWrkNo() == 0
- && this.forkLiftProtocol.getModel() == 2;
+ && this.forkLiftProtocol.getModel() == 2
+ && this.forkLiftProtocol.getErrorCode() == 0
+ ;
return res;
}
@@ -370,13 +413,16 @@
@Override
public List<ForkLiftCommand> getPickAndPutCommand(Integer taskNo, Integer pick, Integer put) {
+ Integer realPick = pick % 1000;
+ Integer realPut = put % 1000;
+
List<ForkLiftCommand> commands = new ArrayList<>();
ForkLiftCommand command = new ForkLiftCommand();
command.setLiftNo(slave.getId());
command.setTaskNo(taskNo.shortValue());
command.setMode(ForkLiftTaskModeType.PICK_PUT.id.shortValue());
- command.setPick(pick.shortValue());
- command.setPut(put.shortValue());
+ command.setPick(realPick.shortValue());
+ command.setPut(realPut.shortValue());
command.setConfirm((short) 1);
commands.add(command);
@@ -384,14 +430,35 @@
}
@Override
- public List<ForkLiftCommand> getShuttleSwitchCommand(Integer taskNo, Integer originLev, Integer targetLev) {
+ public List<ForkLiftCommand> getShuttleSwitchCommand(Integer taskNo, Integer pick, Integer put) {
+ Integer realPick = pick % 1000;
+ Integer realPut = put % 1000;
+
List<ForkLiftCommand> commands = new ArrayList<>();
ForkLiftCommand command = new ForkLiftCommand();
command.setLiftNo(slave.getId());
command.setTaskNo(taskNo.shortValue());
command.setMode(ForkLiftTaskModeType.SHUTTLE_SWITCH.id.shortValue());
- command.setPick(originLev.shortValue());
- command.setPut(targetLev.shortValue());
+ command.setPick(realPick.shortValue());
+ command.setPut(realPut.shortValue());
+ command.setConfirm((short) 1);
+
+ commands.add(command);
+ return commands;
+ }
+
+ @Override
+ public List<ForkLiftCommand> getMoveCommand(Integer taskNo, Integer pick, Integer put) {
+ Integer realPick = pick % 1000;
+ Integer realPut = put % 1000;
+
+ List<ForkLiftCommand> commands = new ArrayList<>();
+ ForkLiftCommand command = new ForkLiftCommand();
+ command.setLiftNo(slave.getId());
+ command.setTaskNo(taskNo.shortValue());
+ command.setMode(ForkLiftTaskModeType.MOVE.id.shortValue());
+ command.setPick(realPick.shortValue());
+ command.setPut(realPut.shortValue());
command.setConfirm((short) 1);
commands.add(command);
--
Gitblit v1.9.1