From 37a50634832b20de8589e4a02d527681d81b53c7 Mon Sep 17 00:00:00 2001
From: whycq <whycq>
Date: 星期二, 15 三月 2022 14:51:07 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/core/thread/SteThread.java | 85 +++++++++++++++++++++++++++---------------
1 files changed, 54 insertions(+), 31 deletions(-)
diff --git a/src/main/java/com/zy/core/thread/SteThread.java b/src/main/java/com/zy/core/thread/SteThread.java
index e74e48e..2d45b85 100644
--- a/src/main/java/com/zy/core/thread/SteThread.java
+++ b/src/main/java/com/zy/core/thread/SteThread.java
@@ -9,12 +9,12 @@
import com.core.common.SpringUtils;
import com.core.exception.CoolException;
import com.zy.asrs.entity.BasSte;
+import com.zy.asrs.service.BasSteOptService;
import com.zy.asrs.service.BasSteService;
import com.zy.core.ThreadHandler;
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;
@@ -175,10 +175,10 @@
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;
}
@@ -188,12 +188,14 @@
// 鏍规嵁瀹炴椂淇℃伅鏇存柊鏁版嵁搴�
BasSteService service = SpringUtils.getBean(BasSteService.class);
- BasSte basSte = new BasSte();
- basSte.setSteNo(slave.getId());
- if (!service.updateById(steProtocol.toSqlModel(basSte))){
- log.error("绌挎杞lc鏁版嵁搴撴洿鏂板け璐� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
- }
+ if (null != service) {
+ BasSte basSte = new BasSte();
+ basSte.setSteNo(slave.getId());
+ if (!service.updateById(steProtocol.toSqlModel(basSte))){
+ log.error("绌挎杞lc鏁版嵁搴撴洿鏂板け璐� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
+ }
+ }
} else {
OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆憑1}绌挎杞lc鐘舵�佷俊鎭け璐�",DateUtils.convert(new Date()), slave.getId()));
throw new CoolException(MessageFormat.format( "绌挎杞lc鐘舵�佷俊鎭け璐� ===>> [id:{0}] [ip:{1}] [port:{2}]", slave.getId(), slave.getIp(), slave.getPort()));
@@ -216,32 +218,39 @@
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 {
// 鏃ュ織璁板綍
-// BasCrnOptService bean = SpringUtils.getBean(BasCrnOptService.class);
-// BasCrnOpt basCrnOpt = new BasCrnOpt(
-// command.getTaskNo().intValue(), // 浠诲姟鍙�
-// command.getCrnNo(), // 绌挎杞闈炵┖]
+ BasSteOptService bean = SpringUtils.getBean(BasSteOptService.class);
+// BasSteOpt basSteOpt = new BasSteOpt(
+// command.getTaskNo(), // 浠诲姟鍙�
+// command.getSteNo(), // 绌挎杞闈炵┖]
// new Date(), // 涓嬪彂鏃堕棿
-// command.getTaskModeType().toString(), // 妯″紡
+// command.getTaskModeType().desc, // 妯″紡
// command.getSourcePosX().intValue(), // 婧愭帓
// command.getSourcePosY().intValue(), // 婧愬垪
// command.getSourcePosZ().intValue(), // 婧愬眰
@@ -254,12 +263,17 @@
// null, // 淇敼鏃堕棿
// null // 淇敼浜哄憳
// );
-// bean.insert(basCrnOpt);
+// 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)));
@@ -284,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