#
Administrator
2 天以前 b256cdb895234a3e68da88310325b5eb38600777
#
2个文件已修改
191 ■■■■ 已修改文件
src/main/java/com/zy/core/network/real/ZyCrnRealConnect.java 125 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/network/real/ZyStationRealConnect.java 66 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/network/real/ZyCrnRealConnect.java
@@ -108,23 +108,32 @@
            }
            int writeAck = 0;
            boolean commandResult = false;
            do {
                OperateResult resultAck = siemensNet.Write("DB100.0", (short) 0);
                if (resultAck.IsSuccess) {
                    Thread.sleep(200);
                    OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB100.0", (short) 2);
                    short ack = siemensNet.getByteTransform().TransInt16(resultRead.Content, 0);
                    if (ack != 0) {
                        writeAck++;
                    } else {
                        News.info("堆垛机命令下发[id:{}] >>>>> {}", command.getCrnNo(), "ack复位完成");
                        break;
                OperateResult result = siemensNet.Write("DB100.0", (short) 0);
                if (result.IsSuccess) {
                    OperateResultExOne<byte[]> commandReadResult = siemensNet.Read("DB100.0", (short) 2);
                    if (commandReadResult.IsSuccess) {
                        short commandRead = siemensNet.getByteTransform().TransInt16(commandReadResult.Content, 0);
                        if (commandRead == 1) {
                            Thread.sleep(500);
                        }else {
                            commandResult = true;
                            break;
                        }
                    }
                }
                writeAck++;
                Thread.sleep(200);
            } while (writeAck < 5);
            if (!commandResult) {
                response.setMessage("堆垛机命令下发[id:{}] >>>>> {}" + command.getCrnNo() + "任务状态位异常");
                return response;
            }
            short[] array = new short[9];
            array[0] = (short) 0;
            array[0] = command.getAckFinish().shortValue();
            array[1] = command.getTaskNo().shortValue();
            array[2] = command.getTaskMode().shortValue();
            array[3] = command.getSourcePosX().shortValue();
@@ -134,62 +143,68 @@
            array[7] = command.getDestinationPosY().shortValue();
            array[8] = command.getDestinationPosZ().shortValue();
            OperateResult result = siemensNet.Write("DB100.0", array);
            if (!result.IsSuccess) {
                response.setMessage("堆垛机命令下发[id:{}] >>>>> {}" + command.getCrnNo() + "任务状态位异常");
                return response;
            }
            int idx = 0;
            boolean commandDataResult = false;
            do {
                OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB100.0", (short) 20);
                if (resultRead.IsSuccess) {
                    short taskNo = siemensNet.getByteTransform().TransInt16(resultRead.Content, 2);
                    short taskMode = siemensNet.getByteTransform().TransInt16(resultRead.Content, 4);
                    short sourcePosX = siemensNet.getByteTransform().TransInt16(resultRead.Content, 6);
                    short sourcePosY = siemensNet.getByteTransform().TransInt16(resultRead.Content, 8);
                    short sourcePosZ = siemensNet.getByteTransform().TransInt16(resultRead.Content, 10);
                    short destinationPosX = siemensNet.getByteTransform().TransInt16(resultRead.Content, 12);
                    short destinationPosY = siemensNet.getByteTransform().TransInt16(resultRead.Content, 14);
                    short destinationPosZ = siemensNet.getByteTransform().TransInt16(resultRead.Content, 16);
                    if (taskNo == 0 || taskMode == 0 || sourcePosX == 0 || sourcePosY == 0 || sourcePosZ == 0 || destinationPosX == 0 || destinationPosY == 0 || destinationPosZ == 0) {
                        result = siemensNet.Write("DB100.0", array);
                    } else {
                        break;
                OperateResult result = siemensNet.Write("DB100.0", array);
                if (result.IsSuccess) {
                    OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB100.0", (short) 20);
                    if (resultRead.IsSuccess) {
                        short taskNo = siemensNet.getByteTransform().TransInt16(resultRead.Content, 2);
                        short taskMode = siemensNet.getByteTransform().TransInt16(resultRead.Content, 4);
                        short sourcePosX = siemensNet.getByteTransform().TransInt16(resultRead.Content, 6);
                        short sourcePosY = siemensNet.getByteTransform().TransInt16(resultRead.Content, 8);
                        short sourcePosZ = siemensNet.getByteTransform().TransInt16(resultRead.Content, 10);
                        short destinationPosX = siemensNet.getByteTransform().TransInt16(resultRead.Content, 12);
                        short destinationPosY = siemensNet.getByteTransform().TransInt16(resultRead.Content, 14);
                        short destinationPosZ = siemensNet.getByteTransform().TransInt16(resultRead.Content, 16);
                        if (taskNo == 0 || taskMode == 0 || sourcePosX == 0 || sourcePosY == 0 || sourcePosZ == 0 || destinationPosX == 0 || destinationPosY == 0 || destinationPosZ == 0) {
                            result = siemensNet.Write("DB100.0", array);
                        } else {
                            commandDataResult = true;
                            break;
                        }
                    }
                }
                idx++;
                Thread.sleep(500);
                Thread.sleep(200);
            } while (idx < 5);
            OperateResult confirmResult = siemensNet.Write("DB100.18", (short) 1);
            if (!confirmResult.IsSuccess) {
            if (!commandDataResult) {
                response.setMessage("堆垛机命令下发[id:{}] >>>>> {}" + command.getCrnNo() + "堆垛机写入任务数据失败");
                return response;
            }
            int writeConfirmIdx = 0;
            boolean commandConfirmResult = false;
            do {
                OperateResult result = siemensNet.Write("DB100.18", (short) 1);
                if (result.IsSuccess) {
                    OperateResultExOne<byte[]> commandReadResult = siemensNet.Read("DB100.18", (short) 2);
                    if (commandReadResult.IsSuccess) {
                        short commandRead = siemensNet.getByteTransform().TransInt16(commandReadResult.Content, 0);
                        if (commandRead == 0) {
                            Thread.sleep(500);
                        }else {
                            commandConfirmResult = true;
                            break;
                        }
                    }
                }
                writeConfirmIdx++;
                Thread.sleep(200);
            } while (writeConfirmIdx < 5);
            if (!commandConfirmResult) {
                News.error("堆垛机写入确认数据失败 ===>> [id:{}]", command.getCrnNo());
                response.setMessage("堆垛机写入确认数据失败");
                return response;
            }
            if (result != null && result.IsSuccess) {
                News.info("堆垛机命令下发[id:{}] >>>>> {}", command.getCrnNo(), JSON.toJSON(command));
                OutputQueue.CRN.offer(MessageFormat.format("【{0}】[id:{1}] >>>>> 命令下发: {2}", DateUtils.convert(new Date()), command.getCrnNo(), JSON.toJSON(command)));
                response.setResult(true);
                response.setMessage("命令下发成功");
            } else {
                News.error("写入堆垛机plc数据失败 ===>> [id:{}]", command.getCrnNo());
                OutputQueue.CRN.offer(MessageFormat.format("【{0}】写入堆垛机plc数据失败 ===>> [id:{1}]", DateUtils.convert(new Date()), command.getCrnNo()));
                response.setResult(false);
                response.setMessage("命令下发失败");
            }
            if (!Cools.isEmpty(command.getLocNo())){
                OperateResult resultAck = siemensNet.Write("DB110." + command.getIndex() * 2, command.getValue());
                if (resultAck.IsSuccess) {
                    News.info("库位白色灯命令下发[locNo:{}] >>>>> {}", command.getLocNo(), command.getValue());
                } else {
                    News.error("库位白色灯命令下发失败[locNo:{}] >>>>> {}", command.getLocNo(), command.getValue());
                }
            }
            News.info("堆垛机命令下发[id:{}] >>>>> {}", command.getCrnNo(), JSON.toJSON(command));
            OutputQueue.CRN.offer(MessageFormat.format("【{0}】[id:{1}] >>>>> 命令下发: {2}", DateUtils.convert(new Date()), command.getCrnNo(), JSON.toJSON(command)));
            response.setResult(true);
            response.setMessage("命令下发成功");
            return response;
        } catch (Exception e) {
            e.printStackTrace();
src/main/java/com/zy/core/network/real/ZyStationRealConnect.java
@@ -184,56 +184,52 @@
    @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;
        OperateResult write1 = null;
        // 任务下发次数
        int writeCount = 0;
        do {
            boolean commandSendResult = false;
            // 任务下发次数
            int writeCount = 0;
            do {
//            short[] data = new short[2];
//            data[0] = command.getTaskNo();
//            data[1] = command.getTargetStaNo().shortValue();
            write = siemensNet.Write("DB100." + index * 6, command.getTaskNo());
            write1 =siemensNet.Write("DB100." + (index * 6+4), command.getTargetStaNo().shortValue());
            if (write.IsSuccess&&write1.IsSuccess) {
                log.error("写入输送线命令成功。站点编号={},站点数据={},写入次数={}", command.getStationId(), JSON.toJSON(command),
                        writeCount);
                commandResponse.setResult(true);
                break;
            } else {
                OperateResult write = siemensNet.Write("DB100." + index * 6, command.getTaskNo());
                OperateResult write1 = siemensNet.Write("DB100." + (index * 6 + 4), command.getTargetStaNo().shortValue());
                if (write.IsSuccess && write1.IsSuccess) {
                    commandSendResult = true;
                    break;
                }
                writeCount++;
                Thread.sleep(300);
            } 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;
    }