| | |
| | | private CrnSlave slave; |
| | | private CrnProtocol crnProtocol; |
| | | private boolean resetFlag = false; |
| | | private boolean resetFlagTwo = false; |
| | | |
| | | /** |
| | | * 堆垛机是否在回原点运动中标记 |
| | |
| | | |
| | | |
| | | OutputQueue.CRN.offer(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功", DateUtils.convert(new Date()), slave.getId())); |
| | | |
| | | // 复位信号 |
| | | if (!Cools.isEmpty(crnProtocol.getStatusType()) && crnProtocol.getStatusType().equals(CrnStatusType.WAITING)) { |
| | | if (!Cools.isEmpty(crnProtocol.getTaskNo()) && crnProtocol.getStatusType() == CrnStatusType.WAITING_ONE) { |
| | | // 复位信号 |
| | | if (resetFlag) { |
| | | if (crnProtocol.getTaskNo() == 9999) { |
| | | backHpFlag = false; |
| | |
| | | CrnCommand crnCommand = new CrnCommand(); |
| | | crnCommand.setAckFinish((short) 1); |
| | | if (write(crnCommand)) { |
| | | News.info("---第二步、[堆垛机号:{}, 工作号:{}]==>> 一工位复位resetFlag标记成功{}!!", |
| | | slave.getId(), crnProtocol.getTaskNo(), resetFlag); |
| | | resetFlag = false; |
| | | } else { |
| | | News.error("---第二步、[堆垛机号:{}, 工作号:{}]==>> 一工位复位resetFlag标记失败{}!!", |
| | | slave.getId(), crnProtocol.getTaskNo(), resetFlag); |
| | | } |
| | | } |
| | | } else if (!Cools.isEmpty(crnProtocol.getTaskNo()) && crnProtocol.getStatusTypeTwo() == CrnStatusType.WAITING_TWO) { |
| | | // 复位信号 |
| | | if (resetFlagTwo) { |
| | | if (crnProtocol.getTaskNo() == 9999) { |
| | | backHpFlag = false; |
| | | } |
| | | CrnCommand crnCommand = new CrnCommand(); |
| | | crnCommand.setAckFinish((short) 1); |
| | | if (write(crnCommand)) { |
| | | News.info("---第二步、[堆垛机号:{}, 工作号:{}]==>> 二工位复位resetFlag标记成功{}!!", |
| | | slave.getId(), crnProtocol.getTaskNo(), resetFlag); |
| | | resetFlagTwo = false; |
| | | } else { |
| | | News.error("---第二步、[堆垛机号:{}, 工作号:{}]==>> 二工位复位resetFlag标记失败{}!!", |
| | | slave.getId(), crnProtocol.getTaskNo(), resetFlag); |
| | | } |
| | | |
| | | } |
| | | } else if (!Cools.isEmpty(crnProtocol.getTaskNo()) && crnProtocol.getStatusType() == CrnStatusType.WAITING_All && crnProtocol.getStatusTypeTwo() == CrnStatusType.WAITING_All) { |
| | | // 复位信号 |
| | | if (resetFlag && resetFlagTwo) { |
| | | if (crnProtocol.getTaskNo() == 9999) { |
| | | backHpFlag = false; |
| | | } |
| | | CrnCommand crnCommand = new CrnCommand(); |
| | | crnCommand.setAckFinish((short) 1); |
| | | if (write(crnCommand)) { |
| | | News.info("---第二步、[堆垛机号:{}, 工作号:{}]==>> 双工位复位resetFlag标记成功{}!!", |
| | | slave.getId(), crnProtocol.getTaskNo(), resetFlag); |
| | | resetFlag = false; |
| | | resetFlagTwo = false; |
| | | } else { |
| | | News.error("---第二步、[堆垛机号:{}, 工作号:{}]==>> 双工位复位resetFlag标记失败{}!!", |
| | | slave.getId(), crnProtocol.getTaskNo(), resetFlag); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | try { |
| | | // 根据实时信息更新数据库 |
| | |
| | | News.error("SiemensCrn" + " - 6" + " - 堆垛机写入命令为空"); |
| | | return false; |
| | | } |
| | | command.setCommand((short) 1); |
| | | System.out.println("------------------"); |
| | | System.out.println(command); |
| | | // convertRow(command); |
| | | command.setCrnNo(slave.getId()); |
| | | short[] array = new short[16]; |
| | |
| | | OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB100.0", (short) 32); |
| | | if (resultRead.IsSuccess) { |
| | | CrnCommand one = new CrnCommand(); |
| | | one.setTaskNo(siemensNet.getByteTransform().TransInt16(resultRead.Content, 2)); |
| | | one.setTaskMode(siemensNet.getByteTransform().TransInt16(resultRead.Content, 4)); |
| | | one.setSourcePosX(siemensNet.getByteTransform().TransInt16(resultRead.Content, 6)); |
| | | one.setSourcePosY(siemensNet.getByteTransform().TransInt16(resultRead.Content, 8)); |
| | | one.setSourcePosZ(siemensNet.getByteTransform().TransInt16(resultRead.Content, 10)); |
| | | one.setDestinationPosX(siemensNet.getByteTransform().TransInt16(resultRead.Content, 12)); |
| | | one.setDestinationPosY(siemensNet.getByteTransform().TransInt16(resultRead.Content, 14)); |
| | | one.setDestinationPosZ(siemensNet.getByteTransform().TransInt16(resultRead.Content, 16)); |
| | | one.setSourcePosXTwo(siemensNet.getByteTransform().TransInt16(resultRead.Content, 18)); |
| | | one.setSourcePosYTwo(siemensNet.getByteTransform().TransInt16(resultRead.Content, 20)); |
| | | one.setSourcePosZTwo(siemensNet.getByteTransform().TransInt16(resultRead.Content, 22)); |
| | | one.setDestinationPosXTwo(siemensNet.getByteTransform().TransInt16(resultRead.Content, 24)); |
| | | one.setDestinationPosYTwo(siemensNet.getByteTransform().TransInt16(resultRead.Content, 26)); |
| | | one.setDestinationPosZTwo(siemensNet.getByteTransform().TransInt16(resultRead.Content, 28)); |
| | | one.setDestinationPosY(siemensNet.getByteTransform().TransInt16(resultRead.Content, 30)); |
| | | if (!command.getTaskNo().equals(one.getTaskNo()) || !command.getTaskMode().equals(one.getTaskMode()) |
| | | || !command.getSourcePosX().equals(one.getSourcePosX()) || !command.getSourcePosY().equals(one.getSourcePosY()) |
| | | || !command.getSourcePosZ().equals(one.getSourcePosZ()) || !command.getDestinationPosX().equals(one.getDestinationPosX()) |
| | | || !command.getDestinationPosY().equals(one.getDestinationPosY()) || !command.getDestinationPosZ().equals(one.getDestinationPosZ()) |
| | | || !command.getSourcePosXTwo().equals(one.getSourcePosXTwo()) || !command.getSourcePosYTwo().equals(one.getSourcePosYTwo()) |
| | | || !command.getSourcePosZTwo().equals(one.getSourcePosZTwo()) || !command.getDestinationPosXTwo().equals(one.getDestinationPosXTwo()) |
| | | || !command.getDestinationPosYTwo().equals(one.getDestinationPosYTwo()) || !command.getDestinationPosZTwo().equals(one.getDestinationPosZTwo()) |
| | | ) { |
| | | try { |
| | | log.error("堆垛机命令地址写入后回读失败==>不一致[id:{}] >>>>> 写入[{}],===>>回读[{}]", slave.getId(), JSON.toJSONString(command), JSON.toJSONString(one)); |
| | | } catch (Exception e) { |
| | | one.setTaskNo(siemensNet.getByteTransform().TransInt16(resultRead.Content, 0)); |
| | | one.setTaskMode(siemensNet.getByteTransform().TransInt16(resultRead.Content, 2)); |
| | | one.setSourcePosX(siemensNet.getByteTransform().TransInt16(resultRead.Content, 4)); |
| | | one.setSourcePosY(siemensNet.getByteTransform().TransInt16(resultRead.Content, 6)); |
| | | one.setSourcePosZ(siemensNet.getByteTransform().TransInt16(resultRead.Content, 8)); |
| | | one.setDestinationPosX(siemensNet.getByteTransform().TransInt16(resultRead.Content, 10)); |
| | | one.setDestinationPosY(siemensNet.getByteTransform().TransInt16(resultRead.Content, 12)); |
| | | one.setDestinationPosZ(siemensNet.getByteTransform().TransInt16(resultRead.Content, 14)); |
| | | one.setSourcePosXTwo(siemensNet.getByteTransform().TransInt16(resultRead.Content, 16)); |
| | | one.setSourcePosYTwo(siemensNet.getByteTransform().TransInt16(resultRead.Content, 18)); |
| | | one.setSourcePosZTwo(siemensNet.getByteTransform().TransInt16(resultRead.Content, 20)); |
| | | one.setDestinationPosXTwo(siemensNet.getByteTransform().TransInt16(resultRead.Content, 22)); |
| | | one.setDestinationPosYTwo(siemensNet.getByteTransform().TransInt16(resultRead.Content, 24)); |
| | | one.setDestinationPosZTwo(siemensNet.getByteTransform().TransInt16(resultRead.Content, 26)); |
| | | one.setCommand(siemensNet.getByteTransform().TransInt16(resultRead.Content, 28)); |
| | | one.setAckFinish(siemensNet.getByteTransform().TransInt16(resultRead.Content, 30)); |
| | | if (command.getTaskMode() != 2) { |
| | | if (!command.getTaskNo().equals(one.getTaskNo()) || !command.getTaskMode().equals(one.getTaskMode()) |
| | | || !command.getSourcePosX().equals(one.getSourcePosX()) || !command.getSourcePosY().equals(one.getSourcePosY()) |
| | | || !command.getSourcePosZ().equals(one.getSourcePosZ()) || !command.getDestinationPosX().equals(one.getDestinationPosX()) |
| | | || !command.getDestinationPosY().equals(one.getDestinationPosY()) || !command.getDestinationPosZ().equals(one.getDestinationPosZ()) |
| | | || !command.getCommand().equals(one.getCommand()) || !command.getAckFinish().equals(one.getAckFinish()) |
| | | ) { |
| | | try { |
| | | log.error("日志打印失败:===>>参数one报错 [id:{}],{}", slave.getId(), JSON.toJSONString(command), JSON.toJSONString(resultRead)); |
| | | } catch (Exception e1) { |
| | | log.error("日志打印失败:===>> [id:{}],{}", slave.getId(), JSON.toJSONString(command)); |
| | | log.error("堆垛机命令地址写入后回读失败==>不一致[id:{}] >>>>> 写入[{}],===>>回读[{}]", slave.getId(), JSON.toJSONString(command), JSON.toJSONString(one)); |
| | | } catch (Exception e) { |
| | | try { |
| | | log.error("日志打印失败:===>>参数one报错 [id:{}],{}", slave.getId(), JSON.toJSONString(command), JSON.toJSONString(resultRead)); |
| | | } catch (Exception e1) { |
| | | log.error("日志打印失败:===>> [id:{}],{}", slave.getId(), JSON.toJSONString(command)); |
| | | } |
| | | } |
| | | } |
| | | try { |
| | | Thread.sleep(100); |
| | | } catch (Exception e) { |
| | | try { |
| | | Thread.sleep(100); |
| | | } catch (Exception e) { |
| | | |
| | | } |
| | | log.error("写入堆垛机plc数据失败,重新下发任务 回读不一致 ===>> [id:{}],{},[写入次数:{}]", slave.getId(), JSON.toJSONString(command), writeCount); |
| | | result = siemensNet.Write("DB100.0", array); |
| | | writeCount++; |
| | | continue; |
| | | } else { |
| | | log.info("堆垛机命令地址写入后回读成功[id:{}] >>>>> 写入[{}],===>>回读[{}]", slave.getId(), JSON.toJSONString(command), JSON.toJSONString(one)); |
| | | break; |
| | | } |
| | | log.error("写入堆垛机plc数据失败,重新下发任务 回读不一致 ===>> [id:{}],{},[写入次数:{}]", slave.getId(), JSON.toJSONString(command), writeCount); |
| | | result = siemensNet.Write("DB100.0", array); |
| | | writeCount++; |
| | | continue; |
| | | } else { |
| | | log.info("堆垛机命令地址写入后回读成功[id:{}] >>>>> 写入[{}],===>>回读[{}]", slave.getId(), JSON.toJSONString(command), JSON.toJSONString(one)); |
| | | break; |
| | | if (!command.getTaskNo().equals(one.getTaskNo()) || !command.getTaskMode().equals(one.getTaskMode()) |
| | | || !command.getSourcePosXTwo().equals(one.getSourcePosXTwo()) || !command.getSourcePosYTwo().equals(one.getSourcePosYTwo()) |
| | | || !command.getSourcePosZTwo().equals(one.getSourcePosZTwo()) || !command.getDestinationPosXTwo().equals(one.getDestinationPosXTwo()) |
| | | || !command.getDestinationPosYTwo().equals(one.getDestinationPosYTwo()) || !command.getDestinationPosZTwo().equals(one.getDestinationPosZTwo()) |
| | | || !command.getCommand().equals(one.getCommand()) || !command.getAckFinish().equals(one.getAckFinish()) |
| | | ) { |
| | | try { |
| | | log.error("堆垛机命令地址写入后回读失败==>不一致[id:{}] >>>>> 写入[{}],===>>回读[{}]", slave.getId(), JSON.toJSONString(command), JSON.toJSONString(one)); |
| | | } catch (Exception e) { |
| | | try { |
| | | log.error("日志打印失败:===>>参数one报错 [id:{}],{}", slave.getId(), JSON.toJSONString(command), JSON.toJSONString(resultRead)); |
| | | } catch (Exception e1) { |
| | | log.error("日志打印失败:===>> [id:{}],{}", slave.getId(), JSON.toJSONString(command)); |
| | | } |
| | | } |
| | | try { |
| | | Thread.sleep(100); |
| | | } catch (Exception e) { |
| | | |
| | | } |
| | | log.error("写入堆垛机plc数据失败,重新下发任务 回读不一致 ===>> [id:{}],{},[写入次数:{}]", slave.getId(), JSON.toJSONString(command), writeCount); |
| | | result = siemensNet.Write("DB100.0", array); |
| | | writeCount++; |
| | | continue; |
| | | } else { |
| | | log.info("堆垛机命令地址写入后回读成功[id:{}] >>>>> 写入[{}],===>>回读[{}]", slave.getId(), JSON.toJSONString(command), JSON.toJSONString(one)); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | |
| | | if (command.getAckFinish() == 0) { |
| | | short commandFinish = 1; |
| | | Thread.sleep(100L); |
| | | result = siemensNet.Write("DB100.30", commandFinish); |
| | | result = siemensNet.Write("DB100.28", commandFinish); |
| | | int signFinish = 1; |
| | | while (signFinish < 5) { |
| | | OperateResultExOne<byte[]> result10018 = siemensNet.Read("DB100.30", (short) 2); |
| | | OperateResultExOne<byte[]> result10018 = siemensNet.Read("DB100.28", (short) 2); |
| | | short transInt16 = siemensNet.getByteTransform().TransInt16(result10018.Content, 0); |
| | | if (transInt16 != commandFinish) { |
| | | log.info("下发DB100.30 回读失败" + "commandFinish:" + commandFinish); |
| | | log.info("下发DB100.30 回读失败" + "array:" + JSON.toJSONString(array)); |
| | | result = siemensNet.Write("DB100.18", commandFinish); |
| | | log.info("下发DB100.28 回读失败" + "commandFinish:" + commandFinish); |
| | | log.info("下发DB100.28 回读失败" + "array:" + JSON.toJSONString(array)); |
| | | result = siemensNet.Write("DB100.28", commandFinish); |
| | | signFinish++; |
| | | } else { |
| | | log.info("下发DB100.30" + "commandFinish:" + commandFinish); |
| | | log.info("下发DB100.30" + "array:" + JSON.toJSONString(array)); |
| | | log.info("下发DB100.28" + "commandFinish:" + commandFinish); |
| | | log.info("下发DB100.28" + "array:" + JSON.toJSONString(array)); |
| | | break; |
| | | } |
| | | } |