From 23b4e7942a8524ed1e89d93c55a470f0dc263d5a Mon Sep 17 00:00:00 2001 From: lsh <lsh@163.com> Date: 星期五, 06 六月 2025 13:54:01 +0800 Subject: [PATCH] * --- src/main/java/com/zy/core/thread/SteThread.java | 95 ++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 88 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/zy/core/thread/SteThread.java b/src/main/java/com/zy/core/thread/SteThread.java index 4b538c2..ccc3c7c 100644 --- a/src/main/java/com/zy/core/thread/SteThread.java +++ b/src/main/java/com/zy/core/thread/SteThread.java @@ -44,6 +44,7 @@ private SteProtocol steProtocol; private short heartBeatVal = 1; private boolean resetFlag = false; + private boolean connectSte = false; public SteThread(SteSlave slave) { this.slave = slave; @@ -51,10 +52,40 @@ @Override @SuppressWarnings("InfiniteLoopStatement") - public void run() { - this.connect(); + public void run() { connectSte = this.connect(); + while(!connectSte){ + try { + connectSte = this.connect(); + Thread.sleep(100); + } catch (Exception e){ + + } + } + + // 鍚姩绾跨▼鑷姩閲嶈繛 + new Thread(this::steConnect).start(); + + // 鍚姩璇绘暟鎹嚎绋� + new Thread(this::readStatusSte).start(); + + // 鍚姩浠诲姟涓嬪彂绾跨▼ + new Thread(this::taskIssued).start(); + } + + /** + * 浠诲姟涓嬪彂 + */ + private void taskIssued() { while (true) { try { + if(!connectSte){ + try { + Thread.sleep(1000L); + } catch (Exception e){ + + } + continue; + } int step = 1; Task task = MessageQueue.poll(SlaveType.Ste, slave.getId()); if (task != null) { @@ -63,7 +94,7 @@ switch (step) { // 璇绘暟鎹� case 1: - readStatus(); +// readStatus(); break; // 鍐欏叆鏁版嵁 case 2: @@ -74,12 +105,62 @@ } // 蹇冭烦 // heartbeat(); - Thread.sleep(500); + Thread.sleep(50); } catch (Exception e) { - e.printStackTrace(); + log.error("STE鍐欑嚎绋嬪紓甯�"+e.getMessage()); + +// e.printStackTrace(); } } + } + + private void steConnect() { + while (true) { + try { + Thread.sleep(1000); + if(!connectSte){ + try { + connectSte = this.connect(); + Thread.sleep(100); + } catch (Exception e){ + + } + } + } catch (Exception e) { + log.error("ste杩炴帴澶辫触锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); + initSte(); +// e.printStackTrace(); + } + } + } + + private void readStatusSte() { + while (true) { + try { + if(!connectSte){ + try { + Thread.sleep(1000L); + } catch (Exception e){ + + } + initSte(); + continue; + } + Thread.sleep(50); +// System.out.println("璇荤嚎绋�"+ slave.getId()); + + readStatus(); + + } catch (Exception e) { + log.error("ste鏁版嵁璇诲彇绾跨▼寮傚父锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); + + initSte(); +// e.printStackTrace(); + } + + } + } /** @@ -155,8 +236,8 @@ boolean[] status2 = siemensS7Net.getByteTransform().TransBool(result.Content, 27, 1); - steProtocol.setChargeStatus(status[0]?(short)1:(short)0); - steProtocol.setTrack(status[1]?(short)1:(short)0); + steProtocol.setChargeStatus(status2[0]?(short)1:(short)0); + steProtocol.setTrack(status2[1]?(short)1:(short)0); // steProtocol.setLoad(status2[6]?(short)1:(short)0); steProtocol.setLoad(status2[7]?(short)1:(short)0); -- Gitblit v1.9.1