#
Junjie
13 小时以前 59b45c1c24ad7ca63902813b86705d7c460fa505
#
1个文件已修改
73 ■■■■ 已修改文件
src/main/java/com/zy/core/network/real/ZyStationRealConnect.java 73 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/network/real/ZyStationRealConnect.java
@@ -177,54 +177,55 @@
    @Override
    public CommandResponse sendCommand(Integer deviceNo, StationCommand command) {
        CommandResponse commandResponse = new CommandResponse(false);
        if (null == command) {
            commandResponse.setMessage("命令为空");
            return commandResponse;
        }
        try {
            if (null == command) {
                commandResponse.setMessage("命令为空");
                return commandResponse;
            }
        int index = findIndex(command.getStationId());
        if (index < 0) {
            commandResponse.setMessage("站点不存在");
            return commandResponse;
        }
            int index = findIndex(command.getStationId());
            if (index < 0) {
                commandResponse.setMessage("站点不存在");
                return commandResponse;
            }
        OperateResult write = null;
        // 任务下发次数
        int writeCount = 0;
        do {
            short[] data = new short[2];
            data[0] = command.getTaskNo().shortValue();
            data[1] = command.getTargetStaNo().shortValue();
            boolean commandSendResult = false;
            // 任务下发次数
            int writeCount = 0;
            do {
                short[] data = new short[2];
                data[0] = command.getTaskNo().shortValue();
                data[1] = command.getTargetStaNo().shortValue();
            write = siemensNet.Write("DB100." + index * 4, data);
            if (write.IsSuccess) {
                log.error("写入输送线命令成功。站点编号={},站点数据={},写入次数={}", command.getStationId(), JSON.toJSON(command),
                        writeCount);
                commandResponse.setResult(true);
                break;
            } else {
                OperateResult write = siemensNet.Write("DB100." + index * 4, data);
                if (write.IsSuccess) {
                    log.error("写入输送线命令成功。站点编号={},站点数据={},写入次数={}", command.getStationId(), JSON.toJSON(command),
                            writeCount);
                    commandSendResult = true;
                    break;
                } else {
                    Thread.sleep(300);
                }
                writeCount++;
            } while (writeCount < 5);
            if (!commandSendResult) {
                log.error("写入输送线命令失败。站点编号={},站点数据={},写入次数={}", command.getStationId(), JSON.toJSON(command),
                        writeCount);
                commandResponse.setResult(false);
                commandResponse.setMessage("写入命令失败");
                return commandResponse;
            }
        } while (writeCount < 5);
        if (write == null) {
            commandResponse.setMessage("写入命令失败");
            return commandResponse;
        }
        if (!write.IsSuccess) {
            ZyStationStatusEntity staProtocol = findStatusEntity(command.getStationId());
            OutputQueue.DEVP.offer(MessageFormat.format("写入输送线站点数据失败。站点编号={1},站点数据={2}", command.getStationId(),
                    JSON.toJSON(staProtocol)));
            News.error("写入输送线站点数据失败。站点编号={},站点数据={}", command.getStationId(), JSON.toJSON(staProtocol));
        } else {
            OutputQueue.DEVP.offer(MessageFormat.format("【{0}】 输送线命令下发 [id:{1}] >>>>> {2}",
                    DateUtils.convert(new Date()), command.getStationId(), JSON.toJSON(command)));
            News.info("输送线命令下发 [id:{}] >>>>> 命令下发: {}", command.getStationId(),
                    JSON.toJSON(command));
            commandResponse.setResult(true);
            commandResponse.setMessage("命令下发成功");
            return commandResponse;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return commandResponse;
    }