| | |
| | | command.setDestinationPosZ((short)0); // 目标库位层 |
| | | write(command); |
| | | break; |
| | | case 4: |
| | | writeAuto((CrnCommand) task.getData()); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | |
| | | log.error("堆垛机写入命令为空"); |
| | | return false; |
| | | } |
| | | if (command.getTaskNo() == 0 && command.getAckFinish() == 0) { |
| | | if (command.getTaskNo() == 0 && command.getAckFinish() == 0 && command.getAuto() != 1) { |
| | | command.setTaskNo((short) 9999); |
| | | } |
| | | |
| | | command.setCrnNo(slave.getId()); |
| | | short[] array = new short[12]; |
| | | if (command.getAckFinish() == 0) { |
| | | if (Cools.isEmpty(command.getAckFinish())) { |
| | | array[0] = 5; |
| | | } else { |
| | | array[0] = 0; |
| | | array[0] = command.getAckFinish(); |
| | | } |
| | | array[1] = command.getTaskNo(); |
| | | array[2] = command.getTaskMode(); |
| | | |
| | | array[3] = command.getDestinationPosZ(); |
| | | if (rowOne.contains(command.getSourcePosX())){ |
| | | array[4] = (short)1; |
| | | }else if (rowTwo.contains(command.getSourcePosX())){ |
| | | array[4] = (short)2; |
| | | }else if (rowThree.contains(command.getSourcePosX())){ |
| | | array[4] = (short)3; |
| | | }else if (rowFour.contains(command.getSourcePosX())){ |
| | | array[4] = (short)4; |
| | | }else { |
| | | array[3] = command.getSourcePosZ(); |
| | | // if (rowOne.contains(command.getSourcePosX())){ |
| | | // array[4] = (short)1; |
| | | // }else if (rowTwo.contains(command.getSourcePosX())){ |
| | | // array[4] = (short)2; |
| | | // }else if (rowThree.contains(command.getSourcePosX())){ |
| | | // array[4] = (short)3; |
| | | // }else if (rowFour.contains(command.getSourcePosX())){ |
| | | // array[4] = (short)4; |
| | | // }else { |
| | | array[4] = command.getSourcePosX(); |
| | | } |
| | | // } |
| | | array[5] = command.getDestinationPosY(); |
| | | |
| | | array[6] = command.getDestinationPosZ(); |
| | | if (rowOne.contains(command.getDestinationPosX())){ |
| | | array[7] = (short)1; |
| | | }else if (rowTwo.contains(command.getDestinationPosX())){ |
| | | array[7] = (short)2; |
| | | }else if (rowThree.contains(command.getDestinationPosX())){ |
| | | array[7] = (short)3; |
| | | }else if (rowFour.contains(command.getDestinationPosX())){ |
| | | array[7] = (short)4; |
| | | }else { |
| | | // if (rowOne.contains(command.getDestinationPosX())){ |
| | | // array[7] = (short)1; |
| | | // }else if (rowTwo.contains(command.getDestinationPosX())){ |
| | | // array[7] = (short)2; |
| | | // }else if (rowThree.contains(command.getDestinationPosX())){ |
| | | // array[7] = (short)3; |
| | | // }else if (rowFour.contains(command.getDestinationPosX())){ |
| | | // array[7] = (short)4; |
| | | // }else { |
| | | array[7] = command.getDestinationPosX(); |
| | | } |
| | | // } |
| | | array[8] = command.getDestinationPosY(); |
| | | array[9] = command.getCommand(); |
| | | if (!Cools.isEmpty(command.getAuto())){ |
| | | array[10] = command.getAuto(); |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | private boolean writeAuto(CrnCommand command){ |
| | | if (null == command) { |
| | | log.error("堆垛机写入命令为空"); |
| | | return false; |
| | | } |
| | | short[] array = new short[1]; |
| | | array[0] = command.getAuto(); |
| | | OperateResult result = siemensNet.Write("DB100.20", array); |
| | | |
| | | //更新命令日志 |
| | | CommandInfoLogService commandInfoLogService = SpringUtils.getBean(CommandInfoLogService.class); |
| | | CommandInfoService commandInfoService = SpringUtils.getBean(CommandInfoService.class); |
| | | CommandInfo commandInfo = commandInfoService.selectById(command.getCommandId()); |
| | | CommandInfoLog commandInfoLog = JSON.parseObject(JSON.toJSONString(commandInfo), CommandInfoLog.class); |
| | | commandInfoLog.setId(null); |
| | | |
| | | if (result.IsSuccess) { |
| | | log.warn("堆垛机命令下发[id:{},时间:{}] >>>>> {}", slave.getId(), DateUtils.convert(new Date(), DateUtils.yyyyMMddHHmmsssss_F), JSON.toJSON(command)); |
| | | OutputQueue.CRN.offer(MessageFormat.format("【{0}】[id:{1}] >>>>> 命令下发: {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command))); |
| | | |
| | | //更新指令日志 |
| | | commandInfoLog.setDeviceLog("指令下发成功"); |
| | | commandInfoLogService.insert(commandInfoLog); |
| | | |
| | | //更新任务步序 |
| | | TaskWrkService taskWrkService = SpringUtils.getBean(TaskWrkService.class); |
| | | TaskWrk taskWrk = taskWrkService.selectByWrkNo(command.getTaskNo().intValue()); |
| | | if (taskWrk != null) { |
| | | taskWrk.setCommandStep(taskWrk.getCommandStep() + 1);//更新指令步序 |
| | | taskWrkService.updateById(taskWrk); |
| | | } |
| | | |
| | | return true; |
| | | } else { |
| | | OutputQueue.CRN.offer(MessageFormat.format("【{0}】写入堆垛机plc数据失败 ===>> [id:{1}] [ip:{2}] [port:{3}] [rack:{4}] [slot:{5}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot())); |
| | | log.error("写入堆垛机plc数据失败 ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot()); |
| | | |
| | | //更新指令日志 |
| | | commandInfoLog.setDeviceLog("指令下发失败"); |
| | | commandInfoLogService.insert(commandInfoLog); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void close() { |
| | | siemensNet.ConnectClose(); |