野心家
2025-05-23 d75bdc98e2bc456eecfa4003bf700cb701d52a9b
src/main/java/com/zy/core/thread/SiemensDevpThread.java
@@ -213,14 +213,37 @@
        //条码
        Thread.sleep(200);
        OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB101.840.0",(short) (barcodeSize*8));
        OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB400.100.0",(short) (barcodeSize*8));
        if (result2.IsSuccess) {
            for (int i = 0; i < barcodeSize; i++) {
                String barcode = siemensS7Net.getByteTransform().TransString(result2.Content,i*8,8, "UTF-8");
                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);
                }
            }
        }
        //条码
        Thread.sleep(200);
        int[] staW = new int[]{1004,1014,1020};
        OperateResultExOne<byte[]> result3 = siemensS7Net.Read("DB400.148.0",(short) (staW.length*4));
        if (result3.IsSuccess) {
            for (int i = 0; i < staW.length; i++) {
                Integer siteId = staW[i]; // 站点编号
                StaProtocol staProtocol = station.get(siteId);
                if (null == staProtocol) {
                    staProtocol = new StaProtocol();
                    station.put(siteId, staProtocol);
                }
                staProtocol.setSiteId(siteId);
                boolean[] status = siemensS7Net.getByteTransform().TransBool(result3.Content, i*4 + 2, 2);
                staProtocol.setFrontErr(status[0]);  // 前超限
                staProtocol.setBackErr(status[1]);  // 后超限
                staProtocol.setHighErr(status[2]);  // 高超限
                staProtocol.setLeftErr(status[3]);  // 左超限
                staProtocol.setRightErr(status[4]); // 右超限
            }
        }
@@ -235,19 +258,27 @@
                    StaProtocol staProtocol = station.get(siteId);
                    basDevps.add(staProtocol.toSqlModel());
                }
                BasDevpService basDevpService = SpringUtils.getBean(BasDevpService.class);
                if (null != basDevpService && !basDevpService.updateBatchById(basDevps)) {
                    throw new Exception("更新数据库数据失败");
                try{
                    BasDevpService basDevpService = SpringUtils.getBean(BasDevpService.class);
                    if (null != basDevpService && !basDevpService.updateBatchById(basDevps)) {
                        throw new Exception("更新数据库数据失败");
                    }
                } catch (Exception e){
                    log.error("e:"+e.getMessage());
                }
            } catch (Exception e) {
                e.printStackTrace();
                OutputQueue.DEVP.offer(MessageFormat.format("【{0}】更新数据库数据失败 ===>> [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("更新数据库数据失败 ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot());
            }
            DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class);
            deviceErrorService.deleteDeviceError("devp", slave.getId());
            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());