| | |
| | | |
| | | public DevpThread(Slave slave) { |
| | | this.slave = slave; |
| | | connect(); |
| | | } |
| | | |
| | | @Override |
| | | @SuppressWarnings("InfiniteLoopStatement") |
| | | public void run() { |
| | | connect(); |
| | | while (true) { |
| | | try { |
| | | int step = 1; |
| | |
| | | default: |
| | | break; |
| | | } |
| | | Thread.sleep(500); |
| | | Thread.sleep(400); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | |
| | | result = true; |
| | | log.info("输送线plc连接成功 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); |
| | | } else { |
| | | log.info("输送线plc连接失败!!! ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); |
| | | log.error("输送线plc连接失败!!! ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); |
| | | } |
| | | siemensS7Net.ConnectClose(); |
| | | return result; |
| | |
| | | |
| | | @Override |
| | | public void close() { |
| | | |
| | | siemensS7Net.ConnectClose(); |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | Slave slave = new Slave(); |
| | | slave.setIp("192.168.2.125"); |
| | | DevpThread devpThread = new DevpThread(slave); |
| | | devpThread.connect(); |
| | | devpThread.read(); |
| | | // 写 |
| | | StaProtocol staProtocol = devpThread.getStation().get(1); |
| | | staProtocol.setWorkNo((short) 9999); |
| | | staProtocol.setStaNo((short) 100); |
| | | staProtocol.setAutoing(false); |
| | | staProtocol.setEmptyMk(false); |
| | | staProtocol.setWorkNo((short) 232); |
| | | staProtocol.setStaNo((short) 6); |
| | | staProtocol.setAutoing(true); |
| | | staProtocol.setEmptyMk(true); |
| | | staProtocol.setInEnable(true); |
| | | devpThread.write(staProtocol); |
| | | System.out.println("----------------------------------------"); |
| | | // 读 |