cpT
2025-07-01 52a57d1a6cd61009304656db35e50d4b9dbbda03
src/main/java/com/zy/core/thread/SiemensDevpThread.java
@@ -259,10 +259,10 @@
            } catch (Exception e) {
                connectDev = false;
                log.error("RGV数据读取线程异常!!! ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
                log.error("dev数据读取线程异常!!! ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
                try{
                    DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class);
                    deviceErrorService.addDeviceError("rgvErr", slave.getId(), "RGV数据读取线程异常"+e.getMessage());
                    deviceErrorService.addDeviceError("devErr", slave.getId(), "dev数据读取线程异常"+e.getMessage());
                } catch (Exception e2){
//                    log.error("e2:"+e2.getMessage());
                }
@@ -323,25 +323,36 @@
                }
            }
        }
        int[] staW = new int[]{1004,1014,1020};
        //条码
//        Thread.sleep(50);
        OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB400.100.0",(short) (barcodeSize*8));
        if (result2.IsSuccess) {
            for (int i = 0; i < barcodeSize; i++) {
                Integer siteId = staW[i]; // 站点编号
                StaProtocol staProtocol = station.get(siteId);
                if (null == staProtocol) {
                    staProtocol = new StaProtocol();
                    station.put(siteId, staProtocol);
                }
                String barcode = siemensS7Net.getByteTransform().TransString(result2.Content,i*8,6, "UTF-8");
                BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, i + 1);
                if(!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)) {
                    barcodeThread.setBarcode(barcode);
                    if (!barcode.equals("000000")){
                        staProtocol.setBarcodeNow(barcode);
                    }
                }
            }
        }
        //条码
//        Thread.sleep(50);
        int[] staW = new int[]{1004,1014,1020};
        OperateResultExOne<byte[]> result3 = siemensS7Net.Read("DB400.148.0",(short) (staW.length*4));
        OperateResultExOne<byte[]> resultErr = siemensS7Net.Read("DB101.922.0",(short) (staW.length*4));
        if (result3.IsSuccess) {
            for (int i = 0; i < staW.length; i++) {
                Integer siteId = staW[i]; // 站点编号
@@ -357,6 +368,19 @@
                staProtocol.setHighErr(status[2]);  // 高超限
                staProtocol.setLeftErr(status[3]);  // 左超限
                staProtocol.setRightErr(status[4]); // 右超限
                staProtocol.setWeightErr(status[5]); // 超重
                staProtocol.setBarcodeErr(status[6]); // 扫码失败
                if (resultErr.IsSuccess){
                    boolean[] statusErr = siemensS7Net.getByteTransform().TransBool(resultErr.Content, i*4 + 2, 2);
                    staProtocol.setErrOther1(statusErr[0]);  // 电路保护器断开
                    staProtocol.setErrOther1(statusErr[1]);  // 光电异常
                    staProtocol.setErrOther1(statusErr[2]);  // 运行超时
                    staProtocol.setErrOther1(statusErr[3]);  // 占位超时
                    staProtocol.setErrOther1(statusErr[4]);  // 有任务无货故障
                    staProtocol.setErrOther1(statusErr[5]);  // 变频器故障
                    staProtocol.setErrOther1(statusErr[6]);  // 接触器故障
                    staProtocol.setErrOther1(statusErr[7]);  // 顶升电机接触器故障
                }
            }
        }
@@ -386,12 +410,12 @@
                log.error("更新数据库数据失败 ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot());
            }
            try{
                DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class);
                deviceErrorService.deleteDeviceError("devp", slave.getId());
            } catch (Exception e){
//                log.error("e:"+e.getMessage());
            }
