*
lsh
9 天以前 9eecd47fa15543f72df06a3b8fb47c3db9e773c3
src/main/java/com/zy/core/thread/SiemensDevpThread.java
@@ -134,6 +134,9 @@
        add(696);add(697);add(698);add(699);
    }};
    private boolean connectDev = false;
    /**
     * 条码数量
     */
@@ -167,10 +170,85 @@
        }
    }
    /**
     * 初始化站点状态
     */
    private void initSite() {
        try{
            ArrayList<Integer> staNos = getStaNo();
            // 站点编号
            for (Integer siteId : staNos) {
                StaProtocol staProtocol = station.get(siteId);
                if (null == staProtocol) {
                    staProtocol = new StaProtocol();
                    staProtocol.setSiteId(siteId);
                    station.put(siteId, staProtocol);
                }
                staProtocol.setSiteId(siteId);
                staProtocol.setWorkNo(0);    // ID
                staProtocol.setAutoing(false);      // 自动
                staProtocol.setLoading(false);      // 有物
                staProtocol.setInEnable(false);     // 可入
                staProtocol.setOutEnable(false);    // 可出
                staProtocol.setEmptyMk(false);      // 空板信号
                staProtocol.setStaNo(0);     // 目标站
                if (!staProtocol.isPakMk() && !staProtocol.isLoading()) {
                    staProtocol.setPakMk(true);
                }
            }
        } catch (Exception e){
            try{
                log.error(e.getMessage());
            } catch (Exception e1){
            }
            log.error("初始化站点状态异常");
        }
    }
    @Override
    @SuppressWarnings("InfiniteLoopStatement")
    public void run() {
        connect();
        connectDev = connect();
        while(!connectDev){
            try {
                connectDev = this.connect();
                Thread.sleep(100);
            } catch (Exception e){
            }
        }
        // 启动线程自动重连
        new Thread(this::devConnect).start();
        new Thread(this::readStatusDev).start();
        new Thread(this::writeStatusDev).start();
    }
    private void devConnect() {
        while (true) {
            try {
                Thread.sleep(1000);
                if(!connectDev){
                    try {
                        connectDev = this.connect();
                        Thread.sleep(100);
                    } catch (Exception e){
                    }
                }
            } catch (Exception e) {
                log.info("dev连接失败 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
                initSite();
//                e.printStackTrace();
            }
        }
    }
    private void writeStatusDev() {
        while (true) {
            try {
                int step = 1;
@@ -181,7 +259,7 @@
                switch (step) {
                    // 读数据
                    case 1:
                        read();
//                        read();
                        break;
                    // 写数据 ID+目标站
                    case 2:
@@ -220,10 +298,33 @@
//                heartbeat();
                Thread.sleep(400);
            } catch (Exception e) {
                e.printStackTrace();
//                e.printStackTrace();
                try{
                    log.error(e.getMessage());
                } catch (Exception e1){
                }
                log.error("DEV数据写入线程异常!!! ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
            }
        }
    }
    private void readStatusDev() {
        while (true) {
            try {
                Thread.sleep(50);
                read();
            } catch (Exception e) {
                log.error("Dev数据读取线程异常!!! ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
                initSite();
            }
        }
    }
    @Override