| | |
| | | //array[9] = command.getCommand(); |
| | | OperateResult result = siemensNet.Write("DB100.0", array); |
| | | |
| | | |
| | | log.info("堆垛机命令下发[id:{}] >>>>> {}", slave.getId(), array); |
| | | |
| | | |
| | | |
| | | //堆垛机任务写入后,回读一次,看是否成功 |
| | | Thread.sleep(200); |
| | | int writeCount = 1; |
| | | do { |
| | | try{ |
| | | if(!result.IsSuccess){ |
| | | log.error("写入堆垛机plc数据失败,重新下发任务 写入直接失败 ===>> [id:{}],{},[写入次数:{}]", slave.getId(), JSON.toJSONString(command),writeCount); |
| | | result = siemensNet.Write("DB100.0", array); |
| | | Thread.sleep(100); |
| | | writeCount++; |
| | | continue; |
| | | } |
| | | OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB100.0", (short) 24); |
| | | 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)); |
| | | 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()) |
| | | ){ |
| | | 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){ |
| | | log.error("堆垛机命令地址写入后回读出错,异常:"+e); |
| | | } |
| | | writeCount++; |
| | | } while (writeCount<6); |
| | | |
| | | if (command.getAckFinish() == 0) { |
| | | short commandFinish = 1; |
| | | Thread.sleep(100L); |
| | | result = siemensNet.Write("DB100.18", commandFinish); |
| | | int signFinish = 1; |
| | | while (signFinish<5){ |
| | | OperateResultExOne<byte[]> result10018 = siemensNet.Read("DB100.18", (short) 2); |
| | | short transInt16 = siemensNet.getByteTransform().TransInt16(result10018.Content, 0); |
| | | if (transInt16 != commandFinish){ |
| | | log.info("下发DB100.18 回读失败" + "commandFinish:"+commandFinish); |
| | | log.info("下发DB100.18 回读失败" + "array:"+ JSON.toJSONString(array)); |
| | | result = siemensNet.Write("DB100.18", commandFinish); |
| | | signFinish++; |
| | | }else { |
| | | log.info("下发DB100.18" + "commandFinish:"+commandFinish); |
| | | log.info("下发DB100.18" + "array:"+ JSON.toJSONString(array)); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | // if (command.getAckFinish() == 0) { |
| | | // short commandFinish = 1; |
| | | // Thread.sleep(100L); |
| | | // result = siemensNet.Write("DB100.18", commandFinish); |
| | | // } |
| | | |
| | | try { |
| | | // 日志记录 |