| | |
| | | @Override |
| | | public CommandResponse sendCommand(CrnCommand command) { |
| | | RedisUtil redisUtil = SpringUtils.getBean(RedisUtil.class); |
| | | redisUtil.set(RedisKeyType.CRN_SEND_COMMAND_LOCK.key + deviceConfig.getDeviceNo(), "lock", 5); |
| | | redisUtil.set(RedisKeyType.CRN_SEND_COMMAND_LOCK.key + deviceConfig.getDeviceNo(), "lock", 10); |
| | | CommandResponse response = new CommandResponse(false); |
| | | try { |
| | | if (null == command) { |
| | |
| | | } |
| | | |
| | | int idx = 0; |
| | | boolean contentFlag = false; |
| | | do { |
| | | OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB100.0", (short) 20); |
| | | if (resultRead.IsSuccess) { |
| | |
| | | if (taskNo == 0 || taskMode == 0 || sourcePosX == 0 || sourcePosY == 0 || sourcePosZ == 0 || destinationPosX == 0 || destinationPosY == 0 || destinationPosZ == 0) { |
| | | result = siemensNet.Write("DB100.0", array); |
| | | } else { |
| | | contentFlag = true; |
| | | break; |
| | | } |
| | | } |
| | |
| | | Thread.sleep(500); |
| | | } while (idx < 5); |
| | | |
| | | OperateResult confirmResult = siemensNet.Write("DB100.18", (short) 1); |
| | | if (!confirmResult.IsSuccess) { |
| | | if(!contentFlag) { |
| | | News.error("堆垛机写入任务数据失败 ===>> [id:{}]", command.getCrnNo()); |
| | | response.setMessage("堆垛机写入任务数据失败"); |
| | | return response; |
| | | } |
| | | |
| | | int confirmIdx = 0; |
| | | boolean confirmFlag = false; |
| | | do { |
| | | OperateResult confirmResult = siemensNet.Write("DB100.18", (short) 1); |
| | | if (!confirmResult.IsSuccess) { |
| | | OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB100.18", (short) 2); |
| | | if (resultRead.IsSuccess) { |
| | | short confirm = siemensNet.getByteTransform().TransInt16(resultRead.Content, 0); |
| | | if(confirm == 0) { |
| | | confirmResult = siemensNet.Write("DB100.18", (short) 1); |
| | | }else { |
| | | confirmFlag = true; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | confirmIdx++; |
| | | Thread.sleep(500); |
| | | } while (confirmIdx < 5); |
| | | |
| | | if(!confirmFlag) { |
| | | News.error("堆垛机写入确认数据失败 ===>> [id:{}]", command.getCrnNo()); |
| | | response.setMessage("堆垛机写入确认数据失败"); |
| | | return response; |
| | |
| | | OutputQueue.CRN.offer(MessageFormat.format("【{0}】[id:{1}] >>>>> 命令下发: {2}", DateUtils.convert(new Date()), command.getCrnNo(), JSON.toJSON(command))); |
| | | response.setResult(true); |
| | | response.setMessage("命令下发成功"); |
| | | redisUtil.set(RedisKeyType.CRN_SEND_COMMAND_LOCK.key + deviceConfig.getDeviceNo(), "lock", 5); |
| | | } else { |
| | | News.error("写入堆垛机plc数据失败 ===>> [id:{}]", command.getCrnNo()); |
| | | OutputQueue.CRN.offer(MessageFormat.format("【{0}】写入堆垛机plc数据失败 ===>> [id:{1}]", DateUtils.convert(new Date()), command.getCrnNo())); |