#ZH
野心家
2025-05-27 1b9f41e12e3ee8ac8bbc388eab7585300bdab75a
src/main/java/com/zy/core/thread/SiemensCrnThread.java
@@ -13,6 +13,7 @@
import com.zy.asrs.service.BasCrnOptService;
import com.zy.asrs.service.BasCrnpService;
import com.zy.core.CrnThread;
import com.zy.core.cache.CrnErrCache;
import com.zy.core.cache.MessageQueue;
import com.zy.core.cache.OutputQueue;
import com.zy.core.enums.CrnStatusType;
@@ -155,12 +156,12 @@
     */
    private void readStatus(){
        try {
            OperateResultExOne<byte[]> result = siemensNet.Read("DB101.0", (short) 56);
            OperateResultExOne<byte[]> result = siemensNet.Read("DB101.0", (short) 58);
            if (result.IsSuccess) {
                if (null == crnProtocol) {
                    crnProtocol = new CrnProtocol();
                    crnProtocol.setCrnNo(slave.getId());
                }
                crnProtocol.setCrnNo(slave.getId());
                crnProtocol.setMode(siemensNet.getByteTransform().TransInt16(result.Content, 0));
                crnProtocol.setTaskNo(siemensNet.getByteTransform().TransInt16(result.Content, 2));
                crnProtocol.setStatus(siemensNet.getByteTransform().TransInt16(result.Content, 4));
@@ -182,6 +183,7 @@
                crnProtocol.setyDistance(siemensNet.getByteTransform().TransInt16(result.Content, 44));
                crnProtocol.setxDuration(siemensNet.getByteTransform().TransInt16(result.Content, 48));
                crnProtocol.setyDuration(siemensNet.getByteTransform().TransInt16(result.Content, 52));
                crnProtocol.setLaneNo((int)siemensNet.getByteTransform().TransInt16(result.Content, 56));//巷道号
                OutputQueue.CRN.offer(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功",DateUtils.convert(new Date()), slave.getId()));
@@ -242,6 +244,8 @@
            log.error("堆垛机写入命令为空");
            return false;
        }
        CrnErrCache.updateCrnErr(slave.getId(), "-");
//        convertRow(command);
        command.setCrnNo(slave.getId());
        short[] array = new short[10];
@@ -254,15 +258,60 @@
        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.18", (short)0);
        try{
            Thread.sleep(50L);
        } catch (Exception e){}
        OperateResult result = siemensNet.Write("DB100.0", array);
        int i=0;
        do{
            //堆垛机任务写入后,回读一次,看是否成功
            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(), "堆垛机命令地址写入后回读失败");
                    log.error("堆垛机命令地址写入后回读失败[id:{}]>>>>重写[{}] >>>>> 写入[{}],===>>回读[{}]", slave.getId(), i,JSON.toJSON(command),JSON.toJSON(one));
                    result = siemensNet.Write("DB100.0", array);
                }else{
                    break;
                }
            }
        }while(i<5);
        if (command.getAckFinish() == 0) {
            short commandFinish = 1;
            Thread.sleep(100L);
            try{
                Thread.sleep(100L);
            } catch (Exception e){}
            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));
                    CrnErrCache.updateCrnErr(slave.getId(), "下发DB100.18  回读失败");
                    result = siemensNet.Write("DB100.18", commandFinish);
                    signFinish++;
                }else {
                    log.info("下发DB100.18" + "commandFinish:"+commandFinish);
                    log.info("下发DB100.18" + "array:"+ JSON.toJSONString(array));
                    break;
                }
            }
        }
        try {
@@ -297,6 +346,8 @@
        } 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());
            CrnErrCache.updateCrnErr(slave.getId(), "写入堆垛机plc数据失败");
            return false;
        }
    }