#
Junjie
6 天以前 f6046d2fc1503dc76fc06c51604b480664f532a3
src/main/java/com/zy/core/thread/impl/ZyRgvThread.java
@@ -40,8 +40,6 @@
    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;
@@ -53,33 +51,39 @@
    public void run() {
        connect();
        initRgv();
        mainThread = Thread.currentThread();
        while (!closed && !Thread.currentThread().isInterrupted()) {
            try {
                deviceLogCollectTime = Utils.getDeviceLogCollectTime();
                int step = 1;
                Task task = MessageQueue.poll(SlaveType.Rgv, deviceConfig.getDeviceNo());
                if (task != null) {
                    step = task.getStep();
        Thread readThread = new Thread(() -> {
            while (true) {
                try {
                    deviceLogCollectTime = Utils.getDeviceLogCollectTime();
                    readStatus();
                    Thread.sleep(100);
                } catch (Exception e) {
                    log.error("RgvThread Fail", e);
                }
                switch (step) {
                    case 1:
                        readStatus();
                        break;
                    case 2:
                        sendCommand((RgvCommand) task.getData());
                        break;
                    default:
                        break;
                }
                Thread.sleep(200);
            } catch (InterruptedException ie) {
                Thread.currentThread().interrupt();
                break;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        });
        readThread.start();
        Thread processThread = new Thread(() -> {
            while (true) {
                try {
                    int step = 1;
                    Task task = MessageQueue.poll(SlaveType.Rgv, deviceConfig.getDeviceNo());
                    if (task != null) {
                        step = task.getStep();
                    }
                    if (step == 2) {
                        sendCommand((RgvCommand) task.getData());
                    }
                    Thread.sleep(100);
                } catch (Exception e) {
                    log.error("RgvProcess Fail", e);
                }
            }
        });
        processThread.start();
    }
    private void initRgv() {
@@ -157,11 +161,6 @@
    @Override
    public void close() {
        closed = true;
        Thread t = mainThread;
        if (t != null) {
            try { t.interrupt(); } catch (Exception ignore) {}
        }
        if (zyRgvConnectDriver != null) {
            zyRgvConnectDriver.close();
        }