#
Junjie
9 天以前 7f1d6410a61bc5a221619f4a7a8f5dcc86eb27b0
#
7个文件已修改
302 ■■■■■ 已修改文件
src/main/java/com/zy/asrs/controller/CrnController.java 92 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java 85 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/MainProcess.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/enums/CrnTaskModeType.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/model/command/CrnCommand.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/thread/SiemensCrnThread.java 114 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/crn.html 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/controller/CrnController.java
@@ -307,58 +307,60 @@
        return crnControl(command)?R.ok():R.error();
    }
    @ManagerAuth(memo = "回原点")
    @PostMapping("/operator/bacOrigin")
    public R crnBacOrigin(CrnOperatorParam param){
        CrnCommand command = new CrnCommand();
        command.setCrnNo(param.getCrnNo()); // 堆垛机编号
        command.setTaskNo((short) 0); // 工作号
        command.setAckFinish((short) 0);  // 任务完成确认位
        command.setTaskMode(CrnTaskModeType.GO_ORIGIN); // 任务模式
        command.setSourcePosX((short) 0);     // 源库位排
        command.setSourcePosY((short) 0);     // 源库位列
        command.setSourcePosZ((short) 0);     // 源库位层
        command.setDestinationPosX((short) 0);     // 目标库位排
        command.setDestinationPosY((short) 0);     // 目标库位列
        command.setDestinationPosZ((short) 0);     // 目标库位层
        return crnControl(command)?R.ok():R.error();
    }
    @ManagerAuth(memo = "反原点")
    @PostMapping("/operator/reverseOrigin")
    public R reverseOrigin(CrnOperatorParam param){
        CrnCommand command = new CrnCommand();
        command.setCrnNo(param.getCrnNo()); // 堆垛机编号
        command.setTaskNo((short) 0); // 工作号
        command.setAckFinish((short) 0);  // 任务完成确认位
        command.setTaskMode(CrnTaskModeType.GO_ORIGIN); // 任务模式
        command.setSourcePosX((short) 0);     // 源库位排
        command.setSourcePosY((short) 0);     // 源库位列
        command.setSourcePosZ((short) 0);     // 源库位层
        command.setDestinationPosX((short) 0);     // 目标库位排
        command.setDestinationPosY((short) 34);     // 目标库位列
        command.setDestinationPosZ((short) 5);     // 目标库位层
        return crnControl(command)?R.ok():R.error();
    }
