| | |
| | | import com.zy.asrs.wcs.core.model.enums.LiftCommandModeType; |
| | | import com.zy.asrs.wcs.core.model.enums.MotionCtgType; |
| | | import com.zy.asrs.wcs.core.service.BasLiftService; |
| | | import com.zy.asrs.wcs.core.utils.LiftDispatcher; |
| | | import com.zy.asrs.wcs.core.utils.RedisUtil; |
| | | import com.zy.asrs.wcs.core.utils.Utils; |
| | | import com.zy.asrs.wcs.rcs.News; |
| | | import com.zy.asrs.wcs.rcs.cache.OutputQueue; |
| | | import com.zy.asrs.wcs.rcs.entity.Device; |
| | | import com.zy.asrs.wcs.rcs.entity.DeviceDataLog; |
| | | import com.zy.asrs.wcs.rcs.model.CommandResponse; |
| | | import com.zy.asrs.wcs.rcs.model.enums.LiftProtocolStatusType; |
| | | import com.zy.asrs.wcs.rcs.model.protocol.LiftProtocol; |
| | | import com.zy.asrs.wcs.rcs.service.DeviceDataLogService; |
| | |
| | | public NyLiftThread(Device device, RedisUtil redisUtil) { |
| | | this.device = device; |
| | | this.redisUtil = redisUtil; |
| | | |
| | | //初始化站点 |
| | | BasLiftService basLiftService = SpringUtils.getBean(BasLiftService.class); |
| | | BasLift basLift = basLiftService.getOne(new LambdaQueryWrapper<BasLift>() |
| | | .eq(BasLift::getDeviceId, device.getId())); |
| | | List<BasLiftStaDto> staList = JSON.parseArray(basLift.getSta(), BasLiftStaDto.class); |
| | | this.staList = staList; |
| | | for (BasLiftStaDto sta : staList) { |
| | | LiftStaProtocol liftStaProtocol = new LiftStaProtocol(); |
| | | liftStaProtocol.setStaNo(sta.getStaNo());//站点号 |
| | | liftStaProtocol.setLev(sta.getLev());//站点楼层 |
| | | String locNo = Utils.getLocNo(sta.getRow(), sta.getBay(), sta.getLev()); |
| | | liftStaProtocol.setLocNo(locNo);//站点库位号 |
| | | liftStaProtocol.setLiftNo(basLift.getLiftNo());//提升机号 |
| | | liftStaProtocols.add(liftStaProtocol); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | private void readStatus() { |
| | | try { |
| | | if (liftStaProtocols.isEmpty()) { |
| | | //初始化站点 |
| | | BasLiftService basLiftService = SpringUtils.getBean(BasLiftService.class); |
| | | BasLift basLift = basLiftService.getOne(new LambdaQueryWrapper<BasLift>() |
| | | .eq(BasLift::getDeviceId, device.getId())); |
| | | List<BasLiftStaDto> staList = JSON.parseArray(basLift.getSta(), BasLiftStaDto.class); |
| | | this.staList = staList; |
| | | for (BasLiftStaDto sta : staList) { |
| | | LiftStaProtocol liftStaProtocol = new LiftStaProtocol(); |
| | | liftStaProtocol.setStaNo(sta.getStaNo());//站点号 |
| | | liftStaProtocol.setLev(sta.getLev());//站点楼层 |
| | | String locNo = Utils.getLocNo(sta.getRow(), sta.getBay(), sta.getLev()); |
| | | liftStaProtocol.setLocNo(locNo);//站点库位号 |
| | | liftStaProtocol.setLiftNo(basLift.getLiftNo());//提升机号 |
| | | liftStaProtocols.add(liftStaProtocol); |
| | | } |
| | | } |
| | | |
| | | //获取提升机数据 |
| | | OperateResultExOne<byte[]> result1 = siemensS7Net.Read("DB82.4.0", (short) 10); |
| | | if (result1.IsSuccess) { |
| | |
| | | //有小车 |
| | | liftProtocol.setHasCar(status2[6]); |
| | | //设备故障 |
| | | liftProtocol.setErrorCode(String.valueOf(status2[7])); |
| | | liftProtocol.setErrorCode(status2[7]?"1":"0"); |
| | | //目的地址 |
| | | liftProtocol.setDistAddress(siemensS7Net.getByteTransform().TransInt16(result1.Content, 4)); |
| | | //已完成任务号 |
| | |
| | | //任务号 |
| | | liftExtend.setLiftTaskNo(String.valueOf(siemensS7Net.getByteTransform().TransInt16(result1.Content, 2))); |
| | | liftProtocol.setExtend(liftExtend); |
| | | |
| | | boolean ready = true; |
| | | if (!liftProtocol.getModel() || liftProtocol.getRun()) { |
| | | ready = false; |
| | | } |
| | | liftProtocol.setReady(ready);//就绪状态 |
| | | |
| | | |
| | | }else { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public boolean move(LiftCommand command) { |
| | | public CommandResponse move(LiftCommand command) { |
| | | return write(command); |
| | | } |
| | | |
| | | @Override |
| | | public boolean palletInOut(LiftCommand command) { |
| | | public CommandResponse palletInOut(LiftCommand command) { |
| | | return write(command); |
| | | } |
| | | |
| | | private boolean write(LiftCommand command) { |
| | | private CommandResponse write(LiftCommand command) { |
| | | CommandResponse response = new CommandResponse(false); |
| | | if (null == command) { |
| | | News.error("提升机写入命令为空"); |
| | | return false; |
| | | response.setMessage("提升机写入命令为空"); |
| | | return response; |
| | | } |
| | | |
| | | List<Short> shorts = JSON.parseArray(command.getBody(), Short.class); |
| | |
| | | array[i] = shorts.get(i); |
| | | } |
| | | |
| | | LiftDispatcher liftDispatcher = SpringUtils.getBean(LiftDispatcher.class); |
| | | |
| | | Integer origin = command.getOriginLev(); |
| | | Integer target = command.getTargetLev(); |
| | | if (command.getMode() == 2) { |
| | | origin = liftDispatcher.getLiftLevOffset(this.device.getId().intValue(), liftProtocol.getLev()); |
| | | target = liftDispatcher.getLiftLevOffset(this.device.getId().intValue(), command.getTargetLev()); |
| | | } |
| | | |
| | | array[1] = origin.shortValue(); |
| | | array[2] = target.shortValue(); |
| | | |
| | | OperateResult result = siemensS7Net.Write("DB83.0", array); |
| | | if (result != null && result.IsSuccess) { |
| | | liftProtocol.setSendTime(System.currentTimeMillis());//指令下发时间 |
| | | News.info("提升机命令下发[id:{}] >>>>> {}", device.getId(), JSON.toJSON(command)); |
| | | OutputQueue.LIFT.offer(MessageFormat.format("【{0}】[id:{1}] >>>>> 命令下发: {2}", DateUtils.convert(new Date()), device.getId(), JSON.toJSON(command))); |
| | | return true; |
| | | response.setMessage(MessageFormat.format("【{0}】[id:{1}] >>>>> 命令下发: {2}", DateUtils.convert(new Date()), device.getId(), JSON.toJSON(command))); |
| | | response.setResult(true); |
| | | return response; |
| | | } else { |
| | | OutputQueue.LIFT.offer(MessageFormat.format("【{0}】写入提升机plc数据失败 ===>> [id:{1}] [ip:{2}] [port:{3}],次数:{}", DateUtils.convert(new Date()), device.getId(), device.getIp(), device.getPort())); |
| | | News.error("写入提升机plc数据失败 ===>> [id:{}] [ip:{}] [port:{}]", device.getId(), device.getIp(), device.getPort()); |
| | | return false; |
| | | response.setMessage(MessageFormat.format("【{0}】写入提升机plc数据失败 ===>> [id:{1}] [ip:{2}] [port:{3}],次数:{}", DateUtils.convert(new Date()), device.getId(), device.getIp(), device.getPort())); |
| | | return response; |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public boolean lock(LiftCommand command) { |
| | | return true; |
| | | public CommandResponse lock(LiftCommand command) { |
| | | return new CommandResponse(true); |
| | | } |
| | | |
| | | @Override |
| | | public boolean unlock(LiftCommand command) { |
| | | return true; |
| | | public CommandResponse unlock(LiftCommand command) { |
| | | return new CommandResponse(true); |
| | | } |
| | | |
| | | @Override |
| | | public boolean reset(LiftCommand command) { |
| | | return false; |
| | | public CommandResponse reset(LiftCommand command) { |
| | | return new CommandResponse(false); |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | @Override |
| | | public int generateDeviceTaskNo(int taskNo, MotionCtgType motionCtgType) { |
| | | int deviceTaskNo = taskNo; |
| | | try { |
| | | deviceTaskNo = Utils.getTaskNo("LIFT_TASK_NO"); |
| | | } catch (Exception e) { |
| | | return taskNo; |
| | | } |
| | | return deviceTaskNo; |
| | | } |
| | | |
| | | @Override |
| | | public List<LiftCommand> getMoveCommand(Integer taskNo, Integer sourceLev, Integer targetLev, LiftCommandModeType mode) { |
| | | /** |
| | | * 任务类型 |
| | | * 1=移托盘;升降机将源站台托盘移到目标站台 |
| | | * 2=移小车,升降机移到目标层,等待 |
| | | 1=移托盘;升降机将源站台托盘移到目标站台 |
| | | 2=换层,升降机移到目标层,等待 |
| | | 3=入库托盘,升降机将源站台托盘移到目标层数; |
| | | 4=出库托盘,升降机将源站台托盘移到目标站台 |
| | | */ |
| | | short taskMode = 2; |
| | | if (mode.equals(LiftCommandModeType.PALLET_INOUT)) { |
| | | taskMode = 1; |
| | | if (mode.equals(LiftCommandModeType.PALLET_IN)) { |
| | | taskMode = 3; |
| | | } else if (mode.equals(LiftCommandModeType.PALLET_OUT)) { |
| | | taskMode = 4; |
| | | } |
| | | |
| | | // 开始任务 |
| | |
| | | LiftCommand command = new LiftCommand(); |
| | | command.setLiftNo(Integer.valueOf(this.device.getDeviceNo())); |
| | | command.setBody(JSON.toJSONString(array)); |
| | | command.setMode(LiftCommandModeType.MOVE.id); |
| | | command.setMode(mode.id); |
| | | command.setOriginLev(sourceLev); |
| | | command.setTargetLev(targetLev); |
| | | |