From ec1f480801fdc89e862f4e9bcad2aed47ae1d37b Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@63.com>
Date: 星期二, 15 三月 2022 15:37:09 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/core/thread/SteThread.java | 118 ++++++++++++++++++++++++++++++++++------------------------
1 files changed, 69 insertions(+), 49 deletions(-)
diff --git a/src/main/java/com/zy/core/thread/SteThread.java b/src/main/java/com/zy/core/thread/SteThread.java
index a3da704..c7af558 100644
--- a/src/main/java/com/zy/core/thread/SteThread.java
+++ b/src/main/java/com/zy/core/thread/SteThread.java
@@ -15,7 +15,6 @@
import com.zy.core.cache.MessageQueue;
import com.zy.core.cache.OutputQueue;
import com.zy.core.enums.SlaveType;
-import com.zy.core.enums.SteStatusType;
import com.zy.core.model.SteSlave;
import com.zy.core.model.Task;
import com.zy.core.model.command.SteCommand;
@@ -73,7 +72,7 @@
break;
}
// 蹇冭烦
- heartbeat();
+// heartbeat();
Thread.sleep(500);
} catch (Exception e) {
e.printStackTrace();
@@ -134,52 +133,52 @@
*/
private void readStatus(){
try {
- OperateResultExOne<byte[]> result = siemensS7Net.Read("V20", (short) 70);
+ OperateResultExOne<byte[]> result = siemensS7Net.Read("DB4", (short) 70);
if (result.IsSuccess) {
if (null == steProtocol) {
steProtocol = new SteProtocol();
}
-// steProtocol.setSteNo();
-// steProtocol.setMode();
-// steProtocol.setStatus();
+ steProtocol.setSteNo(siemensS7Net.getByteTransform().TransInt16(result.Content, 0));
+ steProtocol.setMode(siemensS7Net.getByteTransform().TransInt16(result.Content, 2));
+ steProtocol.setStatus(siemensS7Net.getByteTransform().TransInt16(result.Content, 4));
// steProtocol.setExecute();
// steProtocol.setWaiting();
-// steProtocol.setAlarm();
-// steProtocol.setAlarm0();
-// steProtocol.setCharge();
+ steProtocol.setAlarm(siemensS7Net.getByteTransform().TransInt32(result.Content, 6));
+ steProtocol.setAlarm0(siemensS7Net.getByteTransform().TransInt32(result.Content, 10));
+ steProtocol.setCharge(siemensS7Net.getByteTransform().TransInt16(result.Content, 14));
// steProtocol.setFullCharge();
// steProtocol.setLowCharge();
-// steProtocol.setFeed();
-// steProtocol.setLoca();
+ steProtocol.setFeed(siemensS7Net.getByteTransform().TransInt16(result.Content, 16));
+ steProtocol.setLoca(siemensS7Net.getByteTransform().TransInt16(result.Content, 18));
// steProtocol.setCloser();
// steProtocol.setSpeed();
-// steProtocol.setPos();
-// steProtocol.setLoad();
-// steProtocol.setTrack();
-// steProtocol.setTaskNo();
-// steProtocol.setTaskType();
-// steProtocol.setRow();
-// steProtocol.setBay();
-// steProtocol.setLev();
-//
-// steProtocol.setHisTaskNo();
-// steProtocol.setHisTaskStatus();
-// steProtocol.setCheckQty();
-// steProtocol.setReady();
-// steProtocol.setChargeNo();
-//
-// steProtocol.setHeart();
-// steProtocol.setCrnStopRun();
-// steProtocol.setCrnStopFork();
-// steProtocol.setCrnAllowRun();
+ steProtocol.setPos(siemensS7Net.getByteTransform().TransInt16(result.Content, 28));
+ steProtocol.setLoad(siemensS7Net.getByteTransform().TransInt16(result.Content, 30));
+ steProtocol.setTrack(siemensS7Net.getByteTransform().TransInt16(result.Content, 32));
+ steProtocol.setTaskNo(siemensS7Net.getByteTransform().TransInt32(result.Content, 38));
+ steProtocol.setTaskType(siemensS7Net.getByteTransform().TransInt16(result.Content, 42));
+ steProtocol.setRow(siemensS7Net.getByteTransform().TransInt16(result.Content, 44));
+ steProtocol.setBay(siemensS7Net.getByteTransform().TransInt16(result.Content, 46));
+ steProtocol.setLev(siemensS7Net.getByteTransform().TransInt16(result.Content, 48));
+
+ steProtocol.setHisTaskNo(siemensS7Net.getByteTransform().TransInt32(result.Content, 58));
+ steProtocol.setHisTaskStatus(siemensS7Net.getByteTransform().TransInt16(result.Content, 62));
+ steProtocol.setCheckQty(siemensS7Net.getByteTransform().TransInt16(result.Content, 64));
+ steProtocol.setReady(siemensS7Net.getByteTransform().TransInt16(result.Content, 66));
+ steProtocol.setChargeNo(siemensS7Net.getByteTransform().TransInt16(result.Content, 68));
+
+ steProtocol.setHeart(siemensS7Net.getByteTransform().TransInt16(result.Content, 72));
+ steProtocol.setCrnStopRun(siemensS7Net.getByteTransform().TransInt16(result.Content, 74));
+ steProtocol.setCrnStopFork(siemensS7Net.getByteTransform().TransInt16(result.Content, 76));
+ steProtocol.setCrnAllowRun(siemensS7Net.getByteTransform().TransInt16(result.Content, 78));
OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛",DateUtils.convert(new Date()), slave.getId()));
// 澶嶄綅淇″彿
- if (steProtocol.getStatusType().equals(SteStatusType.WAITING)) {
+ if (steProtocol.getWaiting()) {
if (resetFlag) {
SteCommand steCommand = new SteCommand();
-// steCommand.setAckFinish((short)1);
+ steCommand.setComplete(true);
if (write(steCommand) && confirmPos()) {
resetFlag = false;
}
@@ -219,23 +218,30 @@
return false;
}
command.setSteNo(slave.getId());
- short[] array = new short[10];
-// array[0] = command.getAckFinish();
-// array[1] = command.getTaskNo();
-// array[2] = command.getTaskMode();
-// array[3] = command.getSourcePosX();
+ OperateResult result = null;
+ // 寮�濮嬩换鍔�
+ if (!command.getComplete()) {
+ OperateResult result0 = siemensS7Net.Write("D0", command.getTaskNo());
+ short[] array = new short[10];
+ array[0] = command.getTaskMode();
+// array[1] = command.getTaskNo();
+// array[2] = command.getTaskMode();
+// array[3] = command.getSourcePosX();
// array[4] = command.getSourcePosY();
// array[5] = command.getSourcePosZ();
// array[6] = command.getDestinationPosX();
// array[7] = command.getDestinationPosY();
// array[8] = command.getDestinationPosZ();
// array[9] = command.getCommand();
- OperateResult result = siemensS7Net.Write("D0", array);
-
-// if (command.getAckFinish() == 0) {
-// short commandFinish = 1;
-// result = siemensS7Net.Write("D9", commandFinish);
-// }
+ OperateResult result1 = siemensS7Net.Write("D0", array);
+ // 纭寮�濮嬩换鍔�
+ if (result0.IsSuccess) {
+ result = siemensS7Net.Write("D0", true);
+ }
+ // 浠诲姟瀹屾垚
+ } else {
+ result = siemensS7Net.Write("D0", true);
+ }
try {
// 鏃ュ織璁板綍
@@ -260,9 +266,14 @@
// bean.insert(basSteOpt);
} catch (Exception ignore) {}
- if (result.IsSuccess) {
+ if (result != null && result.IsSuccess) {
// 缁存姢鏁版嵁搴撴帓鍒楀眰
-// this.modifyPos();
+ if (!steProtocol.getWaiting()) {
+ this.lastRow = command.getRow().intValue();
+ this.lastBay = command.getBay().intValue();
+ this.lastLev = command.getLev().intValue();
+ }
+
log.info("绌挎杞﹀懡浠や笅鍙慬id:{}] >>>>> {}", slave.getId(), JSON.toJSON(command));
OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆慬id:{1}] >>>>> 鍛戒护涓嬪彂锛� {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command)));
@@ -287,10 +298,19 @@
BasSteService service = SpringUtils.getBean(BasSteService.class);
BasSte basSte = service.selectById(slave.getId());
if (basSte != null) {
- if (service.updatePos(this.lastRow, this.lastBay, this.lastLev) > 0) {
- return true;
- } else {
- log.error("{}鍙风┛姊溅淇敼鏁版嵁搴撳畾浣嶅け璐ワ紒锛侊紒", slave.getId());
+ // 鏇存柊plc鏁版嵁鍧�
+ short[] arr = new short[] {this.lastRow.shortValue(), this.lastBay.shortValue(), this.lastLev.shortValue()};
+ OperateResult result = siemensS7Net.Write("D0", arr);
+ if (result.IsSuccess) {
+ // 鏇存柊鏁版嵁搴�
+ if (service.updatePos(this.lastRow, this.lastBay, this.lastLev) > 0) {
+ this.lastRow = null;
+ this.lastBay = null;
+ this.lastLev = null;
+ return true;
+ } else {
+ log.error("{}鍙风┛姊溅淇敼鏁版嵁搴撳畾浣嶅け璐ワ紒锛侊紒", slave.getId());
+ }
}
}
--
Gitblit v1.9.1