//    @ManagerAuth(memo = "坐标移动")
//    @PostMapping("/operator/coorMove")
//    public R crnCoorMove(CrnOperatorParam param){
//    @ManagerAuth(memo = "回原点")
//    @PostMapping("/operator/bacOrigin")
//    public R crnBacOrigin(CrnOperatorParam param){
//        CrnCommand command = new CrnCommand();
//        command.setCrnNo(param.getCrnNo()); // 堆垛机编号
//        command.setTaskNo((short) 0); // 工作号
//        command.setAckFinish((short) 0);  // 任务完成确认位
//        command.setTaskMode(CrnTaskModeType.OFFSET_MOVE); // 任务模式
//        command.setSourcePosX(param.getSourceRow());     // 源库位排
//        command.setSourcePosY(param.getSourceBay());     // 源库位列
//        command.setSourcePosZ(param.getSourceLev());     // 源库位层
//        command.setDestinationPosX(param.getRow());     // 目标库位排
//        command.setDestinationPosY(param.getBay());     // 目标库位列
//        command.setDestinationPosZ(param.getLev());     // 目标库位层
//        staNoProcess(param, command);
//        command.setTaskMode(CrnTaskModeType.GO_ORIGIN); // 任务模式
//        command.setSourcePosX((short) 0);     // 源库位排
//        command.setSourcePosY((short) 0);     // 源库位列
//        command.setSourcePosZ((short) 0);     // 源库位层
//        command.setDestinationPosX((short) 0);     // 目标库位排
//        command.setDestinationPosY((short) 0);     // 目标库位列
//        command.setDestinationPosZ((short) 0);     // 目标库位层
//        return crnControl(command)?R.ok():R.error();
//    }
//    @ManagerAuth(memo = "反原点")
//    @PostMapping("/operator/reverseOrigin")
//    public R reverseOrigin(CrnOperatorParam param){
//        CrnCommand command = new CrnCommand();
//        command.setCrnNo(param.getCrnNo()); // 堆垛机编号
//        command.setTaskNo((short) 0); // 工作号
//        command.setAckFinish((short) 0);  // 任务完成确认位
//        command.setTaskMode(CrnTaskModeType.GO_ORIGIN); // 任务模式
//        command.setSourcePosX((short) 0);     // 源库位排
//        command.setSourcePosY((short) 0);     // 源库位列
//        command.setSourcePosZ((short) 0);     // 源库位层
//        command.setDestinationPosX((short) 0);     // 目标库位排
//        command.setDestinationPosY((short) 34);     // 目标库位列
//        command.setDestinationPosZ((short) 5);     // 目标库位层
//        return crnControl(command)?R.ok():R.error();
//    }
    @ManagerAuth(memo = "坐标移动")
    @PostMapping("/operator/crnMove")
    public R crnCoorMove(CrnOperatorParam param){
        CrnCommand command = new CrnCommand();
        command.setCrnNo(param.getCrnNo()); // 堆垛机编号
        command.setTaskNo((short) 9999); // 工作号
        command.setAckFinish((short) 0);  // 任务完成确认位
        command.setTaskMode(CrnTaskModeType.CRN_MOVE); // 任务模式
        command.setSourcePosX(param.getSourceRow());     // 源库位排
        command.setSourcePosY(param.getSourceBay());     // 源库位列
        command.setSourcePosZ(param.getSourceLev());     // 源库位层
        command.setDestinationPosX(param.getRow());     // 目标库位排
        command.setDestinationPosY(param.getBay());     // 目标库位列
        command.setDestinationPosZ(param.getLev());     // 目标库位层
        staNoProcess(param, command);
        boolean offer = MessageQueue.offer(SlaveType.Crn, param.getCrnNo(), new Task(4, command));
        return offer?R.ok():R.error();
    }
    @ManagerAuth(memo = "任务完成")
    @PostMapping("/operator/taskComplete")
    public R crnTaskComplete(CrnOperatorParam param){
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -631,59 +631,52 @@
    }
    /**
     * 回原点,堆垛机没有执行中任务,设备存在入库任务时叫回原点
     * 堆垛机无任务两分钟,回入库口待机
     */
    public synchronized void crnRebackHp(CrnProtocol crnProtocol, CrnThread crnThread) {
//        for (CrnSlave crn : slaveProperties.getCrn()) {
//            // 获取堆垛机信息
//            CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crn.getId());
//            CrnProtocol crnProtocol = crnThread.getCrnProtocol();
//            if (crnProtocol == null) {
//                continue;
//            }
//            BasCrnp basCrnp = basCrnpService.selectById(crn.getId());
//            if (basCrnp == null) {
//                log.error("{}号堆垛机尚未在数据库进行维护!", crn.getId());
//                continue;
//            }
        if (crnProtocol.getStatusType() == CrnStatusType.IDLE && crnProtocol.getTaskNo() == 0 && crnProtocol.getModeType() == CrnModeType.AUTO) {
            if (crnProtocol.getBay() == 1 && crnProtocol.getLevel() == 1) {
                return;
    public synchronized void crnMove() {
        for (CrnSlave crn : slaveProperties.getCrn()) {
            // 获取堆垛机信息
            CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crn.getId());
            CrnProtocol crnProtocol = crnThread.getCrnProtocol();
            if (crnProtocol == null) {
                continue;
            }
            BasCrnp basCrnp = basCrnpService.selectById(crn.getId());
            if (basCrnp == null) {
                log.error("{}号堆垛机尚未在数据库进行维护!", crn.getId());
                continue;
            }
            // 已经存在吊车执行任务时,则过滤3,12
            if (wrkMastMapper.selectWorking(crnProtocol.getCrnNo()) != null) {
                return;
            }
            if (crnProtocol.getStatusType() == CrnStatusType.IDLE && crnProtocol.getTaskNo() == 0 && crnProtocol.getModeType() == CrnModeType.AUTO) {
                if (crnProtocol.getBay() == 1 && crnProtocol.getLevel() == 1) {
                    continue;
                }
            //堆垛机有执行中任务,过滤3,4,11,12
            if (wrkMastMapper.selectCrnWorking(crnProtocol.getCrnNo()) != null) {
                return;
            }
                List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>()
                        .eq("crn_no", crn.getId()));
                if (!wrkMasts.isEmpty()) {
                    continue;
                }
            //输送线没有入库任务,过滤2
            if (wrkMastMapper.selectDevWorking(crnProtocol.getCrnNo()) == null) {
                return;
                News.info("堆垛机无任务自动回入库口待机==>>" + crnProtocol.getCrnNo() + "号堆垛机");
                // 命令下发区 --------------------------------------------------------------------------
                CrnCommand crnCommand = new CrnCommand();
                crnCommand.setCrnNo(crnProtocol.getCrnNo()); // 堆垛机编号
                crnCommand.setTaskNo((short) 9999); // 工作号
                crnCommand.setAckFinish((short) 0);  // 任务完成确认位
                crnCommand.setTaskMode(CrnTaskModeType.CRN_MOVE); // 任务模式:  堆垛机移动
                crnCommand.setSourcePosX((short) 0);     // 源库位排
                crnCommand.setSourcePosY((short) 1);     // 源库位列
                crnCommand.setSourcePosZ((short) 1);     // 源库位层
                crnCommand.setDestinationPosX((short) 0);     // 目标库位排
                crnCommand.setDestinationPosY((short) 0);     // 目标库位列
                crnCommand.setDestinationPosZ((short) 0);     // 目标库位层
                if (!MessageQueue.offer(SlaveType.Crn, crnProtocol.getCrnNo(), new Task(4, crnCommand))) {
                    News.error("堆垛机移动命令下发失败,堆垛机号={},任务数据={}", crnProtocol.getCrnNo(), JSON.toJSON(crnCommand));
                }
                crnThread.setBackHpFlag(true);
            }
            News.info("堆垛机召回原点==>>" + crnProtocol.getCrnNo() + "号堆垛机有入库任务,召回原点");
            // 命令下发区 --------------------------------------------------------------------------
            CrnCommand crnCommand = new CrnCommand();
            crnCommand.setCrnNo(crnProtocol.getCrnNo()); // 堆垛机编号
            crnCommand.setTaskNo((short) 9999); // 工作号
            crnCommand.setAckFinish((short) 0);  // 任务完成确认位
            crnCommand.setTaskMode(CrnTaskModeType.GO_ORIGIN); // 任务模式:  回原点
            crnCommand.setSourcePosX((short) 0);     // 源库位排
            crnCommand.setSourcePosY((short) 0);     // 源库位列
            crnCommand.setSourcePosZ((short) 0);     // 源库位层
            crnCommand.setDestinationPosX((short) 0);     // 目标库位排
            crnCommand.setDestinationPosY((short) 0);     // 目标库位列
            crnCommand.setDestinationPosZ((short) 0);     // 目标库位层
            if (!MessageQueue.offer(SlaveType.Crn, crnProtocol.getCrnNo(), new Task(2, crnCommand))) {
                News.error("堆垛机回原点命令下发失败,堆垛机号={},任务数据={}", crnProtocol.getCrnNo(), JSON.toJSON(crnCommand));
            }
            crnThread.setBackHpFlag(true);
        }
//        }
    }
    /**
src/main/java/com/zy/core/MainProcess.java
@@ -73,6 +73,9 @@
                    // RGV  ===>> 执行对RGV工作档的完成操作
                    mainService.rgvFinished(12);
                    //堆垛机无任务两分钟,回入库口待机
                    mainService.crnMove();
                } catch (Exception e) {
                    e.printStackTrace();
                }
src/main/java/com/zy/core/enums/CrnTaskModeType.java
@@ -9,7 +9,7 @@
    X_MOVE(4),    // 站位移转
    Y_MOVE(5),    // 站位移转
    XY_MOVE(6),    // 站位移转
    GO_ORIGIN(7),    // 回原点
    CRN_MOVE(7),    // 堆垛机移动XYZ
    BACK_ORIGIN(8),      // 回反原点
    CLEAR(9),       // 清错
    ;
src/main/java/com/zy/core/model/command/CrnCommand.java
@@ -32,7 +32,7 @@
     * 4 = 站位移转 源和目标都发
     * 5 = 回原点  不用发
     * 6 = 去反原点 目标发
     * 7 = 坐标移行 目标发
     * 7 = 坐标移行 取货发
     * 90 = 设置时间
     * 99 = 取消当前任务
     */
src/main/java/com/zy/core/thread/SiemensCrnThread.java
@@ -92,6 +92,9 @@
                        command.setDestinationPosZ((short)0);     // 目标库位层
                        write(command);
                        break;
                    case 4://堆垛机移动
                        writeMove((CrnCommand) task.getData());
                        break;
                    default:
                        break;
                }
@@ -349,6 +352,117 @@
        }
    }
    /**
     * 写入数据
     */
    private boolean writeMove(CrnCommand command) throws InterruptedException {
        if (null == command) {
            News.error("SiemensCrn"+" - 6"+" - 堆垛机写入命令为空");
            return false;
        }
        int writeAck = 0;
        do {
            OperateResult resultAck = siemensNet.Write("DB100.0", (short) 0);
            if (resultAck.IsSuccess){
                Thread.sleep(200);
                OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB100.0", (short) 2);
                short ack = siemensNet.getByteTransform().TransInt16(resultRead.Content, 0);
                if (ack != 0) {
                    writeAck++;
                }else {
                    News.info("堆垛机命令下发[id:{}] >>>>> {}", slave.getId(), "ack复位完成");
                    break;
                }
            }
        }while (writeAck <5);
//        convertRow(command);
        command.setCrnNo(slave.getId());
        short[] array = new short[10];
        array[0] = command.getAckFinish();
        array[1] = command.getTaskNo();
        array[2] = command.getTaskMode();
        array[3] = command.getSourcePosX();
        array[4] = command.getSourcePosY();
        array[5] = command.getSourcePosZ();
        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 result = null;
        int idx = 0;
        do {
            OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB100.0", (short) 4);
            if (resultRead.IsSuccess) {
                short taskNo = siemensNet.getByteTransform().TransInt16(resultRead.Content, 2);
                if(taskNo == 0) {
                    result = siemensNet.Write("DB100.0", array);
                }else {
                    break;
                }
            }
            idx++;
            Thread.sleep(500L);
        } while (idx < 5);
        if (command.getAckFinish() == 0) {
            short commandFinish = 1;
            int i = 0;
            do {
                OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB100.0", (short) 4);
                OperateResultExOne<byte[]> resultReadConfirm = siemensNet.Read("DB100.22", (short) 2);
                if (resultRead.IsSuccess && resultReadConfirm.IsSuccess) {
                    short taskNo = siemensNet.getByteTransform().TransInt16(resultRead.Content, 2);
                    short confirm = siemensNet.getByteTransform().TransInt16(resultReadConfirm.Content, 0);
                    if(taskNo != 0 && confirm == 0) {
                        result = siemensNet.Write("DB100.22", commandFinish);
                    }
                }
                i++;
                Thread.sleep(500L);
            } while (i < 5);
        }
        try {
            // 日志记录
            BasCrnOptService bean = SpringUtils.getBean(BasCrnOptService.class);
            BasCrnOpt basCrnOpt = new BasCrnOpt(
                    command.getTaskNo().intValue(),    // 任务号
                    command.getCrnNo(),    // 堆垛机[非空]
                    new Date(),    // 下发时间
                    command.getTaskModeType().toString(),    // 模式
                    command.getSourcePosX().intValue(),    // 源排
                    command.getSourcePosY().intValue(),    // 源列
                    command.getSourcePosZ().intValue(),    // 源层
                    null,    // 源站
                    command.getDestinationPosX().intValue(),    // 目标排
                    command.getDestinationPosY().intValue(),    // 目标列
                    command.getDestinationPosZ().intValue(),    // 目标层
                    null,    // 目标站
                    null,    // 响应结果
                    null,    // 修改时间
                    null    // 修改人员
            );
            bean.insert(basCrnOpt);
        } catch (Exception ignore) {}
        if (result != null && result.IsSuccess) {
            Thread.sleep(200);
            this.readStatus();
            News.info("SiemensCrn"+" - 7"+" - 堆垛机命令下发[id:{}] >>>>> {}", slave.getId(), JSON.toJSON(command));
            OutputQueue.CRN.offer(MessageFormat.format("【{0}】[id:{1}] >>>>> 命令下发: {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command)));
            return true;
        } else {
            OutputQueue.CRN.offer(MessageFormat.format("【{0}】写入堆垛机plc数据失败 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort()));
            News.error("SiemensCrn"+" - 8"+" - 写入堆垛机plc数据失败 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
            return false;
        }
    }
    @Override
    public void close() {
src/main/webapp/views/crn.html
@@ -219,7 +219,7 @@
                        <button class="item" onclick="siteMove()">站到站</button>
                        <!--                <button class="item" onclick="bacOrigin()">回原点</button>-->
                        <!--                <button class="item" onclick="reverseOrigin()">反原点</button>-->
                        <!--                <button class="item" onclick="coorMove()">坐标移行</button>-->
                        <button class="item" onclick="coorMove()">堆垛机移动</button>
                        <button class="item" onclick="taskComplete()">任务完成</button>
                        <!--                <button class="item" onclick="pause()">暂停</button>-->
                        <!--                <button class="item" onclick="boot()">启动</button>-->
@@ -432,7 +432,7 @@
    // 坐标移动
    function coorMove() {
        http.post(baseUrl+"/crn/operator/coorMove", getReqParam(), function (res) {
        http.post(baseUrl+"/crn/operator/crnMove", getReqParam(), function (res) {
            layer.msg(res.msg);
        });
    }