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 | 178 +++++++++++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 161 insertions(+), 17 deletions(-)
diff --git a/src/main/java/com/zy/core/thread/RgvThread.java b/src/main/java/com/zy/core/thread/RgvThread.java
index db19743..6f98c45 100644
--- a/src/main/java/com/zy/core/thread/RgvThread.java
+++ b/src/main/java/com/zy/core/thread/RgvThread.java
@@ -11,6 +11,7 @@
import com.zy.asrs.entity.BasRgvOpt;
import com.zy.asrs.service.BasRgvOptService;
import com.zy.asrs.service.BasRgvService;
+import com.zy.asrs.utils.RouteUtils;
import com.zy.core.ThreadHandler;
import com.zy.core.cache.MessageQueue;
import com.zy.core.cache.OutputQueue;
@@ -46,6 +47,7 @@
* 宸ヤ綅2澶嶄綅淇″彿
*/
private boolean resetFlag2 = false;
+ private boolean connectRgv = false;
public RgvThread(RgvSlave slave) {
this.slave = slave;
@@ -54,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) {
@@ -65,11 +110,19 @@
switch (step) {
// 璇绘暟鎹�
case 1:
- readStatus();
+// readStatus();
break;
- // 鍐欏叆鏁版嵁
+ // 宸ヤ綅1銆�2鍐欏叆鏁版嵁
case 2:
write((RgvCommand) task.getData());
+ break;
+ //宸ヤ綅1鍐欏叆鏁版嵁
+ case 4:
+ write1((RgvCommand) task.getData());
+ break;
+ //宸ヤ綅2鍐欏叆鏁版嵁
+ case 5:
+ write2((RgvCommand) task.getData());
break;
// 澶嶄綅
case 3:
@@ -91,15 +144,103 @@
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();
+ if (null == commandAvoidanceXY) {
+ commandAvoidanceXY = new RgvCommand();
+ }
+ commandAvoidanceXY.setRgvNo(slave.getId()); // RGV缂栧彿
+ commandAvoidanceXY.setTaskNo1((short) 32222); // 宸ヤ綔鍙�
+ commandAvoidanceXY.setAckFinish1((short) 1); // 浠诲姟瀹屾垚纭浣�
+ commandAvoidanceXY.setTaskMode1(RgvTaskModeType.X_MOVE); // 浠诲姟妯″紡
+ commandAvoidanceXY.setSourceStaNo1((short)0); // 婧愮珯
+ commandAvoidanceXY.setDestinationStaNo1(slave.getId()==1? (short) 101:(short)116); // 鐩爣绔�
+ commandAvoidanceXY.setTaskNo2((short) 0); // 宸ヤ綔鍙�
+ commandAvoidanceXY.setAckFinish2((short) 1); // 浠诲姟瀹屾垚纭浣�
+ commandAvoidanceXY.setTaskMode2(RgvTaskModeType.X_MOVE); // 浠诲姟妯″紡
+ commandAvoidanceXY.setSourceStaNo2((short)0); // 婧愮珯
+ commandAvoidanceXY.setDestinationStaNo2(slave.getId()==1? (short) 101:(short)117); // 鐩爣绔�
+ commandAvoidanceXY.setCommand((short)0);
+ write(commandAvoidanceXY);
+ break;
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();
+ }
+
+ }
+
}
/**
@@ -161,7 +302,7 @@
rgvProtocol.setTaskNo1(siemensNet.getByteTransform().TransInt16(result.Content, 4));
rgvProtocol.setStatus1(siemensNet.getByteTransform().TransInt16(result.Content, 6));
rgvProtocol.setLoaded1(siemensNet.getByteTransform().TransInt16(result.Content, 8));
- rgvProtocol.setRgvPos(siemensNet.getByteTransform().TransInt16(result.Content, 10));
+ rgvProtocol.setRgvPos(RouteUtils.RgvPosSta(slave.getId(),siemensNet.getByteTransform().TransInt16(result.Content, 10)));
rgvProtocol.setWalkPos(siemensNet.getByteTransform().TransInt16(result.Content, 12));
rgvProtocol.setTaskNo2(siemensNet.getByteTransform().TransInt16(result.Content, 14));
rgvProtocol.setStatus2(siemensNet.getByteTransform().TransInt16(result.Content, 16));
@@ -180,7 +321,8 @@
OutputQueue.RGV.offer(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛",DateUtils.convert(new Date()), slave.getId()));
// 宸ヤ綅1澶嶄綅淇″彿
- if (rgvProtocol.getStatusType1().equals(RgvStatusType.WAITING)) {
+ if (rgvProtocol.getStatusType1().equals(RgvStatusType.WAITING)
+ || rgvProtocol.getStatusType1().equals(RgvStatusType.FETCHWAITING)) {
if (resetFlag1) {
RgvCommand rgvCommand = new RgvCommand();
rgvCommand.setAckFinish1((short)1);
@@ -191,7 +333,8 @@
}
// 宸ヤ綅2澶嶄綅淇″彿
- if (rgvProtocol.getStatusType2().equals(RgvStatusType.WAITING)) {
+ if (rgvProtocol.getStatusType2().equals(RgvStatusType.WAITING)
+ || rgvProtocol.getStatusType2().equals(RgvStatusType.FETCHWAITING)) {
if (resetFlag2) {
RgvCommand rgvCommand = new RgvCommand();
rgvCommand.setAckFinish2((short)1);
@@ -207,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());
}
@@ -297,15 +441,16 @@
return false;
}
- siemensNet.Write("DB100.20", command.getCommand());
+// siemensNet.Write("DB100.20", command.getCommand());
command.setRgvNo(slave.getId());
short[] array = new short[5];
array[0] = command.getAckFinish1();
array[1] = command.getTaskNo1();
- array[2] = command.getTaskMode1();
+ array[2] = command.getTaskMode1();//浠诲姟妯″紡
array[3] = command.getSourceStaNo1();
array[4] = command.getDestinationStaNo1();
+// siemensNet.Write("DB100.20", 0);
OperateResult result = siemensNet.Write("DB100.0", array);
@@ -357,15 +502,14 @@
return false;
}
- siemensNet.Write("DB100.20", command.getCommand());
-
command.setRgvNo(slave.getId());
- short[] array = new short[5];
- array[0] = command.getAckFinish2();
- array[1] = command.getTaskNo2();
- array[2] = command.getTaskMode2();
- array[3] = command.getSourceStaNo2();
- array[4] = command.getDestinationStaNo2();
+ short[] array = new short[6];
+ array[0] = command.getAckFinish2();//浠诲姟瀹屾垚纭浣�
+ array[1] = command.getTaskNo2();//浠诲姟鍙�
+ array[2] = command.getTaskMode2();//浠诲姟妯″紡
+ array[3] = command.getSourceStaNo2();//婧愮珯
+ array[4] = command.getDestinationStaNo2();//鐩爣绔�
+ array[5] = command.getCommand();//浠诲姟涓嬪彂纭
OperateResult result = siemensNet.Write("DB100.10", array);
--
Gitblit v1.9.1