src/main/java/com/zy/core/thread/RgvThread.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/zy/core/thread/SteThread.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
src/main/java/com/zy/core/thread/RgvThread.java
@@ -48,6 +48,7 @@ * 工位2复位信号 */ private boolean resetFlag2 = false; private boolean connectRgv = false; public RgvThread(RgvSlave slave) { this.slave = slave; @@ -56,7 +57,31 @@ @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(); } /** * 任务下发 */ private void taskIssued() { while (true) { try { int step = 1; @@ -67,7 +92,7 @@ switch (step) { // 读数据 case 1: readStatus(); // readStatus(); break; //工位1写入数据 case 2: @@ -90,14 +115,54 @@ 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(1000); if(!connectRgv){ try { connectRgv = this.connect(); Thread.sleep(100); } 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 { 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(); } } } /** * 初始化RGV状态 */ 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,8 +52,30 @@ @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 { int step = 1; @@ -63,7 +86,7 @@ switch (step) { // 读数据 case 1: readStatus(); // readStatus(); break; // 写入数据 case 2: @@ -74,14 +97,55 @@ } // 心跳 // 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 { 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(); } } } /** * 初始化堆垛机状态 */