#
whycq
2024-07-10 e970c1670c36fc0d3f04dac0a81e504638828919
#
2个文件已修改
174 ■■■■■ 已修改文件
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/JxgtDevpThread.java 96 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/JxgtLiftThread.java 78 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/JxgtDevpThread.java
@@ -108,7 +108,7 @@
        updateWorkMode();
        ArrayList<BasConveyorSta> staNos = getStaNo();
        int staNoSize = staNos.size();
        OperateResultExOne<byte[]> result = siemensS7Net.Read("DB100.16", (short) (staNoSize * 18));
        OperateResultExOne<byte[]> result = siemensS7Net.Read("DB100.20", (short) (staNoSize * 18));
        if (result.IsSuccess) {
            for (int i = 0; i < staNoSize; i++) {
                BasConveyorSta siteStation = staNos.get(i);
@@ -120,17 +120,18 @@
                    station.put(siteId, staProtocol);
                }
                staProtocol.setAutoing(siemensS7Net.getByteTransform().TransInt16(result.Content, i * 18) == 2);  // 自动
                staProtocol.setAutoing(siemensS7Net.getByteTransform().TransInt16(result.Content, i * 18) == 1);  // 自动
                staProtocol.setLoading(siemensS7Net.getByteTransform().TransInt16(result.Content, i * 18 + 2) == 1);  // 有物
                staProtocol.setInEnable(siemensS7Net.getByteTransform().TransInt16(result.Content, i * 18 + 4) == 1); // 可入
                staProtocol.setOutEnable(siemensS7Net.getByteTransform().TransInt16(result.Content, i * 18 + 6) == 2);// 可出
                staProtocol.setOutEnable(siemensS7Net.getByteTransform().TransInt16(result.Content, i * 18 + 6) == 1);// 可出
                //高低信号
                short locType1 = siemensS7Net.getByteTransform().TransInt16(result.Content, i * 18 + 8);
                staProtocol.setLow(locType1 == 1);
//                staProtocol.setWorkMode((int) siemensS7Net.getByteTransform().TransInt16(result.Content, i * 40 + 8));// 工作模式
                staProtocol.setWorkNo(siemensS7Net.getByteTransform().TransInt16(result.Content, i * 10));     // 工作号
                staProtocol.setStaNo(siemensS7Net.getByteTransform().TransInt16(result.Content, i * 18 + 14));   // 目标站
                staProtocol.setWorkNo((short) siemensS7Net.getByteTransform().TransInt32(result.Content, i * 18 + 10));     // 工作号
                staProtocol.setStaNo((short) siemensS7Net.getByteTransform().TransInt32(result.Content, i * 18 + 14));   // 目标站
                if (!staProtocol.isPakMk() && !staProtocol.isLoading()) {
                    staProtocol.setPakMk(true);
@@ -139,17 +140,19 @@
        }
        OperateResultExOne<byte[]> resultBarcode = siemensS7Net.Read("DB100.160", (short) 8);
        //条码数据
        String barcode = siemensS7Net.getByteTransform().TransString(resultBarcode.Content,0,8, "UTF-8");// 条码
        BasConveyorStaService basConveyorStaService = SpringUtils.getBean(BasConveyorStaService.class);
        DeviceBarcodeService deviceBarcodeService = SpringUtils.getBean(DeviceBarcodeService.class);
        BasConveyorSta basConveyorSta = basConveyorStaService.getOne(new LambdaQueryWrapper<BasConveyorSta>().eq(BasConveyorSta::getSiteNo, 31002));
        if (basConveyorSta != null) {
            DeviceBarcode deviceBarcode = deviceBarcodeService.getById(basConveyorSta.getBarcodeId());
            if (deviceBarcode != null) {
                BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, Integer.parseInt(deviceBarcode.getDeviceId()));
                if (barcodeThread != null) {
                    barcodeThread.setBarcode(barcode);
        if (resultBarcode.IsSuccess) {
            //条码数据
            String barcode = siemensS7Net.getByteTransform().TransString(resultBarcode.Content,0,8, "UTF-8");// 条码
            BasConveyorStaService basConveyorStaService = SpringUtils.getBean(BasConveyorStaService.class);
            DeviceBarcodeService deviceBarcodeService = SpringUtils.getBean(DeviceBarcodeService.class);
            BasConveyorSta basConveyorSta = basConveyorStaService.getOne(new LambdaQueryWrapper<BasConveyorSta>().eq(BasConveyorSta::getSiteNo, 31002));
            if (basConveyorSta != null) {
                DeviceBarcode deviceBarcode = deviceBarcodeService.getById(basConveyorSta.getBarcodeId());
                if (deviceBarcode != null) {
                    BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, Integer.parseInt(deviceBarcode.getDeviceId()));
                    if (barcodeThread != null) {
                        barcodeThread.setBarcode(barcode);
                    }
                }
            }
        }
@@ -168,6 +171,7 @@
                }
                if (!stations.isEmpty()) {
                    BasConveyorStaService basConveyorStaService = SpringUtils.getBean(BasConveyorStaService.class);
                    if (null != basConveyorStaService && !basConveyorStaService.updateBatchById(stations)) {
                        throw new Exception("更新数据库数据失败");
                    }
@@ -188,7 +192,7 @@
    @Override
    public boolean connect() {
        boolean result = false;
        siemensS7Net = new SiemensS7Net(SiemensPLCS.S1200, device.getIp());
        siemensS7Net = new SiemensS7Net(SiemensPLCS.S1500, device.getIp());
        siemensS7Net.setRack(device.getRack().byteValue());
        siemensS7Net.setSlot(device.getSlot().byteValue());
        OperateResult connect = siemensS7Net.ConnectServer();
@@ -213,7 +217,7 @@
    public boolean writeWorkNo(int siteId, short workNo) {
        int index = findStaNosIndex(siteId);
        OperateResult write = siemensS7Net.Write("DB101." + (index * 8 + 20), workNo);    // 工作号
        OperateResult write = siemensS7Net.Write("DB101." + (index * 8 + 20 + 4),(int) workNo);    // 工作号
        if (!write.IsSuccess) {
            StaProtocol staProtocol = station.get(siteId);
@@ -234,7 +238,7 @@
    public boolean writeStaNo(int siteId,short staNo) {
        int index = findStaNosIndex(siteId);
        OperateResult write = siemensS7Net.Write("DB1001." + (index * 8 + 20 + 4), staNo);    // 目标站
        OperateResult write = siemensS7Net.Write("DB101." + (index * 8 + 20),(int) staNo);    // 目标站
        if (!write.IsSuccess) {
            StaProtocol staProtocol = station.get(siteId);
@@ -255,44 +259,30 @@
    public boolean writeWorkSta(int siteId, short workNo, short staNo) {
        int index = findStaNosIndex(siteId);
        String workNoAddress = "DB1001." + (index * 8 + 20);
        String staNoAddress = "DB1001." + (index * 8 + 20 + 4);
        short[] array = new short[2];
        array[0] = workNo;
        array[1] = staNo;
        String workNoAddress = "DB101." + (index * 8 + 20 + 4);
        String staNoAddress = "DB101." + (index * 8 + 20);
        OperateResult write1 = null;    // 工作号
        OperateResult write2 = null;     // 目标站
        //任务下发次数
        int writeCount = 0;
        do {
            write1 = siemensS7Net.Write(workNoAddress, workNo);    // 工作号
            write2 = siemensS7Net.Write(staNoAddress, staNo);    // 目标站
            if ((write1.IsSuccess && write2.IsSuccess)) {
                OperateResultExOne<byte[]> readResult = siemensS7Net.Read("DB1000." + (index * 40 + 100 + 2), (short) 4);
                if (readResult.IsSuccess) {
                    short workNo2 = siemensS7Net.getByteTransform().TransInt16(readResult.Content, 0);
                    short staNo2 = siemensS7Net.getByteTransform().TransInt16(readResult.Content, 2);
                    if (workNo == workNo2 && staNo == staNo2) {
                        //任务命令写入成功
                        log.info("写入输送线命令后返回成功,并且回读成功。输送线plc编号={},{},{},写入次数={}", siteId, JSON.toJSON(workNo), JSON.toJSON(staNo), writeCount);
                        return true;
                    } else {//返回结果是成功了,但是真实值不相同
                        writeCount++;
                        log.error("写入输送线命令后返回成功,但是读取任务值不一致。输送线plc编号={},{},{},写入次数={}", siteId, JSON.toJSON(workNo), JSON.toJSON(staNo), writeCount);
                    }
                } else {
                    writeCount++;
                    log.error("写入输送线命令后读取失败。输送线plc编号={},站点数据={},{},写入次数={}", siteId, JSON.toJSON(workNo), JSON.toJSON(staNo), writeCount);
                }
            }else {
                writeCount++;
            }
        }while (writeCount < 5) ;
        StaProtocol staProtocol = station.get(siteId);
        if (staProtocol.getWorkNo() == 0 && staProtocol.getStaNo() ==0) {
            staProtocol.setPakMk(true);
//        write1 = siemensS7Net.Write(workNoAddress, workNo);    // 工作号
//        write2 = siemensS7Net.Write(staNoAddress, staNo);    // 目标站
        write1 = siemensS7Net.Write(workNoAddress, (int) staNo);    // 工作号
        write2 = siemensS7Net.Write(staNoAddress, (int) workNo);    // 目标站
        if ((write1.IsSuccess && write2.IsSuccess)) {
            log.info("写入输送线命令后返回成功,并且回读成功。输送线plc编号={},{},{}", siteId, JSON.toJSON(workNo), JSON.toJSON(staNo));
            return true;
        }else {
            OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入输送线站点数据失败。输送线plc编号={1},站点数据={2}", device.getId(), JSON.toJSON(array)));
            log.error("写入输送线站点数据失败。输送线plc编号={},站点数据={}", device.getId(), JSON.toJSON(array));
            return false;
        }
        OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入输送线站点数据失败。输送线plc编号={1},站点数据={2}", device.getId(), JSON.toJSON(staProtocol)));
        log.error("写入输送线站点数据失败。输送线plc编号={},站点数据={}", device.getId(), JSON.toJSON(staProtocol));
        return false;
    }
    @Override
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/JxgtLiftThread.java
@@ -127,6 +127,12 @@
                liftExtend.setLock(siemensS7Net.getByteTransform().TransInt16(result1.Content, 10) == 1);
                liftProtocol.setExtend(liftExtend);
                boolean ready = true;
                if (!liftProtocol.getModel() || liftProtocol.getRun()) {
                    ready = false;
                }
                liftProtocol.setReady(ready);//就绪状态
            }else {
                OutputQueue.LIFT.offer(MessageFormat.format("【{0}】{1}读取提升机状态信息失败", DateUtils.convert(new Date()), device.getId()));
@@ -212,14 +218,25 @@
            array[i] = shorts.get(i);
        }
        OperateResult result = siemensS7Net.Write("DB83.0", array);
        OperateResult result = null;
        if (command.getMode() == LiftCommandModeType.MOVE.id) {
            //移动
             result = siemensS7Net.Write("DB101.2", array);
        } else if (command.getMode() == LiftCommandModeType.PALLET_INOUT.id) {
            //托盘出入
            result = siemensS7Net.Write("DB101.8", array);
        } else if (command.getMode() == LiftCommandModeType.LOCK.id || command.getMode() == LiftCommandModeType.UNLOCK.id) {
            //提升机锁定/解锁
            result = siemensS7Net.Write("DB101.0", array);
        }
        if (result != null && result.IsSuccess) {
            liftProtocol.setSendTime(System.currentTimeMillis());//指令下发时间
            News.info("提升机命令下发[id:{}] >>>>> {}", device.getId(), JSON.toJSON(command));
            OutputQueue.LIFT.offer(MessageFormat.format("【{0}】[id:{1}] >>>>> 命令下发: {2}", DateUtils.convert(new Date()), device.getId(), JSON.toJSON(command)));
            return true;
        } else {
            OutputQueue.LIFT.offer(MessageFormat.format("【{0}】写入提升机plc数据失败 ===>> [id:{1}] [ip:{2}] [port:{3}],次数:{}", DateUtils.convert(new Date()), device.getId(), device.getIp(), device.getPort()));
            OutputQueue.LIFT.offer(MessageFormat.format("【{0}】写入提升机plc数据失败 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), device.getId(), device.getIp(), device.getPort()));
            News.error("写入提升机plc数据失败 ===>> [id:{}] [ip:{}] [port:{}]", device.getId(), device.getIp(), device.getPort());
            return false;
        }
@@ -310,29 +327,14 @@
    @Override
    public List<LiftCommand> getMoveCommand(Integer taskNo, Integer sourceLev, Integer targetLev, LiftCommandModeType mode) {
        /**
         * 任务类型
         * 1=移托盘;升降机将源站台托盘移到目标站台
         * 2=移小车,升降机移到目标层,等待
         */
        short taskMode = 2;
        if (mode.equals(LiftCommandModeType.PALLET_INOUT)) {
            taskMode = 1;
        }
        // 开始任务
        short[] array = new short[4];
        //任务类型
        array[0] = taskMode;
        //源站台编号
        array[1] = sourceLev.shortValue();
        //目标站台编号
        array[2] = targetLev.shortValue();
        //任务号
        array[3] = taskNo.shortValue();
        short[] array = new short[2];
        array[0] = targetLev.shortValue();//目标层
        array[1] = taskNo.shortValue();//工作号
        LiftCommand command = new LiftCommand();
        command.setLiftNo(Integer.valueOf(this.device.getDeviceNo()));
        command.setTaskNo(taskNo);
        command.setBody(JSON.toJSONString(array));
        command.setMode(LiftCommandModeType.MOVE.id);
        command.setOriginLev(sourceLev);
@@ -350,12 +352,40 @@
    @Override
    public List<LiftCommand> getPalletInOutCommand(Integer taskNo, Integer sourceLev, Integer targetLev, Integer originSta, Integer targetSta, LiftCommandModeType mode) {
        return getMoveCommand(taskNo, sourceLev, targetLev, mode);
        // 开始任务
        short[] array = new short[2];
        array[0] = originSta.shortValue();//起始站
        array[1] = targetSta.shortValue();//目标站
        array[2] = taskNo.shortValue();//工作号
        LiftCommand command = new LiftCommand();
        command.setLiftNo(Integer.valueOf(this.device.getDeviceNo()));
        command.setTaskNo(taskNo);
        command.setBody(JSON.toJSONString(array));
        command.setMode(LiftCommandModeType.PALLET_INOUT.id);
        command.setOriginLev(sourceLev);
        command.setTargetLev(targetLev);
        ArrayList<LiftCommand> list = new ArrayList<>();
        list.add(command);
        return list;
    }
    @Override
    public List<LiftCommand> getLockCommand(Integer taskNo, Boolean lock) {
        return null;
        // 开始任务
        short[] array = new short[2];
        array[0] = lock ? (short) 1 : (short) 0;
        LiftCommand command = new LiftCommand();
        command.setLiftNo(Integer.valueOf(this.device.getDeviceNo()));
        command.setTaskNo(taskNo);
        command.setBody(JSON.toJSONString(array));
        command.setMode(LiftCommandModeType.PALLET_INOUT.id);
        ArrayList<LiftCommand> list = new ArrayList<>();
        list.add(command);
        return list;
    }
    @Override
@@ -367,7 +397,7 @@
    public boolean connect() {
        boolean result = false;
        //-------------------------提升机连接方法------------------------//
        siemensS7Net = new SiemensS7Net(SiemensPLCS.S1200, device.getIp());
        siemensS7Net = new SiemensS7Net(SiemensPLCS.S1500, device.getIp());
        OperateResult connect = siemensS7Net.ConnectServer();
        if(connect.IsSuccess){
            result = true;