*
L
昨天 c3434b1fe0132372b34ff0a46d84e6129a094bfc
src/main/java/com/zy/core/thread/SiemensCrnThread.java
@@ -105,7 +105,7 @@
                    default:
                        break;
                }
                Thread.sleep(500);
                Thread.sleep(200);
            } catch (Exception e) {
//                e.printStackTrace();
            }
@@ -138,7 +138,11 @@
        crnProtocol.setyDistance((short) 0);
        crnProtocol.setxDuration((short) 0);
        crnProtocol.setyDuration((short) 0);
        CrnErrCache.updateCrnErr(crnProtocol.getCrnNo(), "离线");
        try{
            CrnErrCache.updateCrnErr(crnProtocol.getCrnNo(), "离线");
        } catch (Exception e1){
        }
    }
@@ -207,10 +211,12 @@
                            backHpFlag = false;
                        }
                        if (!Cools.isEmpty(crnProtocol.getLoaded()) && crnProtocol.getLoaded()!=0){
                        if (!Cools.isEmpty(crnProtocol.getLaneNo()) && crnProtocol.getLaneNo()!=0){
                            CrnCommand crnCommand = new CrnCommand();
                            crnCommand.setAckFinish((short)1);
//                            crnCommand.setTaskNo(crnProtocol.getTaskNo());
                            crnCommand.setLaneNo(crnProtocol.getLaneNo());
                            crnCommand.setTaskMode(CrnTaskModeType.NONE); // 任务模式
                            if (write(crnCommand)) {
                                resetFlag = false;
                            }
@@ -276,21 +282,20 @@
            log.error("堆垛机写入命令为空");
            return false;
        }
        CrnErrCache.updateCrnErr(slave.getId(), "-");
        try{
            DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class);
            deviceErrorService.addDeviceError("crnWrite", slave.getId(), "巷道号"+command.getLaneNo()+";堆垛机指令下发:"+JSON.toJSONString(command.getNowTask()));
        } catch (Exception e2){
            deviceErrorService.addDeviceError("crnWriteIng", slave.getId(), "巷道号"+command.getLaneNo()+";堆垛机待下发指令:"+JSON.toJSONString(command.getNowTask()));
        } catch (Exception e){
            log.error("crnWriteIng新增异常");
        }
        try{
            BasErrLogService basErrLogService = SpringUtils.getBean(BasErrLogService.class);
            BasErrLog basErrLog = new BasErrLog(command,"","任务下发记录");
            if (!basErrLogService.insert(basErrLog)) {
                log.error("堆垛机plc异常记录失败 ===>> [id:{}] [error:{}]", slave.getId(), "任务下发记录失败");
            }
        } catch (Exception e3){
            CrnErrCache.updateCrnErr(slave.getId(), "-");
        } catch (Exception e){
            log.error(JSON.toJSONString(e));
            log.error("堆垛机任务写异常:异常定位值:crnWrite-294行");
        }
//        convertRow(command);
        command.setCrnNo(slave.getId());
        short[] array = new short[10];
        array[0] = command.getAckFinish();
@@ -302,48 +307,94 @@
        array[6] = command.getDestinationPosX();
        array[7] = command.getDestinationPosY();
        array[8] = command.getDestinationPosZ();
        array[9] = command.getCommand();
