src/main/java/com/zy/core/ServerBootstrap.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/zy/core/thread/LedThread.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/resources/application.yml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
src/main/java/com/zy/core/ServerBootstrap.java
@@ -8,6 +8,7 @@ import com.zy.core.properties.SlaveProperties; import com.zy.core.thread.CrnThread; import com.zy.core.thread.DevpThread; import com.zy.core.thread.LedThread; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Async; @@ -88,6 +89,14 @@ // new Thread(barcodeThread).start(); // SlaveConnection.put(SlaveType.Barcode, barcode.getId(), barcodeThread); // } // 初始化LED线程 log.info("初始化LED线程..................................................."); for (Slave led : slaveProperties.getLed()) { LedThread ledThread = new LedThread(led); new Thread(ledThread).start(); SlaveConnection.put(SlaveType.Led, led.getId(), ledThread); } } src/main/java/com/zy/core/thread/LedThread.java
@@ -19,12 +19,21 @@ public class LedThread implements Runnable, ThreadHandler { private Slave slave; private Bx5GScreenClient screen; public LedThread(Slave slave) { this.slave = slave; try { Bx5GEnv.initial(3000); screen = new Bx5GScreenClient("MyScreen"); } catch (Exception e) { e.printStackTrace(); log.info("led连接构造器错误 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); } } @Override @SuppressWarnings("InfiniteLoopStatement") public void run() { connect(); while (true) { @@ -41,12 +50,23 @@ @Override public boolean connect() { return false; boolean connRes = false; try { connRes = screen.connect(slave.getIp(),slave.getPort()); } catch (Exception e) { e.printStackTrace(); } if (connRes) { log.info("led连接成功 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); } else { log.error("led连接失败!!! ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); } return connRes; } @Override public void close() { screen.disconnect(); } @@ -56,7 +76,6 @@ Bx5GScreenClient screen = new Bx5GScreenClient("MyScreen"); // 创建screen对象,用于对控制器进行访问,串口模式 // Bx5GScreenRS screen = new Bx5GScreenRS("MyScreen"); // 在对控制器交互之前,需要先与控制器建立连接 screen.connect("192.168.100.199",5005); src/main/resources/application.yml
@@ -117,11 +117,16 @@ id: 1 ip: 192.168.2.150 port: 51236 # LED # LED1 led[0]: id: 1 ip: 192.168.1.1 port: 8888 # LED2 led[1]: id: 2 ip: 192.168.1.1 port: 8888 # 磅称 scale[0]: id: 1