#
Administrator
2 天以前 f071edb869770c51249d1b06e535da91863a8362
src/main/java/com/zy/core/network/real/ZyCrnRealConnect.java
@@ -10,6 +10,7 @@
import com.zy.asrs.entity.DeviceConfig;
import com.zy.core.News;
import com.zy.core.cache.OutputQueue;
import com.zy.core.enums.CrnTaskModeType;
import com.zy.core.model.CommandResponse;
import com.zy.core.model.command.CrnCommand;
import com.zy.core.network.api.ZyCrnConnectApi;
@@ -108,25 +109,57 @@
            }
            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;
            }
            Integer commandTaskNo = command.getTaskNo();
            Integer commandTaskMode = command.getTaskMode();
            if (commandTaskMode.equals(CrnTaskModeType.RESET.id)) {
                commandTaskNo = 0;
                commandTaskMode = 0;
                if (!Cools.isEmpty(command.getLocNo())){
                    OperateResult resultAck = siemensNet.Write("DB110." + command.getIndex() * 2, command.getValue());
                    if (resultAck.IsSuccess) {
                        Integer index = command.getIndex()*2 + 200;
                        OperateResult resultAck1 = siemensNet.Write("DB110." + index, command.getValue());
                        if (resultAck1.IsSuccess) {
                            News.info("库位橙色按钮命令下发[locNo:{}] >>>>> {}", command.getLocNo(), command.getValue());
                        } else {
                            News.error("库位白色灯命令下发失败[locNo:{}] >>>>> {}", command.getLocNo(), command.getValue());
                        }
                        News.info("库位白色灯命令下发[locNo:{}] >>>>> {}", command.getLocNo(), command.getValue());
                    } else {
                        News.error("库位白色灯命令下发失败[locNo:{}] >>>>> {}", command.getLocNo(), command.getValue());
                    }
                }
            }
            short[] array = new short[9];
            array[0] = (short) 0;
            array[1] = command.getTaskNo().shortValue();
            array[2] = command.getTaskMode().shortValue();
            array[0] = command.getAckFinish().shortValue();
            array[1] = commandTaskNo.shortValue();
            array[2] = commandTaskMode.shortValue();
            array[3] = command.getSourcePosX().shortValue();
            array[4] = command.getSourcePosY().shortValue();
            array[5] = command.getSourcePosZ().shortValue();
@@ -134,163 +167,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 < 1);
            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());
                }
            }
            return response;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return response;
    }
    @Override
    public CommandResponse sendCommand1(CrnCommand command) {
        CommandResponse response = new CommandResponse(false);
        try {
            if (null == command) {
                News.error("堆垛机写入命令为空");
                response.setMessage("堆垛机写入命令为空");
                return response;
            }
            int writeAck = 0;
            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;
                    }
                }
            } while (writeAck < 5);
            short[] array = new short[10];
            array[0] = (short) 1;
            array[1] = command.getTaskNo().shortValue();
            array[2] = command.getTaskMode().shortValue();
            array[3] = command.getSourcePosX().shortValue();
            array[4] = command.getSourcePosY().shortValue();
            array[5] = command.getSourcePosZ().shortValue();
            array[6] = command.getDestinationPosX().shortValue();
            array[7] = command.getDestinationPosY().shortValue();
            array[8] = command.getDestinationPosZ().shortValue();
            array[9] = (short) 0;
            OperateResult result = siemensNet.Write("DB100.0", array);
            if (!result.IsSuccess) {
                response.setMessage("堆垛机命令下发[id:{}] >>>>> {}" + command.getCrnNo() + "任务状态位异常");
                return response;
            }
            int idx = 0;
            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;
                    }
                }
                idx++;
                Thread.sleep(500);
            } while (idx < 5);
            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) {
                    Integer index = command.getIndex()*2 + 200;
                    OperateResult resultAck1 = siemensNet.Write("DB110." + index, command.getValue());
                    if (resultAck1.IsSuccess) {
                        News.info("库位橙色按钮命令下发[locNo:{}] >>>>> {}", command.getLocNo(), command.getValue());
                    } else {
                        News.error("库位白色灯命令下发失败[locNo:{}] >>>>> {}", command.getLocNo(), command.getValue());
                    }
                    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();
@@ -336,7 +274,7 @@
            if (resultAck.IsSuccess) {
                News.info("库位橙色按钮命令下发[locNo:{}] >>>>> {}", command.getLocNo(), command.getValue());
            } else {
                News.error("库位白色灯命令下发失败[locNo:{}] >>>>> {}", command.getLocNo(), command.getValue());
                News.error("库位橙色按钮命令下发失败[locNo:{}] >>>>> {}", command.getLocNo(), command.getValue());
            }
            return response;
        } catch (Exception e) {