From b256cdb895234a3e68da88310325b5eb38600777 Mon Sep 17 00:00:00 2001
From: Administrator <1051256694@qq.com>
Date: 星期一, 16 三月 2026 10:27:56 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/core/network/real/ZyStationRealConnect.java | 66 +++++++++++++++-----------------
1 files changed, 31 insertions(+), 35 deletions(-)
diff --git a/src/main/java/com/zy/core/network/real/ZyStationRealConnect.java b/src/main/java/com/zy/core/network/real/ZyStationRealConnect.java
index fe83d45..1256513 100644
--- a/src/main/java/com/zy/core/network/real/ZyStationRealConnect.java
+++ b/src/main/java/com/zy/core/network/real/ZyStationRealConnect.java
@@ -184,56 +184,52 @@
@Override
public CommandResponse sendCommand(Integer deviceNo, StationCommand command) {
CommandResponse commandResponse = new CommandResponse(false);
- if (null == command) {
- commandResponse.setMessage("鍛戒护涓虹┖");
- return commandResponse;
- }
+ try {
+ if (null == command) {
+ commandResponse.setMessage("鍛戒护涓虹┖");
+ return commandResponse;
+ }
- int index = findIndex(command.getStationId());
- if (index < 0) {
- commandResponse.setMessage("绔欑偣涓嶅瓨鍦�");
- return commandResponse;
- }
+ int index = findIndex(command.getStationId());
+ if (index < 0) {
+ commandResponse.setMessage("绔欑偣涓嶅瓨鍦�");
+ return commandResponse;
+ }
- OperateResult write = null;
- OperateResult write1 = null;
- // 浠诲姟涓嬪彂娆℃暟
- int writeCount = 0;
- do {
+ boolean commandSendResult = false;
+ // 浠诲姟涓嬪彂娆℃暟
+ int writeCount = 0;
+ do {
// short[] data = new short[2];
// data[0] = command.getTaskNo();
// data[1] = command.getTargetStaNo().shortValue();
- write = siemensNet.Write("DB100." + index * 6, command.getTaskNo());
- write1 =siemensNet.Write("DB100." + (index * 6+4), command.getTargetStaNo().shortValue());
- if (write.IsSuccess&&write1.IsSuccess) {
- log.error("鍐欏叆杈撻�佺嚎鍛戒护鎴愬姛銆傜珯鐐圭紪鍙�={}锛岀珯鐐规暟鎹�={},鍐欏叆娆℃暟={}", command.getStationId(), JSON.toJSON(command),
- writeCount);
- commandResponse.setResult(true);
- break;
- } else {
+ OperateResult write = siemensNet.Write("DB100." + index * 6, command.getTaskNo());
+ OperateResult write1 = siemensNet.Write("DB100." + (index * 6 + 4), command.getTargetStaNo().shortValue());
+ if (write.IsSuccess && write1.IsSuccess) {
+ commandSendResult = true;
+ break;
+ }
writeCount++;
+ Thread.sleep(300);
+ } while (writeCount < 5);
+
+ if(!commandSendResult) {
log.error("鍐欏叆杈撻�佺嚎鍛戒护澶辫触銆傜珯鐐圭紪鍙�={}锛岀珯鐐规暟鎹�={},鍐欏叆娆℃暟={}", command.getStationId(), JSON.toJSON(command),
writeCount);
- commandResponse.setResult(false);
+ commandResponse.setMessage("鍐欏叆鍛戒护澶辫触");
+ return commandResponse;
}
- } while (writeCount < 5);
- if (write == null) {
- commandResponse.setMessage("鍐欏叆鍛戒护澶辫触");
- return commandResponse;
- }
-
- if (!write.IsSuccess) {
- ZyStationStatusEntity staProtocol = findStatusEntity(command.getStationId());
- OutputQueue.DEVP.offer(MessageFormat.format("鍐欏叆杈撻�佺嚎绔欑偣鏁版嵁澶辫触銆傜珯鐐圭紪鍙�={1}锛岀珯鐐规暟鎹�={2}", command.getStationId(),
- JSON.toJSON(staProtocol)));
- News.error("鍐欏叆杈撻�佺嚎绔欑偣鏁版嵁澶辫触銆傜珯鐐圭紪鍙�={}锛岀珯鐐规暟鎹�={}", command.getStationId(), JSON.toJSON(staProtocol));
- } else {
OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆� 杈撻�佺嚎鍛戒护涓嬪彂 [id:{1}] >>>>> {2}",
DateUtils.convert(new Date()), command.getStationId(), JSON.toJSON(command)));
News.info("杈撻�佺嚎鍛戒护涓嬪彂 [id:{}] >>>>> 鍛戒护涓嬪彂锛� {}", command.getStationId(),
JSON.toJSON(command));
+ commandResponse.setResult(true);
+ commandResponse.setMessage("鍛戒护涓嬪彂鎴愬姛");
+ return commandResponse;
+ } catch (Exception e) {
+ e.printStackTrace();
}
return commandResponse;
}
--
Gitblit v1.9.1