From 59b45c1c24ad7ca63902813b86705d7c460fa505 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期一, 16 三月 2026 08:51:34 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/core/network/real/ZyStationRealConnect.java | 73 ++++++++++++++++++------------------
1 files changed, 37 insertions(+), 36 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 8f7ffca..38ea3ee 100644
--- a/src/main/java/com/zy/core/network/real/ZyStationRealConnect.java
+++ b/src/main/java/com/zy/core/network/real/ZyStationRealConnect.java
@@ -177,54 +177,55 @@
@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;
- // 浠诲姟涓嬪彂娆℃暟
- int writeCount = 0;
- do {
- short[] data = new short[2];
- data[0] = command.getTaskNo().shortValue();
- data[1] = command.getTargetStaNo().shortValue();
+ boolean commandSendResult = false;
+ // 浠诲姟涓嬪彂娆℃暟
+ int writeCount = 0;
+ do {
+ short[] data = new short[2];
+ data[0] = command.getTaskNo().shortValue();
+ data[1] = command.getTargetStaNo().shortValue();
- write = siemensNet.Write("DB100." + index * 4, data);
- if (write.IsSuccess) {
- log.error("鍐欏叆杈撻�佺嚎鍛戒护鎴愬姛銆傜珯鐐圭紪鍙�={}锛岀珯鐐规暟鎹�={},鍐欏叆娆℃暟={}", command.getStationId(), JSON.toJSON(command),
- writeCount);
- commandResponse.setResult(true);
- break;
- } else {
+ OperateResult write = siemensNet.Write("DB100." + index * 4, data);
+ if (write.IsSuccess) {
+ log.error("鍐欏叆杈撻�佺嚎鍛戒护鎴愬姛銆傜珯鐐圭紪鍙�={}锛岀珯鐐规暟鎹�={},鍐欏叆娆℃暟={}", command.getStationId(), JSON.toJSON(command),
+ writeCount);
+ commandSendResult = true;
+ break;
+ } else {
+ Thread.sleep(300);
+ }
+
writeCount++;
+ } 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