#
luxiaotao1123
2021-12-30 7136bbbfcd5c2e42793dc05aa8cf49912ee430a7
src/main/java/com/zy/core/thread/CrnThread.java
@@ -7,7 +7,9 @@
import com.core.common.DateUtils;
import com.core.common.SpringUtils;
import com.core.exception.CoolException;
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.ThreadHandler;
import com.zy.core.cache.MessageQueue;
@@ -115,7 +117,7 @@
        try {
            /* 方法1 */
            OperateResultExOne<byte[]> result = melsecMcNet.Read("D2231", (short) 62);
            OperateResultExOne<byte[]> result = melsecMcNet.Read("D2231", (short) 70);
            if (result.IsSuccess) {
                if (null == crnProtocol) {
                    crnProtocol = new CrnProtocol();
@@ -131,7 +133,6 @@
//               crnProtocol.setTaskFinish(melsecMcNet.getByteTransform().TransInt16(result.Content, 18));
                crnProtocol.setLoaded(melsecMcNet.getByteTransform().TransInt16(result.Content, 20));
                crnProtocol.setAlarm(melsecMcNet.getByteTransform().TransInt16(result.Content, 22));
                crnProtocol.setError1(melsecMcNet.getByteTransform().TransBool(result.Content, 24, 2));
                crnProtocol.setTemp1(melsecMcNet.getByteTransform().TransBool(result.Content, 26, 2));
                crnProtocol.setTemp2(melsecMcNet.getByteTransform().TransInt16(result.Content, 28));
                crnProtocol.setTemp3(melsecMcNet.getByteTransform().TransInt16(result.Content, 30));
@@ -142,12 +143,13 @@
                crnProtocol.setXDistance(melsecMcNet.getByteTransform().TransSingle(result.Content, 46));
                crnProtocol.setYDistance(melsecMcNet.getByteTransform().TransSingle(result.Content, 50));
                crnProtocol.setXDuration(melsecMcNet.getByteTransform().TransSingle(result.Content, 54));
                crnProtocol.setYDuration(melsecMcNet.getByteTransform().TransSingle(result.Content, 58));
                crnProtocol.setYDuration(melsecMcNet.getByteTransform().TransSingle(result.Content, 62));
                OutputQueue.CRN.offer(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功",DateUtils.convert(new Date()), slave.getId()));
                // 复位信号
                if (crnProtocol.getStatusType().equals(CrnStatusType.WAITING)) {
                    log.error("-------------------------------------------第一步、[堆垛机号:{}][工作号:{}]==>> 状态为90,等待确认!!",slave.getId(),crnProtocol.getTaskNo());
                    if (resetFlag) {
                        if (melsecMcNet.Write("D2218", (short) 1).IsSuccess) {
                            resetFlag = false;
@@ -158,13 +160,15 @@
                // 根据实时信息更新数据库
                BasCrnpService basCrnpService = SpringUtils.getBean(BasCrnpService.class);
                BasCrnp basCrnp = new BasCrnp();
                basCrnp.setCrnErr(crnProtocol.getAlarm()==null?0:crnProtocol.getAlarm().longValue());
                basCrnp.setCrnNo(slave.getId());
                if (!basCrnpService.updateById(crnProtocol.toSqlModel(basCrnp))){
                    log.error("堆垛机plc数据库更新失败 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
                }
            } else {
                throw new CoolException("堆垛机plc状态信息失败");
                OutputQueue.CRN.offer(MessageFormat.format("【{0}】{1}堆垛机plc状态信息失败",DateUtils.convert(new Date()), slave.getId()));
                throw new CoolException(MessageFormat.format( "堆垛机plc状态信息失败 ===>> [id:{0}] [ip:{1}] [port:{2}]", slave.getId(), slave.getIp(), slave.getPort()));
            }
            /* 方法2 */
//            crnProtocol.setMode(melsecMcNet.ReadInt16("D2231").Content);
@@ -237,6 +241,29 @@
                if (!melsecMcNet.Write("D2218", command.getAckFinish()).IsSuccess) { break; }
            }
            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) {}
            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)));
@@ -266,13 +293,6 @@
    @Override
    public void close() {
        melsecMcNet.ConnectClose();
    }
    public CrnProtocol getCrnProtocol(){
        if (crnProtocol == null) {
            readStatus();
        }
        return this.crnProtocol;
    }