| | |
| | | News.error("四向穿梭车写入命令为空"); |
| | | return false; |
| | | } |
| | | |
| | | BasShuttleService shuttleService = SpringUtils.getBean(BasShuttleService.class); |
| | | if (shuttleService == null) { |
| | | News.error("系统错误"); |
| | |
| | | News.error("四向穿梭车不存在"); |
| | | return false; |
| | | } |
| | | |
| | | command.setShuttleNo(slave.getId().shortValue()); |
| | | short[] array = getCommandArr(command);//获取命令报文 |
| | | OperateResult result = modbusTcpNet.Write("0", array); |
| | | if (result != null && result.IsSuccess) { |
| | | News.info("四向穿梭车命令下发[id:{}] >>>>> {}", slave.getId(), JSON.toJSON(command)); |
| | | OutputQueue.SHUTTLE.offer(MessageFormat.format("【{0}】[id:{1}] >>>>> 命令下发: {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command))); |
| | | |
| | | try { |
| | | Thread.sleep(3000);//命令下发后休眠 |
| | | } catch (InterruptedException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | |
| | | for (int i = 0; i < 5; i++) { |
| | | readStatus();//重新读取状态 |
| | | if (shuttleProtocol.getBusyStatusType().equals(ShuttleStatusType.BUSY)) { |
| | | break; |
| | | } |
| | | |
| | | //判断是否运行中,如不运行,重新下发命令 |
| | | result = modbusTcpNet.Write("0", array); |
| | | News.info("四向穿梭车命令下发[id:{}] >>>>> {},次数:{}", slave.getId(), JSON.toJSON(command), i); |
| | | OutputQueue.SHUTTLE.offer(MessageFormat.format("【{0}】[id:{1}] >>>>> 命令下发: {2},次数:{}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command), i)); |
| | | try { |
| | | Thread.sleep(3000);//命令下发后休眠 |
| | | } catch (InterruptedException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | |
| | | return true; |
| | | } else { |
| | | OutputQueue.SHUTTLE.offer(MessageFormat.format("【{0}】写入四向穿梭车plc数据失败 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort())); |
| | | News.error("写入四向穿梭车plc数据失败 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | //获取命令报文 |
| | | private short[] getCommandArr(ShuttleCommand command) { |
| | | // 开始任务 |
| | | short[] array = new short[17]; |
| | | //控制指令字 |
| | |
| | | array[7] = middleToDistDistances[1]; |
| | | } |
| | | |
| | | array[8] = basShuttle.getRunSpeed().shortValue();//四向穿梭车运行速度,从系统数据库读出 |
| | | if (command.getRunDirection() != null) { |
| | | //小车运行方向 |
| | | array[8] = command.getRunDirection(); |
| | |
| | | //小车雷达备用 |
| | | array[15] = command.getRadarTmp(); |
| | | } |
| | | |
| | | //指令结束位 |
| | | array[16] = command.getCommandEnd(); |
| | | |
| | | OperateResult result = modbusTcpNet.Write("0", array);; |
| | | if (result != null && result.IsSuccess) { |
| | | try { |
| | | Thread.sleep(3000);//命令下发后休眠1s |
| | | } catch (InterruptedException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | News.info("四向穿梭车命令下发[id:{}] >>>>> {}", slave.getId(), JSON.toJSON(command)); |
| | | OutputQueue.SHUTTLE.offer(MessageFormat.format("【{0}】[id:{1}] >>>>> 命令下发: {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command))); |
| | | return true; |
| | | } else { |
| | | OutputQueue.SHUTTLE.offer(MessageFormat.format("【{0}】写入四向穿梭车plc数据失败 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort())); |
| | | News.error("写入四向穿梭车plc数据失败 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); |
| | | return false; |
| | | } |
| | | return array; |
| | | } |
| | | |
| | | /** |
| | | * 初始化四向穿梭车 |
| | | */ |
| | | private void initShuttle() { |
| | | this.connect(); |
| | | if (null == shuttleProtocol) { |
| | | shuttleProtocol = new ShuttleProtocol(); |
| | | } |
| | |
| | | Short liftArrival = liftProtocol.getPositionArrivalFeedback();//提升机位置反馈 |
| | | String liftSiteLocNo = Utils.liftArrivalToOutInStaLocNo(liftArrival); |
| | | LocMast locMast1 = locMastService.selectById(liftSiteLocNo); |
| | | ShuttleCommand moveCommand = getMoveCommand(liftProtocol.getBarcode(), Short.parseShort(locMast1.getQrCodeValue()), 1400, ShuttleRunDirection.BOTTOM.id, null, null, runSpeed); |
| | | ShuttleCommand moveCommand = getMoveCommand(liftProtocol.getBarcode(), Short.parseShort(locMast1.getQrCodeValue()), 1600, ShuttleRunDirection.BOTTOM.id, null, null, runSpeed); |
| | | commands.add(moveCommand); |
| | | |
| | | //起始位置修改为提升机口站点位置 |
| | |
| | | } |
| | | |
| | | //增加移动进提升机命令 |
| | | ShuttleCommand moveCommand = getMoveCommand(endStartCode, liftProtocol.getBarcode(), 1400, ShuttleRunDirection.TOP.id, null, null, runSpeed); |
| | | ShuttleCommand moveCommand = getMoveCommand(endStartCode, liftProtocol.getBarcode(), 1600, ShuttleRunDirection.TOP.id, null, null, runSpeed); |
| | | commands.add(moveCommand); |
| | | break; |
| | | default: |
| | |
| | | //保存数据到数据库做流水 |
| | | BasShuttleOptService shuttleOptService = SpringUtils.getBean(BasShuttleOptService.class); |
| | | if (shuttleOptService != null) { |
| | | short[] commandArr = getCommandArr(command);//获取命令报文 |
| | | BasShuttleOpt opt = new BasShuttleOpt( |
| | | assignCommand.getTaskNo().intValue(), |
| | | assignCommand.getShuttleNo().intValue(), |
| | |
| | | null, |
| | | null, |
| | | null, |
| | | JSON.toJSONString(command) |
| | | JSON.toJSONString(command), |
| | | JSON.toJSONString(commandArr) |
| | | ); |
| | | shuttleOptService.insert(opt); |
| | | } |