//            try{
//                DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class);
//                deviceErrorService.deleteDeviceError("devp", slave.getId());
//            } catch (Exception e){
////                log.error("e:"+e.getMessage());
//            }
        } else {
            OutputQueue.DEVP.offer(MessageFormat.format("【{0}】读取输送线plc状态信息失败 ===>> [id:{1}] [ip:{2}] [port:{3}] [rack:{4}] [slot:{5}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot()));
//            log.error("读取输送线plc状态信息失败 ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot());
@@ -410,6 +434,12 @@
        ArrayList<Integer> staNos = getStaNo();
        int index = staNos.indexOf(staProtocol.getSiteId());
        try{
            DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class);
            deviceErrorService.addDeviceError("devWrite", staProtocol.getSiteId(), "单站点写入:任务号:"+staProtocol.getWorkNo()+";目标站:"+staProtocol.getStaNo());
        } catch (Exception e2){
        }
//        //更新命令日志
//        CommandInfoLogService commandInfoLogService = SpringUtils.getBean(CommandInfoLogService.class);
@@ -461,19 +491,33 @@
                        OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入输送线命令后返回成功,但是读取任务值不一致。输送线plc编号={1},站点数据={2},写入次数={3}",
                                slave.getId(), JSON.toJSON(staProtocol),writeCount));
                        log.error("写入输送线命令后返回成功,但是读取任务值不一致。输送线plc编号={},{},写入次数={}", slave.getId(), JSON.toJSON(staProtocol), writeCount);
                        try{
                            DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class);
                            deviceErrorService.addDeviceError("devErr", staProtocol.getSiteId(), "写入次数"+writeCount+"写入后读取任务值不一致:"+"单站点写入:任务号:"+staProtocol.getWorkNo()+";目标站:"+staProtocol.getStaNo());
                        } catch (Exception e2){
                        }
                    }
                } else {
                    writeCount++;
                    OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入输送线命令后读取失败。输送线plc编号={1},站点数据={2},写入次数={3}",
                            slave.getId(), JSON.toJSON(staProtocol), writeCount));
                    log.error("写入输送线命令后读取失败。输送线plc编号={},站点数据={},写入次数={}", slave.getId(), JSON.toJSON(staProtocol), writeCount);
                    try{
                        DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class);
                        deviceErrorService.addDeviceError("devErr", staProtocol.getSiteId(), "写入次数"+writeCount+"写入输送线命令后读取失败:"+"单站点写入:任务号:"+staProtocol.getWorkNo()+";目标站:"+staProtocol.getStaNo());
                    } catch (Exception e2){
                    }
                }
            } else {
                writeCount++;
                OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入输送线命令失败。输送线plc编号={1},站点数据={2},写入次数={3}",
                        slave.getId(), JSON.toJSON(staProtocol),writeCount));
                log.error("写入输送线命令失败。输送线plc编号={},站点数据={},写入次数={}", slave.getId(), JSON.toJSON(staProtocol), writeCount);
                try{
                    DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class);
                    deviceErrorService.addDeviceError("devErr", staProtocol.getSiteId(), "写入次数"+writeCount+"写入输送线命令失败:"+"单站点写入:任务号:"+staProtocol.getWorkNo()+";目标站:"+staProtocol.getStaNo());
                } catch (Exception e2){
                }
                //更新指令日志
//                commandInfoLog.setDeviceLog("指令下发失败");
//                commandInfoLogService.insert(commandInfoLog);
@@ -489,7 +533,11 @@
            }
            OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入输送线命令尝试5次失败。输送线plc编号={1},站点数据={2}", slave.getId(), JSON.toJSON(staProtocol)));
            log.error("写入输送线命令尝试5次失败。输送线plc编号={},站点数据={}", slave.getId(), JSON.toJSON(staProtocol));
            try{
                DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class);
                deviceErrorService.addDeviceError("devErr", staProtocol.getSiteId(), "写入次数"+writeCount+"写入输送线命令尝试5次失败:"+"单站点写入:任务号:"+staProtocol.getWorkNo()+";目标站:"+staProtocol.getStaNo());
            } catch (Exception e2){
            }
            //重新添加数据到任务队列
            boolean result = MessageQueue.offer(SlaveType.Devp, slave.getId(), new Task(2, staProtocol));
            read();//读取1次设备状态