自动化立体仓库 - WCS系统
#
luxiaotao1123
2020-12-28 bb7ce41d7525f369a93c8b6f76a05fb90d1031b2
src/main/java/com/zy/core/thread/MelsecCrnThread.java
@@ -7,7 +7,9 @@
import com.core.common.Arith;
import com.core.common.DateUtils;
import com.core.common.SpringUtils;
import com.zy.asrs.entity.BasCrnOpt;
import com.zy.asrs.entity.BasCrnp;
import com.zy.asrs.service.BasCrnOptService;
import com.zy.asrs.service.BasCrnpService;
import com.zy.core.CrnThread;
import com.zy.core.cache.MessageQueue;
@@ -23,6 +25,7 @@
import lombok.extern.slf4j.Slf4j;
import java.text.MessageFormat;
import java.util.Calendar;
import java.util.Date;
/**
@@ -112,7 +115,39 @@
            OutputQueue.CRN.offer(MessageFormat.format("【{0}】堆垛机plc连接失败!!! ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort()));
            log.error("堆垛机plc连接失败!!! ===>> [id:{}] [ip:{}] [port:{}] ", slave.getId(), slave.getIp(), slave.getPort());
        }
        // 命令下发区 --------------------------------------------------------------------------
        /**
         *      array[1] = command.getSourcePosY(); // 列
         *         array[2] = command.getSourcePosZ(); // 层
         *         array[3] = command.getSourcePosX(); // 排
         *         array[4] = command.getDestinationPosY(); // 列
         *         array[5] = command.getDestinationPosZ();  // 层
         *         array[6] = command.getDestinationPosX(); // 排
         *         array[7] = command.getTaskNo();
         */
        Date date = new Date();
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        CrnCommand crnCommand = new CrnCommand();
        crnCommand.setCrnNo(slave.getId()); // 堆垛机编号
        crnCommand.setTaskMode(CrnTaskModeType.TIMING); // 任务模式:  设置时间
        crnCommand.setSourcePosY((short) cal.get(Calendar.YEAR));     // 年:1980~2079
        crnCommand.setSourcePosZ((short) (cal.get(Calendar.MONTH)+1));     // 月:1~12
        crnCommand.setSourcePosX((short) cal.get(Calendar.DATE));     // 日:1~31
        crnCommand.setDestinationPosY((short) cal.get(Calendar.HOUR_OF_DAY));     // 时:0~23
        crnCommand.setDestinationPosZ((short) cal.get(Calendar.MINUTE));     // 分:0~59
        crnCommand.setDestinationPosX((short) cal.get(Calendar.SECOND));     // 秒:0~59
        crnCommand.setTaskNo((short) (cal.get(Calendar.DAY_OF_WEEK) - 1));     // 星期:0(日)~6(六)
        crnCommand.setTaskSend((short) 1);
        crnCommand.setAckFinish((short) 0);
        if (write(crnCommand)) {
            log.info("堆垛机plc校对时间成功 ===>> [id:{}] [ip:{}] [port:{}] ", slave.getId(), slave.getIp(), slave.getPort());
        }
        melsecMcNet.ConnectClose();
        try {
            Thread.sleep(1000);
        } catch (InterruptedException ignore) {}
        return result;
    }
@@ -166,6 +201,7 @@
            BasCrnpService basCrnpService = SpringUtils.getBean(BasCrnpService.class);
            BasCrnp basCrnp = new BasCrnp();
            basCrnp.setCrnNo(slave.getId());
            crnProtocol.setAlarm1((short) (crnProtocol.getAlarm1() + 1000));
            if (!basCrnpService.updateById(crnProtocol.toSqlModel(basCrnp))){
                log.error("堆垛机plc数据库更新失败 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
            }
@@ -206,6 +242,30 @@
        if (result.IsSuccess) {
            log.info("堆垛机命令下发[id:{}] >>>>> {}", slave.getId(), JSON.toJSON(command));
            OutputQueue.CRN.offer(MessageFormat.format("【{0}】[id:{1}] >>>>> 命令下发: {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command)));
            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) {}
            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()));