| | |
| | | private ZyRgvConnectDriver zyRgvConnectDriver; |
| | | private RgvProtocol rgvProtocol; |
| | | private int deviceLogCollectTime = 200; |
| | | private volatile boolean closed = false; |
| | | private Thread mainThread; |
| | | |
| | | public ZyRgvThread(DeviceConfig deviceConfig, RedisUtil redisUtil) { |
| | | this.deviceConfig = deviceConfig; |
| | |
| | | public void run() { |
| | | connect(); |
| | | initRgv(); |
| | | while (!Thread.currentThread().isInterrupted()) { |
| | | mainThread = Thread.currentThread(); |
| | | while (!closed && !Thread.currentThread().isInterrupted()) { |
| | | try { |
| | | deviceLogCollectTime = Utils.getDeviceLogCollectTime(); |
| | | int step = 1; |
| | |
| | | break; |
| | | } |
| | | Thread.sleep(200); |
| | | } catch (InterruptedException ie) { |
| | | Thread.currentThread().interrupt(); |
| | | break; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | |
| | | @Override |
| | | public boolean connect() { |
| | | zyRgvConnectDriver = new ZyRgvConnectDriver(deviceConfig); |
| | | new Thread(zyRgvConnectDriver).start(); |
| | | zyRgvConnectDriver.start(); |
| | | DeviceConnectPool.put(SlaveType.Rgv, deviceConfig.getDeviceNo(), zyRgvConnectDriver); |
| | | return true; |
| | | } |
| | |
| | | |
| | | @Override |
| | | public void close() { |
| | | zyRgvConnectDriver.close(); |
| | | closed = true; |
| | | Thread t = mainThread; |
| | | if (t != null) { |
| | | try { t.interrupt(); } catch (Exception ignore) {} |
| | | } |
| | | if (zyRgvConnectDriver != null) { |
| | | zyRgvConnectDriver.close(); |
| | | } |
| | | } |
| | | |
| | | @Override |