#
Junjie
9 小时以前 fe17f760ee361185be383419c04e000776156d27
src/main/java/com/zy/core/network/real/ZyDualCrnRealConnect.java
@@ -14,8 +14,10 @@
import com.zy.asrs.service.BasCrnpOptService;
import com.zy.asrs.service.BasDualCrnpOptService;
import com.zy.asrs.utils.Utils;
import com.zy.common.utils.RedisUtil;
import com.zy.core.News;
import com.zy.core.cache.OutputQueue;
import com.zy.core.enums.RedisKeyType;
import com.zy.core.model.CommandResponse;
import com.zy.core.model.command.DualCrnCommand;
import com.zy.core.network.api.ZyDualCrnConnectApi;
@@ -40,10 +42,10 @@
        if(connect.IsSuccess){
            connected = true;
            OutputQueue.CRN.offer(MessageFormat.format( "【{0}双工位堆垛机plc连接成功 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), deviceConfig.getDeviceNo(), deviceConfig.getIp(), deviceConfig.getPort()));
            News.info("SiemensDualCrn 双工位堆垛机plc连接成功 ===>> [id:{}] [ip:{}] [port:{}]", deviceConfig.getDeviceNo(), deviceConfig.getIp(), deviceConfig.getPort());
            News.info("双工位堆垛机plc连接成功 ===>> [id:{}] [ip:{}] [port:{}]", deviceConfig.getDeviceNo(), deviceConfig.getIp(), deviceConfig.getPort());
        } else {
            OutputQueue.CRN.offer(MessageFormat.format("【{0}双工位堆垛机plc连接失败!!! ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), deviceConfig.getDeviceNo(), deviceConfig.getIp(), deviceConfig.getPort()));
            News.error("SiemensDualCrn 双工位堆垛机plc连接失败!!! ===>> [id:{}] [ip:{}] [port:{}]", deviceConfig.getDeviceNo(), deviceConfig.getIp(), deviceConfig.getPort());
            News.error("双工位堆垛机plc连接失败!!! ===>> [id:{}] [ip:{}] [port:{}]", deviceConfig.getDeviceNo(), deviceConfig.getIp(), deviceConfig.getPort());
        }
//        siemensNet.ConnectClose();
        return connected;
@@ -95,7 +97,7 @@
                crnStatus.setXDuration((double) siemensNet.getByteTransform().TransSingle(result.Content, 62));
                crnStatus.setYDuration((double) siemensNet.getByteTransform().TransSingle(result.Content, 66));
                if (crnStatus.getStatus() == 0 && crnStatus.getTaskReceive() == 0) {
                if ((crnStatus.getStatus() == 0 || crnStatus.getStatus() == 20) && crnStatus.getTaskReceive() == 0) {
                    OperateResultExOne<byte[]> taskResult = siemensNet.Read("DB100.0", (short) 18);
                    if (taskResult.IsSuccess) {
                        short taskNo = siemensNet.getByteTransform().TransInt16(taskResult.Content, 0);
@@ -109,7 +111,7 @@
                        short confirm = siemensNet.getByteTransform().TransInt16(taskResult.Content, 16);
                        if(taskNo != 0 || taskMode != 0 || sourcePosX != 0 || sourcePosY != 0 || sourcePosZ != 0 || destinationPosX != 0 || destinationPosY != 0 || destinationPosZ != 0 || confirm != 0) {
                            short[] array = new short[10];
                            short[] array = new short[9];
                            array[0] = (short) 0;
                            array[1] = (short) 0;
                            array[2] = (short) 0;
@@ -119,13 +121,18 @@
                            array[6] = (short) 0;
                            array[7] = (short) 0;
                            array[8] = (short) 0;
                            array[9] = (short) 0;
                            OperateResult taskClearResult = siemensNet.Write("DB100.0", array);
                            RedisUtil redisUtil = SpringUtils.getBean(RedisUtil.class);
                            Object lock = redisUtil.get(RedisKeyType.DUAL_CRN_SEND_COMMAND_LOCK.key + deviceConfig.getDeviceNo());
                            if (lock == null) {
                                OperateResult taskClearResult = siemensNet.Write("DB100.0", array);
                                redisUtil.set(RedisKeyType.CLEAR_DUAL_CRN_TASK_LIMIT.key + deviceConfig.getDeviceNo(), "lock", 3);
                            }
                        }
                    }
                }
                if (crnStatus.getStatusTwo() == 0 && crnStatus.getTaskReceiveTwo() == 0) {
                if ((crnStatus.getStatusTwo() == 0 || crnStatus.getStatusTwo() == 20) && crnStatus.getTaskReceiveTwo() == 0) {
                    OperateResultExOne<byte[]> taskResult = siemensNet.Read("DB100.18", (short) 18);
                    if (taskResult.IsSuccess) {
                        short taskNo = siemensNet.getByteTransform().TransInt16(taskResult.Content, 0);
@@ -139,7 +146,7 @@
                        short confirm = siemensNet.getByteTransform().TransInt16(taskResult.Content, 16);
                        if(taskNo != 0 || taskMode != 0 || sourcePosX != 0 || sourcePosY != 0 || sourcePosZ != 0 || destinationPosX != 0 || destinationPosY != 0 || destinationPosZ != 0 || confirm != 0) {
                            short[] array = new short[10];
                            short[] array = new short[9];
                            array[0] = (short) 0;
                            array[1] = (short) 0;
                            array[2] = (short) 0;
@@ -149,8 +156,12 @@
                            array[6] = (short) 0;
                            array[7] = (short) 0;
                            array[8] = (short) 0;
                            array[9] = (short) 0;
                            OperateResult taskClearResult = siemensNet.Write("DB100.18", array);
                            RedisUtil redisUtil = SpringUtils.getBean(RedisUtil.class);
                            Object lock = redisUtil.get(RedisKeyType.DUAL_CRN_SEND_COMMAND_LOCK.key + deviceConfig.getDeviceNo());
                            if (lock == null) {
                                OperateResult taskClearResult = siemensNet.Write("DB100.18", array);
                            }
                        }
                    }
                }
@@ -158,18 +169,20 @@
                return crnStatus;
            } else {
                OutputQueue.CRN.offer(MessageFormat.format("【{0}】读取双工位堆垛机plc状态信息失败 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), deviceConfig.getDeviceNo(), deviceConfig.getIp(), deviceConfig.getPort()));
                News.error("SiemensCrn 读取双工位堆垛机plc状态信息失败 ===>> [id:{}] [ip:{}] [port:{}]", deviceConfig.getDeviceNo(), deviceConfig.getIp(), deviceConfig.getPort());
                News.error("读取双工位堆垛机plc状态信息失败 ===>> [id:{}] [ip:{}] [port:{}]", deviceConfig.getDeviceNo(), deviceConfig.getIp(), deviceConfig.getPort());
            }
        } catch (Exception e) {
            e.printStackTrace();
            OutputQueue.CRN.offer(MessageFormat.format("【{0}】读取双工位堆垛机plc状态信息失败 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), deviceConfig.getDeviceNo(), deviceConfig.getIp(), deviceConfig.getPort()));
            News.error("SiemensCrn 读取双工位堆垛机plc状态信息失败 ===>> [id:{}] [ip:{}] [port:{}]", deviceConfig.getDeviceNo(), deviceConfig.getIp(), deviceConfig.getPort());
            News.error("读取双工位堆垛机plc状态信息失败 ===>> [id:{}] [ip:{}] [port:{}]", deviceConfig.getDeviceNo(), deviceConfig.getIp(), deviceConfig.getPort());
        }
        return null;
    }
    @Override
    public CommandResponse sendCommand(DualCrnCommand command) {
        RedisUtil redisUtil = SpringUtils.getBean(RedisUtil.class);
        redisUtil.set(RedisKeyType.DUAL_CRN_SEND_COMMAND_LOCK.key + deviceConfig.getDeviceNo(), "lock", 10);
        CommandResponse response = new CommandResponse(false);
         try {
             if (null == command) {
@@ -248,6 +261,7 @@
                 OutputQueue.CRN.offer(MessageFormat.format("【{0}】[id:{1}] >>>>> 命令下发: {2}", DateUtils.convert(new Date()), command.getCrnNo(), JSON.toJSON(command)));
                 response.setResult(true);
                 response.setMessage("命令下发成功");
                 redisUtil.set(RedisKeyType.DUAL_CRN_SEND_COMMAND_LOCK.key + deviceConfig.getDeviceNo(), "lock", 5);
             } else {
                 News.error("双工位堆垛机写入堆垛机plc数据失败 ===>> [id:{}]", command.getCrnNo());
                 OutputQueue.CRN.offer(MessageFormat.format("【{0}】写入堆垛机plc数据失败 ===>> [id:{1}]", DateUtils.convert(new Date()), command.getCrnNo()));