Junjie
2023-07-31 d08e5f29d4aea9f160b45c86e0004efbf34c76bd
src/main/java/com/zy/core/thread/LiftThread.java
@@ -118,12 +118,12 @@
            readStatus();
            //提升机处于运行状态,将标记置为true
            if (liftProtocol.getRunning()) {
            if (liftProtocol.getBusy()) {
                liftProtocol.setPakMk(true);
            }
            //提升机处于未运行、就绪、标记true、有任务号
            if (!liftProtocol.getRunning()
            if (!liftProtocol.getBusy()
                    && liftProtocol.getPakMk()
                    && liftProtocol.getTaskNo() != 0) {
                //还有未完成的命令
@@ -136,7 +136,7 @@
    private void readStatus() {
        try {
            OperateResultExOne<byte[]> result = siemensS7Net.Read("DB100.200", (short) 24);
            OperateResultExOne<byte[]> result = siemensS7Net.Read("M100.0", (short) 28);
            if (result.IsSuccess) {
                if (null == liftProtocol) {
                    liftProtocol = new LiftProtocol();
@@ -145,97 +145,74 @@
                //----------读取提升机状态-----------
                //获取数据
//                byte[] content = result.Content;
//                //提升机锁定
//                liftProtocol.setLiftLock(CommonUtils.shortToBoolean(modbusTcpNet.getByteTransform().TransInt16(content, 0)));
//                //位置到达反馈
//                liftProtocol.setPositionArrivalFeedback(modbusTcpNet.getByteTransform().TransInt16(content,2));
//
//
//                byte b1 = modbusTcpNet.getByteTransform().TransByte(content, 5);
//                byte b2 = modbusTcpNet.getByteTransform().TransByte(content, 4);
//                int[] datas1 = CommonUtils.byteToBits(b1);
//                int[] datas2 = CommonUtils.byteToBits(b2);
//                //准备就绪
//                liftProtocol.setReady(CommonUtils.intToBoolean(datas1[0]));
//                //运行中
//                liftProtocol.setRunning(CommonUtils.intToBoolean(datas1[1]));
//                //联机/单机
//                liftProtocol.setMode(CommonUtils.intToBoolean(datas1[2]));
//                //输送线前端光电有货
//                liftProtocol.setLineFrontHasStock(CommonUtils.intToBoolean(datas1[3]));
//                //输送线正转反馈
//                liftProtocol.setForwardRotationFeedback(CommonUtils.intToBoolean(datas1[4]));
//                //输送线反转反馈
//                liftProtocol.setReverseFeedback(CommonUtils.intToBoolean(datas1[5]));
//                //输送线电机过载
//                liftProtocol.setMotorOverload(CommonUtils.intToBoolean(datas1[6]));
//                //输送线末端光电有货
//                liftProtocol.setLineEndHasStock(CommonUtils.intToBoolean(datas1[7]));
//                //进输送线卡托盘报警
//                liftProtocol.setInConveyLineCardTrayAlarm(CommonUtils.intToBoolean(datas2[0]));
//                //出输送线卡托盘报警
//                liftProtocol.setOutConveyLineCardTrayAlarm(CommonUtils.intToBoolean(datas2[1]));
//                //平台位置偏差报警
//                liftProtocol.setPlatPositionDeviationAlarm(CommonUtils.intToBoolean(datas2[2]));
//                //平台扭矩偏差报警
//                liftProtocol.setPlatTorqueDeviationAlarm(CommonUtils.intToBoolean(datas2[3]));
//                //平台四向车检测
//                liftProtocol.setPlatShuttleCheck(CommonUtils.intToBoolean(datas2[4]));
//
//                //未就绪状态
//                liftProtocol.setNotReady(modbusTcpNet.getByteTransform().TransInt16(content,6));
//                //伺服1错误
//                liftProtocol.setServoError1(modbusTcpNet.getByteTransform().TransInt16(content,8));
//                //伺服2错误
//                liftProtocol.setServoError2(modbusTcpNet.getByteTransform().TransInt16(content,10));
//                //伺服3错误
//                liftProtocol.setServoError3(modbusTcpNet.getByteTransform().TransInt16(content,12));
//                //伺服4错误
//                liftProtocol.setServoError4(modbusTcpNet.getByteTransform().TransInt16(content,14));
//                //提升机实际速度反馈
//                liftProtocol.setLiftActualSpeed(modbusTcpNet.getByteTransform().TransInt16(content,16));
//
//                ///读取提升机状态-end
//
//                //将提升机状态保存至数据库
//                BasLiftService liftService = SpringUtils.getBean(BasLiftService.class);
//                BasLift basLift = liftService.selectById(liftProtocol.getLiftNo());
//                if (basLift == null) {
//                    basLift = new BasLift();
//                    //提升机号
//                    basLift.setLiftNo(slave.getId());
//                    liftService.insert(basLift);
//                }
//                basLift.setStatus(liftProtocol.getProtocolStatus());
//                basLift.setWrkNo(liftProtocol.getTaskNo().intValue());
//                basLift.setUpdateTime(new Date());
//                basLift.setPakMk(liftProtocol.getPakMk());
//                basLift.setLiftLock(liftProtocol.getLiftLock());
//                basLift.setPositionArrivalFeedback(liftProtocol.getPositionArrivalFeedback().intValue());
//                basLift.setReady(liftProtocol.getReady());
//                basLift.setRunning(liftProtocol.getRunning());
//                basLift.setMode(liftProtocol.getMode());
//                basLift.setLineFrontHasStock(liftProtocol.getLineFrontHasStock());
//                basLift.setForwardRotationFeedback(liftProtocol.getForwardRotationFeedback());
//                basLift.setReverseFeedback(liftProtocol.getReverseFeedback());
//                basLift.setMotorOverload(liftProtocol.getMotorOverload());
//                basLift.setLineEndHasStock(liftProtocol.getLineEndHasStock());
//                basLift.setInConveyLineCardTrayAlarm(liftProtocol.getInConveyLineCardTrayAlarm());
//                basLift.setOutConveyLineCardTrayAlarm(liftProtocol.getOutConveyLineCardTrayAlarm());
//                basLift.setPlatPositionDeviationAlarm(liftProtocol.getPlatPositionDeviationAlarm());
//                basLift.setPlatTorqueDeviationAlarm(liftProtocol.getPlatTorqueDeviationAlarm());
//                basLift.setPlatShuttleCheck(liftProtocol.getPlatShuttleCheck());
//                basLift.setNotReady(liftProtocol.getNotReady().intValue());
//                basLift.setServoError1(liftProtocol.getServoError1().intValue());
//                basLift.setServoError2(liftProtocol.getServoError2().intValue());
//                basLift.setServoError3(liftProtocol.getServoError3().intValue());
//                basLift.setServoError4(liftProtocol.getServoError4().intValue());
//                basLift.setLiftActualSpeed(liftProtocol.getLiftActualSpeed().intValue());
//                if (liftService.updateById(basLift)) {
//                    OutputQueue.LIFT.offer(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功",DateUtils.convert(new Date()), slave.getId()));
////                    log.info(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功",DateUtils.convert(new Date()), slave.getId()));
//                }
                byte[] content = result.Content;
                //模式
                liftProtocol.setModel(siemensS7Net.getByteTransform().TransBool(content, 0));
                //忙闲
                liftProtocol.setBusy(siemensS7Net.getByteTransform().TransBool(content, 1));
                //前超限
                liftProtocol.setFrontOverrun(siemensS7Net.getByteTransform().TransBool(content, 7));
                //后超限
                liftProtocol.setBackOverrun(siemensS7Net.getByteTransform().TransBool(content, 8));
                //左超限
                liftProtocol.setLeftOverrun(siemensS7Net.getByteTransform().TransBool(content, 9));
                //右超限
                liftProtocol.setRightOverrun(siemensS7Net.getByteTransform().TransBool(content, 10));
                //超高
                liftProtocol.setOverHeight(siemensS7Net.getByteTransform().TransBool(content, 11));
                //超重
                liftProtocol.setOverWeight(siemensS7Net.getByteTransform().TransBool(content, 12));
                //有托盘
                liftProtocol.setHasTray(siemensS7Net.getByteTransform().TransBool(content, 16));
                //有小车
                liftProtocol.setHasCar(siemensS7Net.getByteTransform().TransBool(content, 17));
                //设备故障
                liftProtocol.setDeviceError(siemensS7Net.getByteTransform().TransBool(content, 18));
                //任务号
                liftProtocol.setTaskNo(siemensS7Net.getByteTransform().TransInt16(content, 19));
                //任务地址
                liftProtocol.setTaskAddress(siemensS7Net.getByteTransform().TransInt16(content, 21));
                //目的地址
                liftProtocol.setDistAddress(siemensS7Net.getByteTransform().TransInt16(content, 21));
                //已完成任务号
                liftProtocol.setCompleteTaskNo(siemensS7Net.getByteTransform().TransInt16(content, 23));
                //当前楼层
                liftProtocol.setLev(siemensS7Net.getByteTransform().TransInt16(content, 25));
                ///读取提升机状态-end
                //将提升机状态保存至数据库
                BasLiftService liftService = SpringUtils.getBean(BasLiftService.class);
                BasLift basLift = liftService.selectById(liftProtocol.getLiftNo());
                if (basLift == null) {
                    basLift = new BasLift();
                    //提升机号
                    basLift.setLiftNo(slave.getId());
                    liftService.insert(basLift);
                }
                basLift.setStatus(liftProtocol.getProtocolStatus());
                basLift.setWrkNo(liftProtocol.getTaskNo().intValue());
                basLift.setUpdateTime(new Date());
                basLift.setPakMk(liftProtocol.getPakMk());
                basLift.setModel(liftProtocol.getModel());
                basLift.setBusy(liftProtocol.getBusy());
                basLift.setFrontOverrun(liftProtocol.getFrontOverrun());
                basLift.setBackOverrun(liftProtocol.getBackOverrun());
                basLift.setLeftOverrun(liftProtocol.getLeftOverrun());
                basLift.setRightOverrun(liftProtocol.getRightOverrun());
                basLift.setOverHeight(liftProtocol.getOverHeight());
                basLift.setOverWeight(liftProtocol.getOverWeight());
                basLift.setHasTray(liftProtocol.getHasTray());
                basLift.setHasCar(liftProtocol.getHasCar());
                basLift.setDeviceError(liftProtocol.getDeviceError());
                basLift.setTaskAddress(liftProtocol.getTaskAddress().intValue());
                basLift.setDistAddress(liftProtocol.getDistAddress().intValue());
                basLift.setCompleteTaskNo(liftProtocol.getCompleteTaskNo().intValue());
                basLift.setLev(liftProtocol.getLev().intValue());
                if (liftService.updateById(basLift)) {
                    OutputQueue.LIFT.offer(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功",DateUtils.convert(new Date()), slave.getId()));
//                    log.info(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功",DateUtils.convert(new Date()), slave.getId()));
                }
            }else {
                OutputQueue.LIFT.offer(MessageFormat.format("【{0}】{1}提升机plc状态信息失败", DateUtils.convert(new Date()), slave.getId()));
@@ -419,42 +396,42 @@
        int size = commands.size();
        LiftAssignCommand assignCommand = redisCommand.getAssignCommand();
        if (commandStep != 0) {
            //判断上一条指令是否完成
            LiftCommand command = commands.get(commandStep - 1);
            if (command.getRun().intValue() == 1) {
                //提升机升降命令
                if (command.getDistPosition().intValue() == liftProtocol.getPositionArrivalFeedback().intValue()) {
                    //提升机目标楼层和实际楼层相同,则认定命令完成
                    command.setComplete(true);
                }
            } else if (command.getRun().intValue() == 2 || command.getRun().intValue() == 3) {
                //无货正转,有货正转
                if (!liftProtocol.getForwardRotationFeedback()) {
                    //输送线正转反馈不在运行中,认定命令完成
                    command.setComplete(true);
                }
            } else if (command.getRun().intValue() == 6 || command.getRun().intValue() == 7) {
                //有货反转,无货反转
                if (!liftProtocol.getReverseFeedback()) {
                    //输送线反转反馈不在运行中,认定命令完成
                    command.setComplete(true);
                }
            } else if (command.getRun().intValue() == 4) {
                //输送线停止
                if (!liftProtocol.getForwardRotationFeedback() && !liftProtocol.getReverseFeedback()) {
                    //输送线正转反转都不在运行中,认定命令完成
                    command.setComplete(true);
                }
            }
            //任务数据保存到redis
            redisUtil.set("lift_wrk_no_" + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand));
            if (!command.getComplete()) {
                //上一条任务未完成,禁止下发命令
                return false;
            }
        }
//        if (commandStep != 0) {
//            //判断上一条指令是否完成
//            LiftCommand command = commands.get(commandStep - 1);
//            if (command.getRun().intValue() == 1) {
//                //提升机升降命令
//                if (command.getDistPosition().intValue() == liftProtocol.getPositionArrivalFeedback().intValue()) {
//                    //提升机目标楼层和实际楼层相同,则认定命令完成
//                    command.setComplete(true);
//                }
//            } else if (command.getRun().intValue() == 2 || command.getRun().intValue() == 3) {
//                //无货正转,有货正转
//                if (!liftProtocol.getForwardRotationFeedback()) {
//                    //输送线正转反馈不在运行中,认定命令完成
//                    command.setComplete(true);
//                }
//            } else if (command.getRun().intValue() == 6 || command.getRun().intValue() == 7) {
//                //有货反转,无货反转
//                if (!liftProtocol.getReverseFeedback()) {
//                    //输送线反转反馈不在运行中,认定命令完成
//                    command.setComplete(true);
//                }
//            } else if (command.getRun().intValue() == 4) {
//                //输送线停止
//                if (!liftProtocol.getForwardRotationFeedback() && !liftProtocol.getReverseFeedback()) {
//                    //输送线正转反转都不在运行中,认定命令完成
//                    command.setComplete(true);
//                }
//            }
//            //任务数据保存到redis
//            redisUtil.set("lift_wrk_no_" + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand));
//
//            if (!command.getComplete()) {
//                //上一条任务未完成,禁止下发命令
//                return false;
//            }
//        }
        //取出命令
        LiftCommand command = commands.get(commandStep);
@@ -503,7 +480,6 @@
            return false;
        }else {
            News.info("提升机命令下发成功,提升机号={},任务数据={}", command.getLiftNo(), JSON.toJSON(command));
            liftProtocol.setWrkTime(new Date());//更新工作时间
            //将标记置为false(防止重发)
            liftProtocol.setPakMk(false);