From e70fab8263d894ad35408ae84f599fe4c9d37482 Mon Sep 17 00:00:00 2001
From: Junjie <DELL@qq.com>
Date: 星期二, 06 一月 2026 09:12:34 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/core/network/real/ZyDualCrnRealConnect.java | 233 ++++++++++++++++++++++++++--------------------------------
1 files changed, 104 insertions(+), 129 deletions(-)
diff --git a/src/main/java/com/zy/core/network/real/ZyDualCrnRealConnect.java b/src/main/java/com/zy/core/network/real/ZyDualCrnRealConnect.java
index e4762c6..debcdc4 100644
--- a/src/main/java/com/zy/core/network/real/ZyDualCrnRealConnect.java
+++ b/src/main/java/com/zy/core/network/real/ZyDualCrnRealConnect.java
@@ -8,8 +8,11 @@
import com.core.common.DateUtils;
import com.core.common.SpringUtils;
import com.zy.asrs.entity.BasCrnpOpt;
+import com.zy.asrs.entity.BasDualCrnp;
+import com.zy.asrs.entity.BasDualCrnpOpt;
import com.zy.asrs.entity.DeviceConfig;
import com.zy.asrs.service.BasCrnpOptService;
+import com.zy.asrs.service.BasDualCrnpOptService;
import com.zy.asrs.utils.Utils;
import com.zy.core.News;
import com.zy.core.cache.OutputQueue;
@@ -111,144 +114,116 @@
@Override
public CommandResponse sendCommand(DualCrnCommand command) {
CommandResponse response = new CommandResponse(false);
- // try {
- // if (null == command) {
- // News.error("鍙屽伐浣嶅爢鍨涙満鍐欏叆鍛戒护涓虹┖");
- // response.setMessage("鍙屽伐浣嶅爢鍨涙満鍐欏叆鍛戒护涓虹┖");
- // return response;
- // }
+ try {
+ if (null == command) {
+ News.error("鍙屽伐浣嶅爢鍨涙満鍐欏叆鍛戒护涓虹┖");
+ response.setMessage("鍙屽伐浣嶅爢鍨涙満鍐欏叆鍛戒护涓虹┖");
+ return response;
+ }
- // String address = "DB100.0";
- // if (command.getStation() == 1) {
- // //宸ヤ綅1
- // address = "DB100.0";
- // }else {
- // //宸ヤ綅2
- // address = "DB100.20";
- // }
+ String address = "DB100.0";
+ if (command.getStation() == 1) {
+ //宸ヤ綅1
+ address = "DB100.0";
+ }else {
+ //宸ヤ綅2
+ address = "DB100.18";
+ }
- // int writeAck = 0;
- // boolean ackResult = false;
- // do {
- // OperateResult resultAck = siemensNet.Write(address, (short) 0);
- // if (resultAck.IsSuccess) {
- // Thread.sleep(200);
- // OperateResultExOne<byte[]> resultRead = siemensNet.Read(address, (short) 2);
- // short ack = siemensNet.getByteTransform().TransInt16(resultRead.Content, 0);
- // if (ack != 0) {
- // writeAck++;
- // } else {
- // News.info("鍙屽伐浣嶅爢鍨涙満鍛戒护涓嬪彂[id:{}] >>>>> {}", command.getCrnNo(), "ack澶嶄綅瀹屾垚");
- // ackResult = true;
- // break;
- // }
- // }
- // } while (writeAck < 5);
+ String confirmAddress = "DB100.16";
+ if (command.getStation() == 1) {
+ //宸ヤ綅1
+ confirmAddress = "DB100.16";
+ }else {
+ //宸ヤ綅2
+ confirmAddress = "DB100.34";
+ }
- // if (!ackResult) {
- // response.setMessage("鍙屽伐浣嶅爢鍨涙満鍛戒护涓嬪彂[id:{}] >>>>> {}" + command.getCrnNo() + "ack澶嶄綅澶辫触");
- // return response;
- // }
+ short[] array = new short[9];
+ array[0] = command.getTaskNo().shortValue();
+ array[1] = command.getTaskMode().shortValue();
+ array[2] = command.getSourcePosX().shortValue();
+ array[3] = command.getSourcePosY().shortValue();
+ array[4] = command.getSourcePosZ().shortValue();
+ array[5] = command.getDestinationPosX().shortValue();
+ array[6] = command.getDestinationPosY().shortValue();
+ array[7] = command.getDestinationPosZ().shortValue();
+ array[8] = (short) 0;
- // short[] array = new short[10];
- // 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 = siemensNet.Write(address, array);
+ if (!result.IsSuccess) {
+ News.error("鍙屽伐浣嶅爢鍨涙満鍐欏叆鍫嗗灈鏈簆lc鏁版嵁澶辫触 ===>> [id:{}]", command.getCrnNo());
+ response.setMessage("鍙屽伐浣嶅爢鍨涙満鍐欏叆鍫嗗灈鏈簆lc鏁版嵁澶辫触");
+ return response;
+ }
- // OperateResult result = null;
- // int idx = 0;
- // do {
- // OperateResultExOne<byte[]> resultRead = siemensNet.Read(address, (short) 20);
- // if (resultRead.IsSuccess) {
- // if (command.getAckFinish() == 0) {
- // short taskNo = siemensNet.getByteTransform().TransInt16(resultRead.Content, 2);
- // short taskMode = siemensNet.getByteTransform().TransInt16(resultRead.Content, 4);
- // short sourcePosX = siemensNet.getByteTransform().TransInt16(resultRead.Content, 6);
- // short sourcePosY = siemensNet.getByteTransform().TransInt16(resultRead.Content, 8);
- // short sourcePosZ = siemensNet.getByteTransform().TransInt16(resultRead.Content, 10);
- // short destinationPosX = siemensNet.getByteTransform().TransInt16(resultRead.Content, 12);
- // short destinationPosY = siemensNet.getByteTransform().TransInt16(resultRead.Content, 14);
- // short destinationPosZ = siemensNet.getByteTransform().TransInt16(resultRead.Content, 16);
- // if (taskNo == 0 || taskMode == 0 || sourcePosX == 0 || sourcePosY == 0 || sourcePosZ == 0 || destinationPosX == 0 || destinationPosY == 0 || destinationPosZ == 0) {
- // result = siemensNet.Write(address, array);
- // } else {
- // break;
- // }
- // } else {
- // short ackFinish = siemensNet.getByteTransform().TransInt16(resultRead.Content, 0);
- // if (ackFinish != command.getAckFinish()) {
- // result = siemensNet.Write(address, array);
- // } else {
- // break;
- // }
- // }
- // }
- // idx++;
- // Thread.sleep(500);
- // } while (idx < 5);
+ int idx = 0;
+ do {
+ OperateResultExOne<byte[]> resultRead = siemensNet.Read(address, (short) 18);
+ if (resultRead.IsSuccess) {
+ short taskNo = siemensNet.getByteTransform().TransInt16(resultRead.Content, 2);
+ short taskMode = siemensNet.getByteTransform().TransInt16(resultRead.Content, 4);
+ short sourcePosX = siemensNet.getByteTransform().TransInt16(resultRead.Content, 6);
+ short sourcePosY = siemensNet.getByteTransform().TransInt16(resultRead.Content, 8);
+ short sourcePosZ = siemensNet.getByteTransform().TransInt16(resultRead.Content, 10);
+ short destinationPosX = siemensNet.getByteTransform().TransInt16(resultRead.Content, 12);
+ short destinationPosY = siemensNet.getByteTransform().TransInt16(resultRead.Content, 14);
+ short destinationPosZ = siemensNet.getByteTransform().TransInt16(resultRead.Content, 16);
+ if (taskNo == 0 || taskMode == 0 || sourcePosX == 0 || sourcePosY == 0 || sourcePosZ == 0 || destinationPosX == 0 || destinationPosY == 0 || destinationPosZ == 0) {
+ result = siemensNet.Write(address, array);
+ } else {
+ break;
+ }
+ }
+ idx++;
+ Thread.sleep(500);
+ } while (idx < 5);
- // if (command.getAckFinish() == 0) {
- // short commandFinish = 1;
- // int i = 0;
- // do {
- // OperateResultExOne<byte[]> resultRead = siemensNet.Read(address, (short) 4);
- // OperateResultExOne<byte[]> resultReadConfirm = siemensNet.Read(address + 18, (short) 2);
- // if (resultRead.IsSuccess && resultReadConfirm.IsSuccess) {
- // short taskNo = siemensNet.getByteTransform().TransInt16(resultRead.Content, 2);
- // short confirm = siemensNet.getByteTransform().TransInt16(resultReadConfirm.Content, 0);
- // if (taskNo != 0 && confirm == 0) {
- // result = siemensNet.Write(address + 18, commandFinish);
- // }
- // }
- // i++;
- // Thread.sleep(500);
- // } while (i < 5);
- // }
+ OperateResult confirmResult = siemensNet.Write(confirmAddress, (short) 1);
+ if (!confirmResult.IsSuccess) {
+ News.error("鍙屽伐浣嶅爢鍨涙満鍐欏叆纭鏁版嵁澶辫触 ===>> [id:{}]", command.getCrnNo());
+ response.setMessage("鍙屽伐浣嶅爢鍨涙満鍐欏叆纭鏁版嵁澶辫触");
+ return response;
+ }
- // if (result != null && result.IsSuccess) {
- // News.info("SiemensDualCrn 鍙屽伐浣嶅爢鍨涙満鍛戒护涓嬪彂[id:{}] >>>>> {}", command.getCrnNo(), JSON.toJSON(command));
- // OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆慬id:{1}] >>>>> 鍛戒护涓嬪彂锛� {2}", DateUtils.convert(new Date()), command.getCrnNo(), JSON.toJSON(command)));
- // response.setResult(true);
- // response.setMessage("鍛戒护涓嬪彂鎴愬姛");
- // } else {
- // News.error("SiemensDualCrn 鍙屽伐浣嶅爢鍨涙満鍐欏叆鍫嗗灈鏈簆lc鏁版嵁澶辫触 ===>> [id:{}]", command.getCrnNo());
- // OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆戝啓鍏ュ爢鍨涙満plc鏁版嵁澶辫触 ===>> [id:{1}]", DateUtils.convert(new Date()), command.getCrnNo()));
- // response.setResult(false);
- // response.setMessage("鍛戒护涓嬪彂澶辫触");
- // }
+ if (result != null && result.IsSuccess) {
+ News.info("鍙屽伐浣嶅爢鍨涙満鍛戒护涓嬪彂[id:{}] >>>>> {}", command.getCrnNo(), JSON.toJSON(command));
+ OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆慬id:{1}] >>>>> 鍛戒护涓嬪彂锛� {2}", DateUtils.convert(new Date()), command.getCrnNo(), JSON.toJSON(command)));
+ response.setResult(true);
+ response.setMessage("鍛戒护涓嬪彂鎴愬姛");
+ } else {
+ News.error("鍙屽伐浣嶅爢鍨涙満鍐欏叆鍫嗗灈鏈簆lc鏁版嵁澶辫触 ===>> [id:{}]", command.getCrnNo());
+ OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆戝啓鍏ュ爢鍨涙満plc鏁版嵁澶辫触 ===>> [id:{1}]", DateUtils.convert(new Date()), command.getCrnNo()));
+ response.setResult(false);
+ response.setMessage("鍛戒护涓嬪彂澶辫触");
+ }
- // return response;
- // } catch (Exception e) {
- // e.printStackTrace();
- // }finally {
- // String sourceLocNo = Utils.getLocNo(command.getSourcePosX(), command.getSourcePosY(), command.getSourcePosZ());
- // String targetLocNo = Utils.getLocNo(command.getDestinationPosX(), command.getDestinationPosY(), command.getDestinationPosZ());
+ return response;
+ } catch (Exception e) {
+ e.printStackTrace();
+ }finally {
+ String sourceLocNo = Utils.getLocNo(command.getSourcePosX(), command.getSourcePosY(), command.getSourcePosZ());
+ String targetLocNo = Utils.getLocNo(command.getDestinationPosX(), command.getDestinationPosY(), command.getDestinationPosZ());
- // // 鏃ュ織璁板綍
- // BasCrnpOptService bean = SpringUtils.getBean(BasCrnpOptService.class);
- // BasCrnpOpt basCrnpOpt = new BasCrnpOpt(
- // command.getTaskNo().intValue(), // 浠诲姟鍙�
- // command.getCrnNo(), // 鍫嗗灈鏈篬闈炵┖]
- // new Date(), // 涓嬪彂鏃堕棿
- // String.valueOf(command.getTaskMode()), // 妯″紡
- // sourceLocNo, //婧愬簱浣�
- // targetLocNo, //鐩爣搴撲綅
- // null, // 淇敼鏃堕棿
- // null, // 淇敼浜哄憳
- // null, // 澶囨敞
- // JSON.toJSONString(command), // 鎸囦护
- // JSON.toJSONString(getStatus()), // 绯荤粺鐘舵��
- // 1, // 涓嬪彂鐘舵�亄0:鏈笅鍙�,1:宸蹭笅鍙憓
- // JSON.toJSONString(response) // 鍝嶅簲
- // );
- // bean.insert(basCrnpOpt);
- // }
+ // 鏃ュ織璁板綍
+ BasDualCrnpOptService bean = SpringUtils.getBean(BasDualCrnpOptService.class);
+ BasDualCrnpOpt basDualCrnp = new BasDualCrnpOpt(
+ command.getTaskNo(), // 浠诲姟鍙�
+ command.getCrnNo(), // 鍫嗗灈鏈篬闈炵┖]
+ new Date(), // 涓嬪彂鏃堕棿
+ String.valueOf(command.getTaskMode()), // 妯″紡
+ sourceLocNo, //婧愬簱浣�
+ targetLocNo, //鐩爣搴撲綅
+ null, // 淇敼鏃堕棿
+ null, // 淇敼浜哄憳
+ null, // 澶囨敞
+ JSON.toJSONString(command), // 鎸囦护
+ JSON.toJSONString(getStatus()), // 绯荤粺鐘舵��
+ 1, // 涓嬪彂鐘舵�亄0:鏈笅鍙�,1:宸蹭笅鍙憓
+ JSON.toJSONString(response) // 鍝嶅簲
+ );
+ bean.insert(basDualCrnp);
+ }
return response;
}
}
--
Gitblit v1.9.1