//        array[9] = command.getCommand();
        array[9] = (short)0;
        log.info("堆垛机任务写100.18:值:0 crnWrite-313行");
        OperateResult result18 = siemensNet.Write("DB100.18", (short)0);
        if (command.getAckFinish() == 0) {
            log.info("堆垛机任务写100.0:值:0 crnWrite-317行");
            OperateResult result100 = siemensNet.Write("DB100.0", (short)0);
        }
        try{
            Thread.sleep(50L);
        } catch (Exception e){}
        } catch (Exception e){log.error("延时异常324行");}
        log.info("堆垛机任务写100.0:值:array crnWrite-317行;array:"+JSON.toJSONString(array));
        OperateResult result = siemensNet.Write("DB100.0", array);
        int i=0;
        do{
            i++;
            //堆垛机任务写入后,回读一次,看是否成功
            try{
                Thread.sleep(100L);
            } catch (Exception e){}
            OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB101.0", (short) 4);
            if (resultRead.IsSuccess) {
                CrnCommand one = new CrnCommand();
                one.setTaskNo(siemensNet.getByteTransform().TransInt16(resultRead.Content, 2));
                if (!command.getTaskNo().equals(one.getTaskNo())
                ){
                    i++;
                    CrnErrCache.updateCrnErr(slave.getId(), "堆垛机命令地址写入后回读失败");
                Thread.sleep(50L);
            } catch (Exception e){log.error("延时异常335行");}
                    log.error("堆垛机命令地址写入后回读失败[id:{}]>>>>重写[{}] >>>>> 写入[{}],===>>回读[{}]", slave.getId(), i,JSON.toJSON(command),JSON.toJSON(one));
            log.info("堆垛机任务读100.0:值:20 crnWrite-317行;");
            try{
                OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB100.0", (short) 20);
                if (resultRead.IsSuccess) {
                    CrnCommand one = new CrnCommand();
                    one.setTaskNo(siemensNet.getByteTransform().TransInt16(resultRead.Content, 2));
                    one.setTaskMode(siemensNet.getByteTransform().TransInt16(resultRead.Content, 4));
                    one.setSourcePosX(siemensNet.getByteTransform().TransInt16(resultRead.Content, 6));
                    one.setSourcePosY(siemensNet.getByteTransform().TransInt16(resultRead.Content, 8));
                    one.setSourcePosZ(siemensNet.getByteTransform().TransInt16(resultRead.Content, 10));
                    one.setDestinationPosX(siemensNet.getByteTransform().TransInt16(resultRead.Content, 12));
                    one.setDestinationPosY(siemensNet.getByteTransform().TransInt16(resultRead.Content, 14));
                    one.setDestinationPosZ(siemensNet.getByteTransform().TransInt16(resultRead.Content, 16));
                    if (!command.getTaskNo().equals(one.getTaskNo())
                            || !command.getTaskMode().equals(one.getTaskMode())
                            || !command.getSourcePosX().equals(one.getSourcePosX())
                            || !command.getSourcePosY().equals(one.getSourcePosY())
                            || !command.getSourcePosZ().equals(one.getSourcePosZ())
                            || !command.getDestinationPosX().equals(one.getDestinationPosX())
                            || !command.getDestinationPosY().equals(one.getDestinationPosY())
                            || !command.getDestinationPosZ().equals(one.getDestinationPosZ())
                    ){
                        CrnErrCache.updateCrnErr(slave.getId(), "堆垛机命令地址写入后回读失败");
                        log.error("堆垛机命令地址写入后回读失败[id:{}]>>>>重写[{}] >>>>> 写入[{}],===>>回读[{}]", slave.getId(), i,JSON.toJSON(command),JSON.toJSON(one));
                        try{
                            DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class);
                            deviceErrorService.addDeviceError("CrnErr", slave.getId(), "巷道号"+command.getLaneNo()+";写入次数"+i+";堆垛机命令地址写入后回读失败:"+JSON.toJSONString(command.getNowTask()));
                        } catch (Exception e2){
                        }
                        try{
                            BasErrLogService basErrLogService = SpringUtils.getBean(BasErrLogService.class);
                            BasErrLog basErrLog = new BasErrLog(command,"堆垛机命令地址写入后回读失败","");
                            if (!basErrLogService.insert(basErrLog)) {
                                log.error("堆垛机plc异常记录失败 ===>> [id:{}] [error:{}]", slave.getId(), "堆垛机命令地址写入后回读失败记录失败");
                            }
                        } catch (Exception e3){
                        }
                        result = siemensNet.Write("DB100.0", array);
                    }else{
                        try{
                            DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class);
                            deviceErrorService.addDeviceError("crnWrite", slave.getId(), "巷道号"+command.getLaneNo()+";堆垛机指令下发:"+JSON.toJSONString(command.getNowTask()));
                        } catch (Exception e2){
                        }
                        break;
                    }
                } else {
                    CrnErrCache.updateCrnErr(slave.getId(), "堆垛机命令读取失败");
                    log.error("堆垛机命令读取失败[id:{}]>>>>重写[{}] >>>>> 写入[{}],===>>回读[{}]", slave.getId(), i,JSON.toJSON(command),"");
                    try{
                        DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class);
                        deviceErrorService.addDeviceError("crnErr", slave.getId(), "巷道号"+command.getLaneNo()+";写入次数"+i+";堆垛机命令地址写入后回读失败:"+JSON.toJSONString(command.getNowTask()));
                        deviceErrorService.addDeviceError("CrnErr", slave.getId(), "巷道号"+command.getLaneNo()+";写入次数"+i+";堆垛机命令读取失败:"+JSON.toJSONString(command.getNowTask()));
                    } catch (Exception e2){
                    }
                    try{
                        BasErrLogService basErrLogService = SpringUtils.getBean(BasErrLogService.class);
                        BasErrLog basErrLog = new BasErrLog(command,"堆垛机命令地址写入后回读失败","");
                        if (!basErrLogService.insert(basErrLog)) {
                            log.error("堆垛机plc异常记录失败 ===>> [id:{}] [error:{}]", slave.getId(), "堆垛机命令地址写入后回读失败记录失败");
                        }
                    } catch (Exception e3){
                    }
                    result = siemensNet.Write("DB100.0", array);
                }else{
                    break;
                }
            } catch (Exception e396){
                log.error("堆垛机任务读100.0:值:20 crnWrite-317行;异常"+e396.getMessage());
            }
        }while(i<5);
@@ -355,6 +406,7 @@
            result = siemensNet.Write("DB100.18", commandFinish);
            int signFinish = 1;
            while (signFinish<5){
                signFinish++;
                OperateResultExOne<byte[]> result10018 = siemensNet.Read("DB100.18", (short) 2);
                short transInt16 = siemensNet.getByteTransform().TransInt16(result10018.Content, 0);
                if (transInt16 != commandFinish){
@@ -363,7 +415,7 @@
                    CrnErrCache.updateCrnErr(slave.getId(), "下发DB100.18  回读失败");
                    try{
                        DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class);
                        deviceErrorService.addDeviceError("crnErr", slave.getId(), "巷道号"+command.getLaneNo()+";写入次数"+signFinish+";下发DB100.18  回读失败:"+JSON.toJSONString(command.getNowTask()));
                        deviceErrorService.addDeviceError("CrnErr", slave.getId(), "巷道号"+command.getLaneNo()+";写入次数"+signFinish+";下发DB100.18  回读失败:"+JSON.toJSONString(command.getNowTask()));
                    } catch (Exception e2){
                    }
                    try{
@@ -375,7 +427,6 @@
                    } catch (Exception e3){
                    }
                    result = siemensNet.Write("DB100.18", commandFinish);
                    signFinish++;
                }else {
                    log.info("下发DB100.18" + "commandFinish:"+commandFinish);
                    log.info("下发DB100.18" + "array:"+ JSON.toJSONString(array));
@@ -556,4 +607,22 @@
    public void setWrkSign() {
    }
    /**
     * 清除作业启动中
     */
    @Override
    public void setResetFlag(boolean flag) {
        this.resetFlag = flag;
    }
    /**
     * 清除作业启动中
     */
    @Override
    public boolean getResetFlag() {
        return resetFlag;
    }
}