From 507397970e1186f9b7c10c8252168ebc7fb7b38b Mon Sep 17 00:00:00 2001 From: L <L@132> Date: 星期日, 13 七月 2025 16:00:01 +0800 Subject: [PATCH] * --- src/main/java/com/zy/core/thread/RgvThread.java | 188 ++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 184 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/zy/core/thread/RgvThread.java b/src/main/java/com/zy/core/thread/RgvThread.java index d53239b..34d8055 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(); @@ -107,7 +171,7 @@ commandAvoidanceXY = new RgvCommand(); } commandAvoidanceXY.setRgvNo(slave.getId()); // RGV缂栧彿 - commandAvoidanceXY.setTaskNo1((short) 29999); // 宸ヤ綔鍙� + commandAvoidanceXY.setTaskNo1((short) 32222); // 宸ヤ綔鍙� commandAvoidanceXY.setAckFinish1((short) 1); // 浠诲姟瀹屾垚纭浣� commandAvoidanceXY.setTaskMode1(RgvTaskModeType.X_MOVE); // 浠诲姟妯″紡 commandAvoidanceXY.setSourceStaNo1((short)0); // 婧愮珯 @@ -120,15 +184,67 @@ commandAvoidanceXY.setCommand((short)0); write(commandAvoidanceXY); break; + // 宸ヤ綅1瀹屾垚銆�2鍐欏叆鏁版嵁 + case 10: + write10((RgvCommand) task.getData()); + 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(); + } + + } + } /** @@ -238,6 +354,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()); } @@ -319,6 +436,69 @@ } } + + /** + * 宸ヤ綅1瀹屾垚銆�2鍚屾椂鍐欏叆鏁版嵁 + */ + private boolean write10(RgvCommand command) throws InterruptedException { + if (null == command) { + log.error("RGV鍐欏叆鍛戒护涓虹┖"); + return false; + } +// convertRow(command); + command.setRgvNo(slave.getId()); + short[] array = new short[11]; + array[0] = command.getAckFinish1(); + array[1] = command.getTaskNo1(); + array[2] = command.getTaskMode1(); + array[3] = command.getSourceStaNo1(); + array[4] = command.getDestinationStaNo1(); + array[5] = command.getAckFinish2(); + array[6] = command.getTaskNo2(); + array[7] = command.getTaskMode2(); + array[8] = command.getSourceStaNo2(); + array[9] = command.getDestinationStaNo2(); + array[10] = command.getCommand(); + OperateResult result = siemensNet.Write("DB100.0", array); + + if (command.getAckFinish2() == 0) { + short commandFinish = 2; //宸ヤ綅2浠诲姟鍚屾椂鍐欏叆 + Thread.sleep(100L); + result = siemensNet.Write("DB100.20", commandFinish); + } + + try { + // 鏃ュ織璁板綍 + BasRgvOptService bean = SpringUtils.getBean(BasRgvOptService.class); + BasRgvOpt basRgvOpt = new BasRgvOpt( + command.getTaskNo1().intValue(), + command.getTaskNo2().intValue(), + command.getRgvNo(), + new Date(), + command.getTaskModeType1().toString(), + command.getSourceStaNo1().intValue(), + command.getDestinationStaNo1().intValue(), + command.getSourceStaNo2().intValue(), + command.getDestinationStaNo2().intValue(), + null, + new Date(), + null + ); + bean.insert(basRgvOpt); + } catch (Exception ignore) {} + + if (result != null && result.IsSuccess) { + Thread.sleep(200); + this.readStatus(); + log.info("RGV 鍛戒护涓嬪彂[id:{}] >>>>> {}", slave.getId(), JSON.toJSON(command)); + OutputQueue.RGV.offer(MessageFormat.format("銆恵0}銆慬id:{1}] >>>>> 鍛戒护涓嬪彂锛� {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command))); + return true; + } else { + OutputQueue.RGV.offer(MessageFormat.format("銆恵0}銆戝啓鍏GV plc鏁版嵁澶辫触 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort())); + log.error("鍐欏叆RGV plc鏁版嵁澶辫触 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); + return false; + } + } /** * 宸ヤ綅1鍐欏叆鏁版嵁 */ -- Gitblit v1.9.1