From 03879530a3a6b4258cc7fe7007e8dfe5368905a4 Mon Sep 17 00:00:00 2001
From: lsh <lsh@163.com>
Date: 星期二, 03 六月 2025 08:22:17 +0800
Subject: [PATCH] *
---
src/main/java/com/zy/core/thread/RgvThread.java | 83 +++++++++++++++++++++++++++++++++++++----
1 files changed, 74 insertions(+), 9 deletions(-)
diff --git a/src/main/java/com/zy/core/thread/RgvThread.java b/src/main/java/com/zy/core/thread/RgvThread.java
index 496ec77..ece3eeb 100644
--- a/src/main/java/com/zy/core/thread/RgvThread.java
+++ b/src/main/java/com/zy/core/thread/RgvThread.java
@@ -48,6 +48,7 @@
* 宸ヤ綅2澶嶄綅淇″彿
*/
private boolean resetFlag2 = false;
+ private boolean connectRgv = false;
public RgvThread(RgvSlave slave) {
this.slave = slave;
@@ -56,7 +57,31 @@
@Override
@SuppressWarnings("InfiniteLoopStatement")
public void run() {
- this.connect();
+ connectRgv = this.connect();
+ while(!connectRgv){
+ try {
+ connectRgv = this.connect();
+ Thread.sleep(100);
+ } catch (Exception e){
+
+ }
+ }
+
+ // 鍚姩绾跨▼鑷姩閲嶈繛
+ new Thread(this::rgvConnect).start();
+
+ // 鍚姩璇绘暟鎹嚎绋�
+ new Thread(this::readStatusRgv).start();
+
+ // 鍚姩浠诲姟涓嬪彂绾跨▼
+ new Thread(this::taskIssued).start();
+ }
+
+
+ /**
+ * 浠诲姟涓嬪彂
+ */
+ private void taskIssued() {
while (true) {
try {
int step = 1;
@@ -67,7 +92,7 @@
switch (step) {
// 璇绘暟鎹�
case 1:
- readStatus();
+// readStatus();
break;
//宸ヤ綅1鍐欏叆鏁版嵁
case 2:
@@ -90,12 +115,52 @@
default:
break;
}
- Thread.sleep(500);
+ Thread.sleep(100);
} catch (Exception e) {
+ log.error("RGV鍐欑嚎绋嬪紓甯�"+e.getMessage());
// e.printStackTrace();
}
}
+ }
+
+ private void rgvConnect() {
+ while (true) {
+ try {
+ Thread.sleep(1000);
+ if(!connectRgv){
+ try {
+ connectRgv = this.connect();
+ Thread.sleep(100);
+ } catch (Exception e){
+
+ }
+ }
+ } catch (Exception e) {
+
+ log.error("rgv杩炴帴澶辫触锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
+ initRgv();
+// e.printStackTrace();
+ }
+ }
+ }
+
+ private void readStatusRgv() {
+ while (true) {
+ try {
+ Thread.sleep(40);
+ readStatus();
+
+ } catch (Exception e) {
+ log.error("RGV璇荤嚎绋嬪紓甯�"+e.getMessage());
+
+ log.error("RGV鏁版嵁璇诲彇绾跨▼寮傚父锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
+ initRgv();
+// e.printStackTrace();
+ }
+
+ }
+
}
/**
@@ -223,7 +288,7 @@
if (command.getAckFinish1().equals((short)0)) {
// Thread.sleep(100L);
siemensNet.Write("DB24.10.7", command.getRgvSome() == 1);
- Thread.sleep(100L);
+ Thread.sleep(20L);
result = siemensNet.Write("DB24.10.0", true);
} else {
siemensNet.Write("DB24.10.1", true);
@@ -250,8 +315,8 @@
} catch (Exception ignore) {}
if (result != null && result.IsSuccess) {
- Thread.sleep(200);
- this.readStatus();
+// Thread.sleep(200);
+// this.readStatus();
log.info("RGV 宸ヤ綅1鍛戒护涓嬪彂[id:{}] >>>>> {}", slave.getId(), JSON.toJSONString(command));
OutputQueue.RGV.offer(MessageFormat.format("銆恵0}銆慬id:{1}] >>>>> 宸ヤ綅1鍛戒护涓嬪彂锛� {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSONString(command)));
return true;
@@ -281,7 +346,7 @@
// OperateResult result = siemensNet.Write("DB24.0", array);
OperateResult result = null;
if (command.getAckFinish1().equals((short)0)) {
- Thread.sleep(100L);
+ Thread.sleep(20L);
result = siemensNet.Write("DB24.10.0", true);
} else {
siemensNet.Write("DB24.10.1", true);
@@ -308,8 +373,8 @@
} catch (Exception ignore) {}
if (result != null && result.IsSuccess) {
- Thread.sleep(200);
- this.readStatus();
+// Thread.sleep(200);
+// this.readStatus();
log.info("RGV 宸ヤ綅1鍛戒护涓嬪彂[id:{}] >>>>> {}", slave.getId(), JSON.toJSONString(command));
OutputQueue.RGV.offer(MessageFormat.format("銆恵0}銆慬id:{1}] >>>>> 宸ヤ綅1鍛戒护涓嬪彂锛� {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSONString(command)));
return true;
--
Gitblit v1.9.1