#
Junjie
5 天以前 5e4345b5903010cbd63bb7edad3bbce479e2b57d
src/main/java/com/zy/core/thread/impl/ZySiemensCrnThread.java
@@ -12,7 +12,6 @@
import com.zy.asrs.service.BasCrnpOptService;
import com.zy.asrs.utils.Utils;
import com.zy.common.utils.RedisUtil;
import com.zy.core.News;
import com.zy.core.cache.MessageQueue;
import com.zy.core.cache.OutputQueue;
import com.zy.core.enums.CrnTaskModeType;
@@ -44,9 +43,6 @@
    private ZyCrnConnectDriver zyCrnConnectDriver;
    private CrnProtocol crnProtocol;
    private int deviceLogCollectTime = 200;
    private boolean resetFlag = false;
    private volatile boolean closed = false;
    private Thread mainThread;
    public ZySiemensCrnThread(DeviceConfig deviceConfig, RedisUtil redisUtil) {
        this.deviceConfig = deviceConfig;
@@ -58,33 +54,39 @@
    public void run() {
        this.connect();
        this.initCrn();
        mainThread = Thread.currentThread();
        while (!closed && !Thread.currentThread().isInterrupted()) {
            try {
                deviceLogCollectTime = Utils.getDeviceLogCollectTime();
                int step = 1;
                Task task = MessageQueue.poll(SlaveType.Crn, 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("CrnThread Fail", e);
                }
                switch (step) {
                    case 1:
                        readStatus();
                        break;
                    case 2:
                        sendCommand((CrnCommand) 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.Crn, deviceConfig.getDeviceNo());
                    if (task != null) {
                        step = task.getStep();
                    }
                    if (step == 2) {
                        sendCommand((CrnCommand) task.getData());
                    }
                    Thread.sleep(100);
                } catch (Exception e) {
                    log.error("CrnProcess Fail", e);
                }
            }
        });
        processThread.start();
    }
    /**
@@ -105,13 +107,13 @@
        crnProtocol.setWalkPos(0);
        crnProtocol.setLoaded(0);
        crnProtocol.setAlarm(0);
        crnProtocol.setXSpeed(0);
        crnProtocol.setYSpeed(0);
        crnProtocol.setZSpeed(0);
        crnProtocol.setXDistance(0);
        crnProtocol.setYDistance(0);
        crnProtocol.setXDuration(0);
        crnProtocol.setYDuration(0);
        crnProtocol.setXSpeed(0D);
        crnProtocol.setYSpeed(0D);
        crnProtocol.setZSpeed(0D);
        crnProtocol.setXDistance(0D);
        crnProtocol.setYDistance(0D);
        crnProtocol.setXDuration(0D);
        crnProtocol.setYDuration(0D);
    }
    @Override
@@ -155,20 +157,6 @@
        crnProtocol.setYDuration(crnStatus.getYDuration());
        OutputQueue.CRN.offer(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功",DateUtils.convert(new Date()), deviceConfig.getDeviceNo()));
//        // 复位信号
//        if (!Cools.isEmpty(crnProtocol.getStatusType()) && crnProtocol.getStatusType().equals(CrnStatusType.WAITING)) {
//            if (resetFlag) {
//                if(crnProtocol.getTaskNo()==9999){
//                    backHpFlag = false;
//                }
//                CrnCommand crnCommand = new CrnCommand();
//                crnCommand.setAckFinish((short)1);
//                if (write(crnCommand)) {
//                    resetFlag = false;
//                }
//            }
//        }
        if (crnProtocol.getAlarm() > 0) {
            crnProtocol.setLastCommandTime(-1L);
@@ -216,11 +204,6 @@
    @Override
    public void close() {
        closed = true;
        Thread t = mainThread;
        if (t != null) {
            try { t.interrupt(); } catch (Exception ignore) {}
        }
        if (zyCrnConnectDriver != null) {
            zyCrnConnectDriver.close();
        }