From 75bd6db4408e4e7dd40e0ebcc7f6afa074dffbe6 Mon Sep 17 00:00:00 2001
From: L <L@132>
Date: 星期六, 12 七月 2025 15:25:14 +0800
Subject: [PATCH] *
---
src/main/java/com/zy/core/thread/RgvThread.java | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 116 insertions(+), 3 deletions(-)
diff --git a/src/main/java/com/zy/core/thread/RgvThread.java b/src/main/java/com/zy/core/thread/RgvThread.java
index 85d4e40..6f98c45 100644
--- a/src/main/java/com/zy/core/thread/RgvThread.java
+++ b/src/main/java/com/zy/core/thread/RgvThread.java
@@ -47,6 +47,7 @@
* 宸ヤ綅2澶嶄綅淇″彿
*/
private boolean resetFlag2 = false;
+ private boolean connectRgv = false;
public RgvThread(RgvSlave slave) {
this.slave = slave;
@@ -55,9 +56,52 @@
@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();
+
+
while (true) {
try {
+
+ Thread.sleep(500);
+ } catch (Exception e) {
+// e.printStackTrace();
+ }
+
+ }
+ }
+
+
+ /**
+ * 浠诲姟涓嬪彂
+ */
+ private void taskIssued() {
+ while (true) {
+ try {
+ if(!connectRgv){
+ try {
+ Thread.sleep(1000L);
+ } catch (Exception e){
+
+ }
+ continue;
+ }
int step = 1;
Task task = MessageQueue.poll(SlaveType.Rgv, slave.getId());
if (task != null) {
@@ -66,7 +110,7 @@
switch (step) {
// 璇绘暟鎹�
case 1:
- readStatus();
+// readStatus();
break;
// 宸ヤ綅1銆�2鍐欏叆鏁版嵁
case 2:
@@ -100,6 +144,26 @@
command.setCommand((short)0);
write(command);
break;
+ // 澶嶄綅
+ case 8:
+ RgvCommand command4 = (RgvCommand) task.getData();
+ if (null == command4) {
+ command4 = new RgvCommand();
+ }
+ command4.setRgvNo(slave.getId()); // RGV缂栧彿
+// command4.setTaskNo1((short) command4); // 宸ヤ綔鍙�
+ command4.setAckFinish1((short) 1); // 浠诲姟瀹屾垚纭浣�
+ command4.setTaskMode1(RgvTaskModeType.NONE); // 浠诲姟妯″紡
+ command4.setSourceStaNo1((short)0); // 婧愮珯
+ command4.setDestinationStaNo1((short)0); // 鐩爣绔�
+ command4.setTaskNo2((short) 0); // 宸ヤ綔鍙�
+ command4.setAckFinish2((short) 1); // 浠诲姟瀹屾垚纭浣�
+ command4.setTaskMode2(RgvTaskModeType.NONE); // 浠诲姟妯″紡
+ command4.setSourceStaNo2((short)0); // 婧愮珯
+ command4.setDestinationStaNo2((short)0); // 鐩爣绔�
+ command4.setCommand((short)0);
+ write(command4);
+ break;
// 鍥炲師鐐� 閬胯
case 9:
RgvCommand commandAvoidanceXY = (RgvCommand) task.getData();
@@ -123,12 +187,60 @@
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(1000L);
+ if(!connectRgv){
+ try {
+ connectRgv = this.connect();
+ Thread.sleep(100L);
+ } 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 {
+ if(!connectRgv){
+ try {
+ Thread.sleep(1000L);
+ } catch (Exception e){
+
+ }
+ continue;
+ }
+ 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();
+ }
+
+ }
+
}
/**
@@ -238,6 +350,7 @@
BasRgv basRgv = new BasRgv();
basRgv.setRgvNo(slave.getId());
basRgv.setRgvSts((int)rgvProtocol.getMode());
+ basRgv.setLoaded2(rgvProtocol.getLoaded2().intValue());
if (!basRgvService.updateById(rgvProtocol.toSqlModel(basRgv))){
log.error("RGV plc鏁版嵁搴撴洿鏂板け璐� ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot());
}
--
Gitblit v1.9.1