From 9eecd47fa15543f72df06a3b8fb47c3db9e773c3 Mon Sep 17 00:00:00 2001 From: lsh <lsh@163.com> Date: 星期四, 29 五月 2025 16:21:04 +0800 Subject: [PATCH] * --- src/main/java/com/zy/core/thread/SiemensDevpThread.java | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 104 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/zy/core/thread/SiemensDevpThread.java b/src/main/java/com/zy/core/thread/SiemensDevpThread.java index db5ca80..efdafb7 100644 --- a/src/main/java/com/zy/core/thread/SiemensDevpThread.java +++ b/src/main/java/com/zy/core/thread/SiemensDevpThread.java @@ -134,6 +134,9 @@ add(696);add(697);add(698);add(699); }}; + private boolean connectDev = false; + + /** * 鏉$爜鏁伴噺 */ @@ -167,10 +170,85 @@ } } + + /** + * 鍒濆鍖栫珯鐐圭姸鎬� + */ + private void initSite() { + try{ + ArrayList<Integer> staNos = getStaNo(); + // 绔欑偣缂栧彿 + for (Integer siteId : staNos) { + StaProtocol staProtocol = station.get(siteId); + if (null == staProtocol) { + staProtocol = new StaProtocol(); + staProtocol.setSiteId(siteId); + station.put(siteId, staProtocol); + } + staProtocol.setSiteId(siteId); + staProtocol.setWorkNo(0); // ID + staProtocol.setAutoing(false); // 鑷姩 + staProtocol.setLoading(false); // 鏈夌墿 + staProtocol.setInEnable(false); // 鍙叆 + staProtocol.setOutEnable(false); // 鍙嚭 + staProtocol.setEmptyMk(false); // 绌烘澘淇″彿 + staProtocol.setStaNo(0); // 鐩爣绔� + + if (!staProtocol.isPakMk() && !staProtocol.isLoading()) { + staProtocol.setPakMk(true); + } + } + } catch (Exception e){ + try{ + log.error(e.getMessage()); + } catch (Exception e1){ + + } + log.error("鍒濆鍖栫珯鐐圭姸鎬佸紓甯�"); + } + } + @Override @SuppressWarnings("InfiniteLoopStatement") public void run() { - connect(); + connectDev = connect(); + while(!connectDev){ + try { + connectDev = this.connect(); + Thread.sleep(100); + } catch (Exception e){ + + } + } + + // 鍚姩绾跨▼鑷姩閲嶈繛 + new Thread(this::devConnect).start(); + new Thread(this::readStatusDev).start(); + new Thread(this::writeStatusDev).start(); + } + + private void devConnect() { + while (true) { + try { + Thread.sleep(1000); + + if(!connectDev){ + try { + connectDev = this.connect(); + Thread.sleep(100); + } catch (Exception e){ + + } + } + } catch (Exception e) { + log.info("dev杩炴帴澶辫触 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); + initSite(); +// e.printStackTrace(); + } + } + } + + private void writeStatusDev() { while (true) { try { int step = 1; @@ -181,7 +259,7 @@ switch (step) { // 璇绘暟鎹� case 1: - read(); +// read(); break; // 鍐欐暟鎹� ID+鐩爣绔� case 2: @@ -220,10 +298,33 @@ // heartbeat(); Thread.sleep(400); } catch (Exception e) { - e.printStackTrace(); +// e.printStackTrace(); + try{ + log.error(e.getMessage()); + } catch (Exception e1){ + + } + log.error("DEV鏁版嵁鍐欏叆绾跨▼寮傚父锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); + } } + + } + + private void readStatusDev() { + while (true) { + try { + Thread.sleep(50); + read(); + + } catch (Exception e) { + log.error("Dev鏁版嵁璇诲彇绾跨▼寮傚父锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); + initSite(); + } + + } + } @Override -- Gitblit v1.9.1