| | |
| | | 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[]> readResult = siemensNet.Read("DB100.0", (short) 20); |
| | | if(readResult.IsSuccess){ |
| | | short ackFinish = siemensNet.getByteTransform().TransInt16(readResult.Content, 0); |
| | | short taskNo = siemensNet.getByteTransform().TransInt16(readResult.Content, 2); |
| | | if(command.getTaskNo().equals(taskNo) && command.getAckFinish().equals(ackFinish)){ |
| | | //任务命令写入成功 |
| | | 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); |
| | | } |
| | | } |
| | | 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); |
| | | } |
| | | |
| | | try { |