自动化立体仓库 - WCS系统
zjj
2023-11-30 f6e955d57bf5e885afde54a8c6eefe80bc1bec26
src/main/java/com/zy/core/thread/SiemensCrnThread.java
@@ -26,6 +26,7 @@
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Optional;
/**
 * 堆垛机线程
@@ -76,7 +77,7 @@
                        break;
                    // 写入数据
                    case 2:
                        write((CrnCommand) task.getData());
                        write2((CrnCommand) task.getData());
                        break;
                    // 复位
                    case 3:
@@ -430,6 +431,93 @@
        array[8] = command.getDestinationPosY();
        array[9] = command.getCommand();
        // 作业信息
        OperateResult result = siemensNet.Write("DB100.0", array);
        if (command.getAckFinish() != 1) {
            BasCrnOptService bean = SpringUtils.getBean(BasCrnOptService.class);
            BasCrnOpt basCrnOpt = new BasCrnOpt(
                    command.getTaskNo().intValue(),    // 任务号
                    command.getCrnNo(),    // 堆垛机[非空]
                    new Date(),    // 下发时间
                    command.getTaskModeType() == null ? null : 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);
        }
        if (result.IsSuccess) {
            log.warn("堆垛机命令下发[id:{},时间:{}] >>>>> {}", slave.getId(), DateUtils.convert(new Date(), DateUtils.yyyyMMddHHmmsssss_F), 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}] [rack:{4}] [slot:{5}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot()));
            log.error("写入堆垛机plc数据失败 ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot());
            return false;
        }
    }
    /**
     * 写入数据
     */
    private boolean write2(CrnCommand command){
        if (null == command) {
            log.error("堆垛机写入命令为空");
            return false;
        }
        if (command.getTaskNo() == 0 && command.getAckFinish() == 0 && command.getAuto() != 1) {
            command.setTaskNo((short) 9999);
        }
        command.setCrnNo(slave.getId());
        short[] array = new short[10];
        if (Cools.isEmpty(command.getAckFinish())) {
            array[0] = 5;
        } else {
            array[0] = command.getAckFinish();
        }
        array[1] = command.getTaskNo();
        array[2] = command.getTaskMode();
        array[3] = command.getSourcePosZ();
//        if (rowOne.contains(command.getSourcePosX())){
//            array[4] = (short)1;
//        }else if (rowTwo.contains(command.getSourcePosX())){
//            array[4] = (short)2;
//        }else if (rowThree.contains(command.getSourcePosX())){
//            array[4] = (short)3;
//        }else if (rowFour.contains(command.getSourcePosX())){
//            array[4] = (short)4;
//        }else {
            array[4] = command.getSourcePosX();
//        }
        array[5] = command.getSourcePosY();
        array[6] = command.getDestinationPosZ();
//        if (rowOne.contains(command.getDestinationPosX())){
//            array[7] = (short)1;
//        }else if (rowTwo.contains(command.getDestinationPosX())){
//            array[7] = (short)2;
//        }else if (rowThree.contains(command.getDestinationPosX())){
//            array[7] = (short)3;
//        }else if (rowFour.contains(command.getDestinationPosX())){
//            array[7] = (short)4;
//        }else {
            array[7] = command.getDestinationPosX();
//        }
        array[8] = command.getDestinationPosY();
        array[9] = command.getCommand();
        // 作业信息
@@ -453,7 +541,7 @@
                        command.getTaskNo().intValue(),    // 任务号
                        command.getCrnNo(),    // 堆垛机[非空]
                        new Date(),    // 下发时间
                        command.getTaskModeType().toString(),    // 模式
                        command.getTaskModeType() == null ? null : command.getTaskModeType().toString(),    // 模式
                        command.getSourcePosX().intValue(),    // 源排
                        command.getSourcePosY().intValue(),    // 源列
                        command.getSourcePosZ().intValue(),    // 源层