#
Junjie
2025-12-17 96f987b030f4c961a985f07079ba12abd865fdb2
src/main/java/com/zy/core/thread/impl/ZySiemensCrnThread.java
@@ -45,6 +45,8 @@
    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;
@@ -56,7 +58,8 @@
    public void run() {
        this.connect();
        this.initCrn();
        while (true) {
        mainThread = Thread.currentThread();
        while (!closed && !Thread.currentThread().isInterrupted()) {
            try {
                deviceLogCollectTime = Utils.getDeviceLogCollectTime();
                int step = 1;
@@ -65,7 +68,6 @@
                    step = task.getStep();
                }
                switch (step) {
                    // 读数据
                    case 1:
                        readStatus();
                        break;
@@ -76,6 +78,9 @@
                        break;
                }
                Thread.sleep(200);
            } catch (InterruptedException ie) {
                Thread.currentThread().interrupt();
                break;
            } catch (Exception e) {
                e.printStackTrace();
            }
@@ -112,7 +117,7 @@
    @Override
    public boolean connect() {
        zyCrnConnectDriver = new ZyCrnConnectDriver(deviceConfig);
        new Thread(zyCrnConnectDriver).start();
        zyCrnConnectDriver.start();
        DeviceConnectPool.put(SlaveType.Crn, deviceConfig.getDeviceNo(), zyCrnConnectDriver);
        return true;
    }
@@ -124,7 +129,6 @@
        ZyCrnStatusEntity crnStatus = zyCrnConnectDriver.getStatus();
        if (crnStatus == null) {
            OutputQueue.CRN.offer(MessageFormat.format("【{0}】读取堆垛机plc状态信息失败 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), deviceConfig.getDeviceNo(), deviceConfig.getIp(), deviceConfig.getPort()));
            News.error("SiemensCrn"+" - 5"+" - 读取堆垛机plc状态信息失败 ===>> [id:{}] [ip:{}] [port:{}]", deviceConfig.getDeviceNo(), deviceConfig.getIp(), deviceConfig.getPort());
            return;
        }
@@ -188,7 +192,12 @@
            crnProtocol.setDeviceDataLog(System.currentTimeMillis());
        }
        BasCrnpService basCrnpService = SpringUtils.getBean(BasCrnpService.class);
        BasCrnpService basCrnpService = null;
        try {
            basCrnpService = SpringUtils.getBean(BasCrnpService.class);
        }catch (Exception e){
        }
        if (basCrnpService != null) {
            BasCrnp basCrnp = basCrnpService.selectOne(new EntityWrapper<BasCrnp>().eq("crn_no", deviceConfig.getDeviceNo()));
            if(basCrnp == null) {
@@ -197,6 +206,8 @@
                basCrnp.setStatus(1);
                basCrnp.setInEnable("N");
                basCrnp.setOutEnable("N");
                basCrnp.setMaxInTask(5);
                basCrnp.setMaxOutTask(5);
                basCrnp.setCreateTime(new Date());
                basCrnpService.insert(basCrnp);
            }
@@ -205,7 +216,14 @@
    @Override
    public void close() {
        zyCrnConnectDriver.close();
        closed = true;
        Thread t = mainThread;
        if (t != null) {
            try { t.interrupt(); } catch (Exception ignore) {}
        }
        if (zyCrnConnectDriver != null) {
            zyCrnConnectDriver.close();
        }
    }
    @Override