| | |
| | | package com.zy.core.network; |
| | | |
| | | import HslCommunication.Profinet.Siemens.SiemensS7Net; |
| | | import com.zy.asrs.entity.DeviceConfig; |
| | | import com.zy.core.ThreadHandler; |
| | | import com.zy.core.model.CommandResponse; |
| | |
| | | private boolean connected = false; |
| | | private DeviceConfig deviceConfig; |
| | | private ZyStationConnectApi zyStationConnectApi; |
| | | private volatile boolean closed = false; |
| | | private Thread selfThread; |
| | | |
| | | public ZyStationConnectDriver(DeviceConfig deviceConfig) { |
| | | this.deviceConfig = deviceConfig; |
| | |
| | | @Override |
| | | @SuppressWarnings("InfiniteLoopStatement") |
| | | public void run() { |
| | | while (!Thread.currentThread().isInterrupted()) { |
| | | selfThread = Thread.currentThread(); |
| | | while (!closed && !Thread.currentThread().isInterrupted()) { |
| | | try { |
| | | if (!connected) { |
| | | connect(); |
| | | } |
| | | Thread.sleep(1000); |
| | | } catch (InterruptedException ie) { |
| | | Thread.currentThread().interrupt(); |
| | | break; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | |
| | | |
| | | @Override |
| | | public void close() { |
| | | zyStationConnectApi.disconnect(); |
| | | zyStationConnectApi = null; |
| | | closed = true; |
| | | Thread t = selfThread; |
| | | if (t != null) { |
| | | try { t.interrupt(); } catch (Exception ignore) {} |
| | | } |
| | | if (zyStationConnectApi != null) { |
| | | zyStationConnectApi.disconnect(); |
| | | zyStationConnectApi = null; |
| | | } |
| | | connected = false; |
| | | } |
| | | |
| | | public void start() { |
| | | Thread t = new Thread(this); |
| | | t.start(); |
| | | } |
| | | |
| | | public List<ZyStationStatusEntity> getStatus() { |
| | |
| | | public CommandResponse sendCommand(StationCommand command) { |
| | | return zyStationConnectApi.sendCommand(command); |
| | | } |
| | | } |
| | | } |