自动化立体仓库 - WCS系统
#
lsh
2024-06-27 efad59da8921d93537fca47d6ec2512e312bc1c3
src/main/java/com/zy/core/thread/SiemensCrnThread.java
@@ -19,6 +19,7 @@
import com.zy.core.model.CrnSlave;
import com.zy.core.model.Task;
import com.zy.core.model.command.CrnCommand;
import com.zy.core.model.cpmmandParam.CrnCommandParam;
import com.zy.core.model.protocol.CrnProtocol;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
@@ -48,6 +49,7 @@
     * 堆垛机是否在回原点运动中标记
     */
    private boolean backHpFlag = false;
    private boolean backHpFlagTwo = false;
    public SiemensCrnThread(CrnSlave slave) {
        this.slave = slave;
@@ -57,6 +59,7 @@
    @SuppressWarnings("InfiniteLoopStatement")
    public void run() {
        this.connect();
        sign = System.currentTimeMillis();
        while (isRunning) {
            try {
                int step = 1;
@@ -113,6 +116,10 @@
                        command2.setDestinationPosZ((short)0);     // 目标库位层
                        write5(command2);
                        break;
                    // 复位
                    case 7:
                        write9((CrnCommandParam) task.getData());
                        break;
                    default:
                        break;
                }
@@ -135,6 +142,7 @@
        crnProtocol.setMode((short) -1);
//        crnProtocol.setTaskNo((short)0);
        crnProtocol.setStatus((short)-1);
        crnProtocol.setStatusTwo((short)-1);
        crnProtocol.setBay((short)0);
        crnProtocol.setLevel((short)0);
        crnProtocol.setForkPos((short) -1);
@@ -149,6 +157,16 @@
        crnProtocol.setyDistance((short) 0);
        crnProtocol.setxDuration((short) 0);
        crnProtocol.setyDuration((short) 0);
        // 根据实时信息更新数据库
        BasCrnpService basCrnpService = SpringUtils.getBean(BasCrnpService.class);
        BasCrnp basCrnp = basCrnpService.selectById(slave.getId());
        basCrnp.setCrnSts((int)crnProtocol.getMode());
        basCrnp.setCrnStatusOne(-1);
        basCrnp.setCrnStatusTwo(-1);
        if (!basCrnpService.updateById(basCrnp)){
            log.error("堆垛机plc数据库更新失败 ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot());
        }
    }
    @Override
@@ -176,7 +194,12 @@
     */
    private void readStatus(){
        try {
            OperateResultExOne<byte[]> result = siemensNet.Read("DB101.0", (short) 56);
            OperateResultExOne<byte[]> result = new OperateResultExOne<byte[]>();
            if (slave.getId()>2 && slave.getId()<6){
                result = siemensNet.Read("DB101.0", (short) 66);
            } else {
                result = siemensNet.Read("DB101.0", (short) 56);
            }
            if (result.IsSuccess) {
                if (null == crnProtocol) {
                    crnProtocol = new CrnProtocol();
@@ -188,40 +211,56 @@
                crnProtocol.setBay(siemensNet.getByteTransform().TransInt16(result.Content, 6));
                crnProtocol.setLevel(siemensNet.getByteTransform().TransInt16(result.Content, 8));
                crnProtocol.setForkPos(siemensNet.getByteTransform().TransInt16(result.Content, 10));
                crnProtocol.setLiftPos(siemensNet.getByteTransform().TransInt16(result.Content, 12));
                crnProtocol.setWalkPos(siemensNet.getByteTransform().TransInt16(result.Content, 14));
                crnProtocol.setLoaded(siemensNet.getByteTransform().TransInt16(result.Content, 16));
                crnProtocol.setAlarm(siemensNet.getByteTransform().TransInt16(result.Content, 18));
                crnProtocol.setTemp1(siemensNet.getByteTransform().TransInt16(result.Content, 20));
                crnProtocol.setTemp2(siemensNet.getByteTransform().TransInt16(result.Content, 22));
                crnProtocol.setTemp3(siemensNet.getByteTransform().TransInt16(result.Content, 24));
                crnProtocol.setTemp4(siemensNet.getByteTransform().TransInt16(result.Content, 26));
                crnProtocol.setxSpeed(siemensNet.getByteTransform().TransInt16(result.Content, 28));
                crnProtocol.setySpeed(siemensNet.getByteTransform().TransInt16(result.Content, 32));
                crnProtocol.setzSpeed(siemensNet.getByteTransform().TransInt16(result.Content, 36));
                crnProtocol.setxDistance(siemensNet.getByteTransform().TransInt16(result.Content, 40));
                crnProtocol.setyDistance(siemensNet.getByteTransform().TransInt16(result.Content, 44));
                crnProtocol.setxDuration(siemensNet.getByteTransform().TransInt16(result.Content, 48));
                crnProtocol.setyDuration(siemensNet.getByteTransform().TransInt16(result.Content, 52));
                if (slave.getId()<3 || slave.getId()>5){
                    crnProtocol.setLiftPos(siemensNet.getByteTransform().TransInt16(result.Content, 12));
                    crnProtocol.setWalkPos(siemensNet.getByteTransform().TransInt16(result.Content, 14));
                    crnProtocol.setLoaded(siemensNet.getByteTransform().TransInt16(result.Content, 16));
                    crnProtocol.setAlarm(siemensNet.getByteTransform().TransInt16(result.Content, 18));
                    crnProtocol.setTemp1(siemensNet.getByteTransform().TransInt16(result.Content, 20));
                    crnProtocol.setTemp2(siemensNet.getByteTransform().TransInt16(result.Content, 22));
                    crnProtocol.setTemp3(siemensNet.getByteTransform().TransInt16(result.Content, 24));
                    crnProtocol.setTemp4(siemensNet.getByteTransform().TransInt16(result.Content, 26));
                    crnProtocol.setxSpeed(siemensNet.getByteTransform().TransInt16(result.Content, 28));
                    crnProtocol.setySpeed(siemensNet.getByteTransform().TransInt16(result.Content, 32));
                    crnProtocol.setzSpeed(siemensNet.getByteTransform().TransInt16(result.Content, 36));
                    crnProtocol.setxDistance(siemensNet.getByteTransform().TransInt16(result.Content, 40));
                    crnProtocol.setyDistance(siemensNet.getByteTransform().TransInt16(result.Content, 44));
                    crnProtocol.setxDuration(siemensNet.getByteTransform().TransInt16(result.Content, 48));
                    crnProtocol.setyDuration(siemensNet.getByteTransform().TransInt16(result.Content, 52));
                } else {
                    crnProtocol.setLoaded(siemensNet.getByteTransform().TransInt16(result.Content, 12));
                //工位2数据  无则无需理会
                try{
                    crnProtocol.setTaskNoTwo(siemensNet.getByteTransform().TransInt16(result.Content, 56));
                    crnProtocol.setStatusTwo(siemensNet.getByteTransform().TransInt16(result.Content, 56));
                    crnProtocol.setForkPosTwo(siemensNet.getByteTransform().TransInt16(result.Content, 58));
                    crnProtocol.setLiftPosTwo(siemensNet.getByteTransform().TransInt16(result.Content, 60));
                    crnProtocol.setLoadedTwo(siemensNet.getByteTransform().TransInt16(result.Content, 64));
                }catch (Exception e){
                    crnProtocol.setTaskNoTwo(siemensNet.getByteTransform().TransInt16(result.Content, 14));
                    crnProtocol.setStatusTwo(siemensNet.getByteTransform().TransInt16(result.Content, 16));
                    crnProtocol.setBayTwo(siemensNet.getByteTransform().TransInt16(result.Content, 18));
                    crnProtocol.setLevelTwo(siemensNet.getByteTransform().TransInt16(result.Content, 20));
                    crnProtocol.setForkPosTwo(siemensNet.getByteTransform().TransInt16(result.Content, 22));
                    crnProtocol.setLoadedTwo(siemensNet.getByteTransform().TransInt16(result.Content, 24));
                    crnProtocol.setWalkPos(siemensNet.getByteTransform().TransInt16(result.Content, 26));
                    crnProtocol.setWalkPosTwo(siemensNet.getByteTransform().TransInt16(result.Content, 28));
                    crnProtocol.setLiftPos(siemensNet.getByteTransform().TransInt16(result.Content, 30));
                    crnProtocol.setAlarm(siemensNet.getByteTransform().TransInt16(result.Content, 32));
                    crnProtocol.setxSpeed(siemensNet.getByteTransform().TransInt16(result.Content, 34));
                    crnProtocol.setySpeed(siemensNet.getByteTransform().TransInt16(result.Content, 38));
                    crnProtocol.setzSpeed(siemensNet.getByteTransform().TransInt16(result.Content, 42));
//                    crnProtocol.setzSpeed(siemensNet.getByteTransform().TransInt16(result.Content, 42));
                    crnProtocol.setxDistance(siemensNet.getByteTransform().TransInt16(result.Content, 50));
                    crnProtocol.setyDistance(siemensNet.getByteTransform().TransInt16(result.Content, 54));
                    crnProtocol.setxDuration(siemensNet.getByteTransform().TransInt16(result.Content, 58));
                    crnProtocol.setyDuration(siemensNet.getByteTransform().TransInt16(result.Content, 62));
                }
                OutputQueue.CRN.offer(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功",DateUtils.convert(new Date()), slave.getId()));
                // 复位信号
                if (!Cools.isEmpty(crnProtocol.getStatusType()) && crnProtocol.getStatusType().equals(CrnStatusType.WAITING)) {
                    log.error("-------------------------------------------第一步、[堆垛机号:{}, 工作号:{}, 载货台:{}]==>> 状态为10,等待确认!!",
                            slave.getId(),crnProtocol.getTaskNo(), crnProtocol.getLoaded()==1 ? "有物" : "无物");
                if (!Cools.isEmpty(crnProtocol.getStatusType()) && (crnProtocol.getStatusType().equals(CrnStatusType.WAITING) || crnProtocol.getStatusType().equals(CrnStatusType.SEPARATE_WAITING))) {
                    log.error("-------------------------工位1-------------------------第一步、[堆垛机号:{}, 工作号:{}, 载货台:{}]==>> 状态为{},等待确认!!",
                            slave.getId(),crnProtocol.getTaskNo(), crnProtocol.getLoaded()==1 ? "有物" : "无物",crnProtocol.getStatusType());
                    if (resetFlag) {
                        if(crnProtocol.getTaskNo()==9999){
                            backHpFlag = false;
@@ -232,14 +271,20 @@
                            resetFlag = false;
                        }
                    }
                }
                // 复位信号
                if (!Cools.isEmpty(crnProtocol.getStatusTypeTwo()) && (crnProtocol.getStatusTypeTwo().equals(CrnStatusType.WAITING) || crnProtocol.getStatusTypeTwo().equals(CrnStatusType.SEPARATE_WAITING))) {
                    log.error("-------------------------工位2-------------------------第一步、[堆垛机号:{}, 工作号:{}, 载货台:{}]==>> 状态为{},等待确认!!",
                            slave.getId(),crnProtocol.getTaskNoTwo(), crnProtocol.getLoadedTwo()==1 ? "有物" : "无物",crnProtocol.getStatusTypeTwo());
                    if (resetFlagTwo) {
                        if(crnProtocol.getTaskNo()==9999){
                            backHpFlag = false;
                        if(crnProtocol.getTaskNoTwo()==9999){
                            backHpFlagTwo = false;
                        }
                        CrnCommand crnCommand = new CrnCommand();
                        crnCommand.setAckFinish((short)1);
                        if (write5(crnCommand)) {
                            resetFlag = false;
                            resetFlagTwo = false;
                        }
                    }
                }
@@ -302,11 +347,86 @@
        array[9] = command.getCommand();
        OperateResult result18 = siemensNet.Write("DB100.18", (short)0);
        OperateResult result = siemensNet.Write("DB100.0", array);
        log.info("堆垛机命令下发[id:{}] >>>>> {}", slave.getId(), array);
        //堆垛机任务写入后,回读一次,看是否成功
        Thread.sleep(200);
        int writeCount = 1;
        do {
            try{
                if(!result.IsSuccess){
                    log.error("写入堆垛机plc数据失败,重新下发任务  写入直接失败 ===>> [id:{}],{},[写入次数:{}]", slave.getId(), JSON.toJSON(command),writeCount);
                    result = siemensNet.Write("DB100.0", array);
                    Thread.sleep(100);
                    writeCount++;
                    continue;
                }
                OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB100.0", (short) 24);
                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())
                    ){
                        try{
                            log.error("堆垛机命令地址写入后回读失败==>不一致[id:{}] >>>>> 写入[{}],===>>回读[{}]", slave.getId(), JSON.toJSON(command),JSON.toJSON(one));
                        }catch (Exception e){
                            try{
                                log.error("日志打印失败:===>>参数one报错 [id:{}],{}", slave.getId(), JSON.toJSON(command),JSON.toJSON(resultRead));
                            }catch (Exception e1){
                                log.error("日志打印失败:===>> [id:{}],{}", slave.getId(), JSON.toJSON(command));
                            }
                        }
                        try{
                            Thread.sleep(100);
                        }catch (Exception e){
                        }
                        log.error("写入堆垛机plc数据失败,重新下发任务  回读不一致 ===>> [id:{}],{},[写入次数:{}]", slave.getId(), JSON.toJSON(command),writeCount);
                        result = siemensNet.Write("DB100.0", array);
                        writeCount++;
                        continue;
                    } else {
                        log.info("堆垛机命令地址写入后回读成功[id:{}] >>>>> 写入[{}],===>>回读[{}]", slave.getId(), JSON.toJSON(command),JSON.toJSON(one));
                        break;
                    }
                }
            }catch (Exception e){
                log.error("堆垛机命令地址写入后回读出错,异常:"+e);
            }
            writeCount++;
        } while (writeCount<6);
        if (command.getAckFinish() == 0) {
            short commandFinish = 1;
            Thread.sleep(100L);
            result = siemensNet.Write("DB100.18", commandFinish);
            int signFinish = 1;
            while (signFinish<5){
                OperateResultExOne<byte[]> result10018 = siemensNet.Read("DB100.18", (short) 2);
                short transInt16 = siemensNet.getByteTransform().TransInt16(result10018.Content, 0);
                if (transInt16 != commandFinish){
                    log.info("下发DB100.18  回读失败" + "commandFinish:"+commandFinish);
                    log.info("下发DB100.18  回读失败" + "array:"+ JSON.toJSONString(array));
                    result = siemensNet.Write("DB100.18", commandFinish);
                    signFinish++;
                }else {
                    log.info("下发DB100.18" + "commandFinish:"+commandFinish);
                    log.info("下发DB100.18" + "array:"+ JSON.toJSONString(array));
                    break;
                }
            }
        }
        try {
@@ -355,26 +475,240 @@
        }
//        convertRow(command);
        command.setCrnNo(slave.getId());
        short[] array = new short[9];
//        array[0] = command.getAckFinish();
        array[0] = command.getTaskNo();
        array[1] = command.getTaskMode();
        array[2] = command.getSourcePosX();
        array[3] = command.getSourcePosY();
        array[4] = command.getSourcePosZ();
        array[5] = command.getDestinationPosX();
        array[6] = command.getDestinationPosY();
        array[7] = command.getDestinationPosZ();
        short[] array = new short[10];
        array[0] = command.getAckFinish();
        array[1] = command.getTaskNo();
        array[2] = command.getTaskMode();
        array[3] = command.getSourcePosX();
        array[4] = command.getSourcePosY();
        array[5] = command.getSourcePosZ();
        array[6] = command.getDestinationPosX();
        array[7] = command.getDestinationPosY();
        array[8] = command.getDestinationPosZ();
//        array[9] = command.getSourceStaNo();
//        array[10] = command.getDestinationStaNo();
        array[9] = command.getCommand();
        OperateResult result = siemensNet.Write("DB100.0", command.getAckFinish());
        OperateResult result2 = siemensNet.Write("DB100.20", array);
        OperateResult result18 = siemensNet.Write("DB100.38", (short)0);
        OperateResult result = siemensNet.Write("DB100.20", array);
        log.info("堆垛机命令下发[id:{}] >>>>> {}", slave.getId(), array);
        //堆垛机任务写入后,回读一次,看是否成功
        Thread.sleep(200);
        int writeCount = 1;
        do {
            try{
                if(!result.IsSuccess){
                    log.error("写入堆垛机plc数据失败,重新下发任务  写入直接失败 ===>> [id:{}],{},[写入次数:{}]", slave.getId(), JSON.toJSON(command),writeCount);
                    result = siemensNet.Write("DB100.20", array);
                    Thread.sleep(100);
                    writeCount++;
                    continue;
                }
                OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB100.20", (short) 24);
                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())
                    ){
                        try{
                            log.error("堆垛机命令地址写入后回读失败==>不一致[id:{}] >>>>> 写入[{}],===>>回读[{}]", slave.getId(), JSON.toJSON(command),JSON.toJSON(one));
                        }catch (Exception e){
                            try{
                                log.error("日志打印失败:===>>参数one报错 [id:{}],{}", slave.getId(), JSON.toJSON(command),JSON.toJSON(resultRead));
                            }catch (Exception e1){
                                log.error("日志打印失败:===>> [id:{}],{}", slave.getId(), JSON.toJSON(command));
                            }
                        }
                        try{
                            Thread.sleep(100);
                        }catch (Exception e){
                        }
                        log.error("写入堆垛机plc数据失败,重新下发任务  回读不一致 ===>> [id:{}],{},[写入次数:{}]", slave.getId(), JSON.toJSON(command),writeCount);
                        result = siemensNet.Write("DB100.20", array);
                        writeCount++;
                        continue;
                    } else {
                        log.info("堆垛机命令地址写入后回读成功[id:{}] >>>>> 写入[{}],===>>回读[{}]", slave.getId(), JSON.toJSON(command),JSON.toJSON(one));
                        break;
                    }
                }
            }catch (Exception e){
                log.error("堆垛机命令地址写入后回读出错,异常:"+e);
            }
            writeCount++;
        } while (writeCount<6);
        if (command.getAckFinish() == 0) {
            short commandFinish = 1;
            Thread.sleep(100L);
            result = siemensNet.Write("DB100.38", commandFinish);
            int signFinish = 1;
            while (signFinish<5){
                OperateResultExOne<byte[]> result10018 = siemensNet.Read("DB100.38", (short) 2);
                short transInt16 = siemensNet.getByteTransform().TransInt16(result10018.Content, 0);
                if (transInt16 != commandFinish){
                    log.info("下发DB100.38  回读失败" + "commandFinish:"+commandFinish);
                    log.info("下发DB100.38  回读失败" + "array:"+ JSON.toJSONString(array));
                    result = siemensNet.Write("DB100.38", commandFinish);
                    signFinish++;
                }else {
                    log.info("下发DB100.38" + "commandFinish:"+commandFinish);
                    log.info("下发DB100.38" + "array:"+ JSON.toJSONString(array));
                    break;
                }
            }
        }
        try {
            // 日志记录
            BasCrnOptService bean = SpringUtils.getBean(BasCrnOptService.class);
            BasCrnOpt basCrnOpt = new BasCrnOpt(
                    command.getTaskNo().intValue(),    // 任务号
                    command.getCrnNo(),    // 堆垛机[非空]
                    new Date(),    // 下发时间
                    command.getTaskModeType().toString(),    // 模式
                    command.getSourcePosX().intValue(),    // 源排
                    command.getSourcePosY().intValue(),    // 源列
                    command.getSourcePosZ().intValue(),    // 源层
                    null,    // 源站
                    command.getDestinationPosX().intValue(),    // 目标排
                    command.getDestinationPosY().intValue(),    // 目标列
                    command.getDestinationPosZ().intValue(),    // 目标层
                    null,    // 目标站
                    null,    // 响应结果
                    null,    // 修改时间
                    null    // 修改人员
            );
            bean.insert(basCrnOpt);
        } catch (Exception ignore) {}
        if (result != null && result.IsSuccess) {
            Thread.sleep(200);
            this.readStatus();
            log.info("堆垛机命令下发[id:{}] >>>>> {}", slave.getId(), JSON.toJSON(command));
            OutputQueue.CRN.offer(MessageFormat.format("【{0}】[id:{1}] >>>>> 命令下发: {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command)));
            return true;
        } else {
            OutputQueue.CRN.offer(MessageFormat.format("【{0}】写入堆垛机plc数据失败 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort()));
            log.error("写入堆垛机plc数据失败 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
            return false;
        }
    }
    /**
     * 写入数据  工位2
     */
    private boolean write9(CrnCommandParam command) throws InterruptedException {
        if (null == command) {
            log.error("堆垛机写入命令为空");
            return false;
        }
//        convertRow(command);
        command.setCrnNo(slave.getId());
        short[] array = new short[10];
        array[0] = command.getAckFinish();
        array[1] = command.getTaskNo();
        array[2] = command.getTaskMode();
        array[3] = command.getSourcePosX();
        array[4] = command.getSourcePosY();
        array[5] = command.getSourcePosZ();
        array[6] = command.getDestinationPosX();
        array[7] = command.getDestinationPosY();
        array[8] = command.getDestinationPosZ();
//        array[9] = command.getSourceStaNo();
//        array[10] = command.getDestinationStaNo();
        array[9] = command.getCommand();
        OperateResult result18 = siemensNet.Write("DB100.38", (short)0);
        OperateResult result = siemensNet.Write("DB100.20", array);
        log.info("堆垛机命令下发[id:{}] >>>>> {}", slave.getId(), array);
        //堆垛机任务写入后,回读一次,看是否成功
        Thread.sleep(200);
        int writeCount = 1;
        do {
            try{
                if(!result.IsSuccess){
                    log.error("写入堆垛机plc数据失败,重新下发任务  写入直接失败 ===>> [id:{}],{},[写入次数:{}]", slave.getId(), JSON.toJSON(command),writeCount);
                    result = siemensNet.Write("DB100.20", array);
                    Thread.sleep(100);
                    writeCount++;
                    continue;
                }
                OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB100.20", (short) 24);
                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())
                    ){
                        try{
                            log.error("堆垛机命令地址写入后回读失败==>不一致[id:{}] >>>>> 写入[{}],===>>回读[{}]", slave.getId(), JSON.toJSON(command),JSON.toJSON(one));
                        }catch (Exception e){
                            try{
                                log.error("日志打印失败:===>>参数one报错 [id:{}],{}", slave.getId(), JSON.toJSON(command),JSON.toJSON(resultRead));
                            }catch (Exception e1){
                                log.error("日志打印失败:===>> [id:{}],{}", slave.getId(), JSON.toJSON(command));
                            }
                        }
                        try{
                            Thread.sleep(100);
                        }catch (Exception e){
                        }
                        log.error("写入堆垛机plc数据失败,重新下发任务  回读不一致 ===>> [id:{}],{},[写入次数:{}]", slave.getId(), JSON.toJSON(command),writeCount);
                        result = siemensNet.Write("DB100.20", array);
                        writeCount++;
                        continue;
                    } else {
                        log.info("堆垛机命令地址写入后回读成功[id:{}] >>>>> 写入[{}],===>>回读[{}]", slave.getId(), JSON.toJSON(command),JSON.toJSON(one));
                        break;
                    }
                }
            }catch (Exception e){
                log.error("堆垛机命令地址写入后回读出错,异常:"+e);
            }
            writeCount++;
        } while (writeCount<6);
        if (command.getAckFinish() == 0) {
            short commandFinish = 1;
            Thread.sleep(100L);
            result = siemensNet.Write("DB100.38", commandFinish);
            int signFinish = 1;
            while (signFinish<5){
                OperateResultExOne<byte[]> result10018 = siemensNet.Read("DB100.38", (short) 2);
                short transInt16 = siemensNet.getByteTransform().TransInt16(result10018.Content, 0);
                if (transInt16 != commandFinish){
                    log.info("下发DB100.38  回读失败" + "commandFinish:"+commandFinish);
                    log.info("下发DB100.38  回读失败" + "array:"+ JSON.toJSONString(array));
                    result = siemensNet.Write("DB100.38", commandFinish);
                    signFinish++;
                }else {
                    log.info("下发DB100.38" + "commandFinish:"+commandFinish);
                    log.info("下发DB100.38" + "array:"+ JSON.toJSONString(array));
                    break;
                }
            }
        }
        try {