| | |
| | | News.error("堆垛机写入命令为空"); |
| | | return false; |
| | | } |
| | | // siemensNet.Write("DB100.18", (short) 0); |
| | | // convertRow(command); |
| | | command.setCrnNo(slave.getId()); |
| | | short[] array = new short[10]; |
| | | array[0] = command.getAckFinish(); |
| | | array[1] = command.getTaskNo(); |
| | | array[2] = command.getTaskMode(); |
| | | array[3] = command.getSourcePosX(); |
| | | if (command.getSourcePosX()==4){ |
| | | array[3] = 1; |
| | | }else if (command.getSourcePosX()==5){ |
| | | array[3] = 2; |
| | | }else { |
| | | array[3] = command.getSourcePosX(); |
| | | } |
| | | |
| | | |
| | | array[4] = command.getSourcePosY(); |
| | | array[5] = command.getSourcePosZ(); |
| | | array[6] = command.getDestinationPosX(); |
| | | if (command.getDestinationPosX()==4){ |
| | | array[6] = 1; |
| | | }else if (command.getDestinationPosX()==5){ |
| | | array[6] = 2; |
| | | }else { |
| | | array[6] = command.getDestinationPosX(); |
| | | } |
| | | |
| | | array[7] = command.getDestinationPosY(); |
| | | array[8] = command.getDestinationPosZ(); |
| | | array[9] = command.getCommand(); |
| | | OperateResult result = siemensNet.Write("DB100.0", array); |
| | | OperateResult result=null; |
| | | //任务下发次数 |
| | | int writeCount = 0; |
| | | do { |
| | | result = siemensNet.Write("DB100.0", array); |
| | | if(result.IsSuccess){ |
| | | //堆垛机任务写入后,回读一次,看是否成功 |
| | | Thread.sleep(200); |
| | | OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB100.0", (short) 20); |
| | | 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()) |
| | | ){ |
| | | News.error("堆垛机命令地址写入后回读失败[id:{}] >>>>> 写入[{}],===>>回读[{}]", slave.getId(), JSON.toJSON(command),JSON.toJSON(one)); |
| | | }else{ |
| | | //任务命令写入成功 |
| | | log.info("写入堆垛机命令后返回成功,并且回读成功。堆垛机plc编号={},{},写入次数={}", slave.getId(), JSON.toJSON(command), writeCount); |
| | | break; |
| | | } |
| | | }else { |
| | | writeCount++; |
| | | log.error("写入堆垛机命令后读取失败。堆垛机plc编号={},站点数据={},写入次数={}", slave.getId(), JSON.toJSON(command), writeCount); |
| | | } |
| | | } else { |
| | | writeCount++; |
| | | log.error("写入堆垛机命令后读取失败。堆垛机plc编号={},站点数据={},写入次数={}", slave.getId(), JSON.toJSON(command), writeCount); |
| | | } |
| | | }while (writeCount<5); |
| | | |
| | | if (command.getAckFinish() == 0) { |
| | | if (result.IsSuccess) { |
| | | short commandFinish = 1; |
| | | Thread.sleep(300); |
| | | result = siemensNet.Write("DB100.18", commandFinish); |
| | | } |
| | | short commandFinish = 1; |
| | | Thread.sleep(300); |
| | | result = siemensNet.Write("DB100.18", commandFinish); |
| | | log.info("写入堆垛机命令后返回成功,并且回读成功。堆垛机plc编号={},{},写入次数={}", slave.getId(), JSON.toJSON(command), writeCount); |
| | | }else { |
| | | log.info("未写入堆垛机命令"+command.getAckFinish()); |
| | | } |
| | | log.info("堆垛机命令测试-----"+command.getAckFinish()); |
| | | |
| | | try { |
| | | // 日志记录 |