自动化立体仓库 - WCS系统
#
LSH
2024-03-19 a5fa1d77b80aeb74c228b1d4bd846eef35a4baca
src/main/java/com/zy/core/thread/SiemensDevpThread.java
@@ -125,6 +125,11 @@
                        write((StaProtocol)task.getData());
                        read();
                        break;
                    // 写数据 ID+目标站
                    case 4:
                        writeAgvOk((StaProtocol)task.getData());
                        read();
                        break;
                   /* case 3:
                        write2((StaProtocol)task.getData());
                        read();
@@ -229,14 +234,42 @@
            }
        }
        OperateResultExOne<byte[]> resultAgvAndPlc = siemensS7Net.Read("DB102.0", (short) 30);
        if (resultAgvAndPlc.IsSuccess) {
            for (int i = 0; i < staNoSize; i++) {
                int sign =(i+2)/2-1;
                if ((i+2)%2!=0){
                    Integer siteId = staNos.get(i); // 站点编号
                    StaProtocol staProtocol = station.get(siteId);
                    if (null == staProtocol) {
                        staProtocol = new StaProtocol();
                        staProtocol.setSiteId(siteId);
                        station.put(siteId, staProtocol);
                    }
                    staProtocol.setAgvStartPick(siemensS7Net.getByteTransform().TransInt16(resultAgvAndPlc.Content, sign*6+4));     // 允许取货
                    staProtocol.setAgvStartPlace((short)0);   // 允许放货
                    continue;
                }
                Integer siteId = staNos.get(i); // 站点编号
                StaProtocol staProtocol = station.get(siteId);
                if (null == staProtocol) {
                    staProtocol = new StaProtocol();
                    staProtocol.setSiteId(siteId);
                    station.put(siteId, staProtocol);
                }
                staProtocol.setAgvStartPick(siemensS7Net.getByteTransform().TransInt16(resultAgvAndPlc.Content, sign*6));     // 允许取货
                staProtocol.setAgvStartPlace(siemensS7Net.getByteTransform().TransInt16(resultAgvAndPlc.Content, sign*6 + 2));   // 允许放货
            }
        }
        if (slave.getId() == 1) {
            //条码
            //Thread.sleep(200);
            OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB101.840.0", (short) 60);
            OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB101.840.0", (short) 32);
            if (result2.IsSuccess) {
                for (int i = 0; i < 4; i++) {
                    String barcode = siemensS7Net.getByteTransform().TransString(result2.Content, i * 10, 8, "UTF-8");
                    String barcode = siemensS7Net.getByteTransform().TransString(result2.Content, i * 8, 8, "UTF-8");
                    BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, i + 1);
                    if (!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)) {
                        barcodeThread.setBarcode(barcode);
@@ -324,6 +357,83 @@
    /**
     * 写入 ID+目标站 =====> 单站点写入
     */
    private void writeAgvOk(StaProtocol staProtocol) throws InterruptedException {
        if (null == staProtocol) {
            return;
        }
        ArrayList<Integer> staNos = getStaNo();
        int index = staNos.indexOf(staProtocol.getSiteId());
        if (staProtocol.getAgvTypeSign()==0){  //0取货
            switch (staProtocol.getSiteId()){
                case 100:
                    index=32;
                    break;
                case 101:
                    index=34;
                    break;
                case 102:
                    index=38;
                    break;
                case 103:
                    index=40;
                    break;
                case 104:
                    index=44;
                    break;
                case 105:
                    index=46;
                    break;
                case 106:
                    index=50;
                    break;
                case 107:
                    index=52;
                    break;
                default:
                    return;
            }
        }else {
            switch (staProtocol.getSiteId()){
                case 100:
                    index=30;
                    break;
                case 102:
                    index=36;
                    break;
                case 104:
                    index=42;
                    break;
                case 106:
                    index=48;
                    break;
                default:
                    return;
            }
        }
        OperateResult write = null;
        //任务下发次数
        int writeCount = 0;
        do {
            write = siemensS7Net.Write("DB102." + index, (short) 1);    // 任务完成
            if(write.IsSuccess){
                writeCount=6;
            }else {
                writeCount++;
                log.error("写入输送线取放货完成命令后读取失败。输送线plc编号={},站点数据={},写入次数={}", slave.getId(), JSON.toJSON(staProtocol), writeCount);
            }
        }while (writeCount<5);
        if (!write.IsSuccess) {
            OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入输送线站点数据失败。输送线plc编号={1},站点数据={2}", slave.getId(), JSON.toJSON(staProtocol)));
            log.error("写入输送线取放货完成站点数据失败。输送线plc编号={},站点数据={}", slave.getId(), JSON.toJSON(staProtocol));
        } else {
            OutputQueue.DEVP.offer(MessageFormat.format("【{0}】 输送线命令下发 [id:{1}] >>>>> {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(staProtocol)));
            log.info("输送线取放货完成命令下发码垛完成  给输送线写任务完成 [id:{}] >>>>> 命令下发: {}",  slave.getId(), JSON.toJSON(staProtocol));
        }
    }
    private void write(StaProtocol staProtocol) throws InterruptedException {
        if (null == staProtocol) {
            return;
@@ -335,29 +445,6 @@
        array[0] = staProtocol.getWorkNo();
        array[1] = staProtocol.getStaNo();
//        OperateResult write = siemensS7Net.Write("DB100." + index*4, array);
        //更新命令日志
        CommandInfoLogService commandInfoLogService = SpringUtils.getBean(CommandInfoLogService.class);
        CommandInfoService commandInfoService = SpringUtils.getBean(CommandInfoService.class);
        CommandInfo commandInfo = commandInfoService.selectById(staProtocol.getCommandId());
        CommandInfoLog commandInfoLog = JSON.parseObject(JSON.toJSONString(commandInfo), CommandInfoLog.class);
        commandInfoLog.setId(null);
//        CommandInfoLog commandInfoLog = new CommandInfoLog();
//        if (commandInfo != null) {
//            commandInfoLog = JSON.parseObject(JSON.toJSONString(commandInfo), CommandInfoLog.class);
//            commandInfoLog.setId(null);
//        }else {
//            Date now = new Date();
//            commandInfoLog.setCommand(JSON.toJSONString(staProtocol));
//            commandInfoLog.setCommandStatus(3);
//            commandInfoLog.setStartTime(now);
//            commandInfoLog.setExecuteTime(now);
//            commandInfoLog.setCompleteTime(now);
//            commandInfoLog.setDevice(SlaveType.Devp.toString());
//            commandInfoLog.setWrkNo(9999);
//            commandInfoLog.setTaskNo("9999");
//            commandInfoLog.setCommandDesc("手动命令");
//        }
        OperateResult writeResult;
        //任务下发次数