自动化立体仓库 - WCS系统
Junjie
2023-07-26 41ac27fbf8c61af9b9a3bdfa53a8dc9069fa317a
src/main/java/com/zy/core/thread/LiftThread.java
@@ -11,8 +11,11 @@
import com.core.exception.CoolException;
import com.zy.asrs.entity.BasLift;
import com.zy.asrs.entity.BasLiftOpt;
import com.zy.asrs.entity.WrkMast;
import com.zy.asrs.mapper.WrkMastMapper;
import com.zy.asrs.service.BasLiftOptService;
import com.zy.asrs.service.BasLiftService;
import com.zy.asrs.utils.Utils;
import com.zy.common.utils.CommonUtils;
import com.zy.common.utils.RedisUtil;
import com.zy.core.DevpThread;
@@ -65,7 +68,7 @@
                switch (step) {
                    // 读数据
                    case 1:
                        readStatus();
                        read();
                        break;
                    // 写入数据
                    case 2:
@@ -109,6 +112,28 @@
    @Override
    public void close() {
        modbusTcpNet.ConnectClose();
    }
    private void read() {
        try {
            readStatus();
            //提升机处于运行状态,将标记置为true
            if (liftProtocol.getRunning()) {
                liftProtocol.setPakMk(true);
            }
            //提升机处于未运行、就绪、标记true、有任务号
            if (!liftProtocol.getRunning()
                    && liftProtocol.getPakMk()
                    && liftProtocol.getTaskNo() != 0) {
                //还有未完成的命令
                executeWork(liftProtocol.getTaskNo());
            }
        } catch (Exception e) {
            OutputQueue.LIFT.offer(MessageFormat.format("【{0}】提升机plc状态信息失败 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort()));
            initLift();
        }
    }
    private void readStatus() {
@@ -175,19 +200,6 @@
                ///读取提升机状态-end
                //提升机处于运行状态,将标记置为true
                if (liftProtocol.getRunning()) {
                    liftProtocol.setPakMk(true);
                }
                //提升机处于未运行、就绪、标记true、有任务号
                if (!liftProtocol.getRunning()
                        && liftProtocol.getPakMk()
                        && liftProtocol.getTaskNo() != 0) {
                    //还有未完成的命令
                    executeWork(liftProtocol.getTaskNo());
                }
                //将提升机状态保存至数据库
                BasLiftService liftService = SpringUtils.getBean(BasLiftService.class);
                BasLift basLift = liftService.selectById(liftProtocol.getLiftNo());
@@ -247,7 +259,7 @@
        short[] array = getCommandArr(command);//获取命令报文
        try {
            Thread.sleep(1000);//命令下发前休眠1s
            Thread.sleep(500);//命令下发前休眠
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
@@ -256,9 +268,35 @@
        if (result != null && result.IsSuccess) {
            News.info("提升机命令下发[id:{}] >>>>> {}", slave.getId(), JSON.toJSON(command));
            OutputQueue.LIFT.offer(MessageFormat.format("【{0}】[id:{1}] >>>>> 命令下发: {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command)));
            try {
                Thread.sleep(500);//命令下发后休眠
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            for (int i = 0; i < 5; i++) {
                if (command.getRun().intValue() == 4 || command.getRun().intValue() == 5) {
                    break;//系统复位和链条停止转动不需要重发
                }
                readStatus();//重新读取状态
                if (liftProtocol.getRunning()) {
                    break;
                }
                //判断是否运行中,如不运行,重新下发命令
                result = modbusTcpNet.Write("41088", array);
                News.info("提升机命令下发[id:{}] >>>>> {},次数:{}", slave.getId(), JSON.toJSON(command), i);
                OutputQueue.LIFT.offer(MessageFormat.format("【{0}】[id:{1}] >>>>> 命令下发: {2},次数:{}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command), i));
                try {
                    Thread.sleep(300);//命令下发后休眠
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            return true;
        } else {
            OutputQueue.LIFT.offer(MessageFormat.format("【{0}】写入提升机plc数据失败 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort()));
            OutputQueue.LIFT.offer(MessageFormat.format("【{0}】写入提升机plc数据失败 ===>> [id:{1}] [ip:{2}] [port:{3}],次数:{}", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort()));
            News.error("写入提升机plc数据失败 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
            return false;
        }
@@ -369,6 +407,7 @@
            return false;
        }
        WrkMastMapper wrkMastMapper = SpringUtils.getBean(WrkMastMapper.class);
        Object o = redisUtil.get("lift_wrk_no_" + wrkNo);
        if (o == null) {
            return false;
@@ -424,6 +463,7 @@
            //站点和输送线ID不为null,需要下发站点指令调度指定站点进行链条转动
            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, command.getDevpId());
            StaProtocol staProtocol = devpThread.getStation().get(command.getOperaStaNo().intValue());
            staProtocol = staProtocol.clone();
            if (!staProtocol.isLiftArrival()) {//链条转动条件,需要有提升机到位信号
                liftProtocol.setPakMk(true);
                return false;
@@ -440,6 +480,24 @@
            boolean result1 = MessageQueue.offer(SlaveType.Devp, devpId, new Task(3, staProtocol));//下发命令使输送线链条运转
        }
        WrkMast wrkMast = wrkMastMapper.selectByWorkNo(wrkNo.intValue());
        if (wrkMast != null) {
            if (wrkMast.getWrkSts() == 28) {//28.提升机搬运中
                if (command.getRun().intValue() == 1 && command.getDistPosition().intValue() == LiftLevType.TWO.lev) {
                    //提升机移动且位置是到输送线楼层,需要判断站点货物是否无物,提升机是否有物
                    DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, command.getDevpId());
                    //工作档源库位楼层
                    int wrkMastLocNoLey = Utils.getLev(wrkMast.getSourceLocNo());
                    StaProtocol staProtocol = devpThread.getStation().get(Utils.levToOutInStaNo(wrkMastLocNoLey >= 2 ? wrkMastLocNoLey + 1 : wrkMastLocNoLey));//起始站点
                    //判断输送站点是否有物,只有无物情况才能继续调度提升机
                    if (staProtocol.isLoading()) {
                        //有物禁止调度
                        return false;
                    }
                }
            }
        }
        //下发命令
        if (!write(command)) {
            News.error("提升机命令下发失败,提升机号={},任务数据={}", command.getLiftNo(), JSON.toJSON(command));