| | |
| | | import com.zy.asrs.entity.*; |
| | | import com.zy.asrs.service.BasDualCrnpOptService; |
| | | import com.zy.asrs.service.BasDualCrnpService; |
| | | import com.zy.asrs.service.WrkMastService; |
| | | import com.zy.asrs.utils.Utils; |
| | | import com.zy.common.utils.RedisUtil; |
| | | import com.zy.core.News; |
| | |
| | | private RedisUtil redisUtil; |
| | | private ZyDualCrnConnectDriver zyDualCrnConnectDriver; |
| | | private DualCrnProtocol crnProtocol; |
| | | private int deviceLogCollectTime = 200; |
| | | private volatile int deviceLogCollectTime = 200; |
| | | |
| | | public ZySiemensDualCrnThread(DeviceConfig deviceConfig, RedisUtil redisUtil) { |
| | | this.deviceConfig = deviceConfig; |
| | |
| | | try { |
| | | deviceLogCollectTime = Utils.getDeviceLogCollectTime(); |
| | | readStatus(); |
| | | Thread.sleep(50); |
| | | Thread.sleep(100); |
| | | } catch (Exception e) { |
| | | log.error("DualCrnThread Fail", e); |
| | | } |
| | |
| | | |
| | | if (step == 2) { |
| | | List<SendDualCrnCommandParam> commandList = (List<SendDualCrnCommandParam>) task.getData(); |
| | | redisUtil.set(RedisKeyType.DUAL_CRN_COMMAND_.key + crnProtocol.getCrnNo(), JSON.toJSONString(commandList, SerializerFeature.DisableCircularReferenceDetect), 60 * 60 * 24); |
| | | for (SendDualCrnCommandParam sendDualCrnCommandParam : commandList) { |
| | | DualCrnCommand dualCrnCommand = sendDualCrnCommandParam.getCommands().get(0); |
| | | redisUtil.set(RedisKeyType.DUAL_CRN_COMMAND_IDX.key + dualCrnCommand.getTaskNo(), 0, 60 * 60 * 24); |
| | | redisUtil.set(RedisKeyType.DUAL_CRN_COMMAND_.key + dualCrnCommand.getTaskNo(), JSON.toJSONString(sendDualCrnCommandParam, SerializerFeature.DisableCircularReferenceDetect), 60 * 60 * 24); |
| | | if (sendDualCrnCommandParam.getStation() == 1) { |
| | | redisUtil.set(RedisKeyType.DUAL_CRN_STATION1_FLAG.key + crnProtocol.getCrnNo(), dualCrnCommand.getTaskNo(), 60 * 60 * 24); |
| | | } else { |
| | | redisUtil.set(RedisKeyType.DUAL_CRN_STATION2_FLAG.key + crnProtocol.getCrnNo(), dualCrnCommand.getTaskNo(), 60 * 60 * 24); |
| | | } |
| | | } |
| | | } else if (step == 3) { |
| | | sendCommand((DualCrnCommand) task.getData()); |
| | | } |
| | |
| | | Thread commandThread = new Thread(() -> { |
| | | while (true) { |
| | | try { |
| | | if(crnProtocol.getMode() != DualCrnModeType.AUTO.id) { |
| | | continue; |
| | | } |
| | | |
| | | if(crnProtocol.getAlarm() != 0) { |
| | | continue; |
| | | } |
| | | |
| | | // if (crnProtocol.getLoaded() == 1 && crnProtocol.getLoadedTwo() == 1) { |
| | | // Object wait = redisUtil.get(RedisKeyType.DUAL_CRN_PICK_WAIT_NEXT_TASK.key + crnProtocol.getCrnNo()); |
| | | // if (wait != null) { |
| | | // redisUtil.del(RedisKeyType.DUAL_CRN_PICK_WAIT_NEXT_TASK.key + crnProtocol.getCrnNo()); |
| | | // } |
| | | // } |
| | | |
| | | Object commandListObj = redisUtil.get(RedisKeyType.DUAL_CRN_COMMAND_.key + crnProtocol.getCrnNo()); |
| | | if (commandListObj == null) { |
| | | continue; |
| | | } |
| | | List<SendDualCrnCommandParam> commandList = JSON.parseArray(commandListObj.toString(), SendDualCrnCommandParam.class); |
| | | |
| | | List<SendDualCrnCommandParam> newCommandList = new ArrayList<>(); |
| | | for (SendDualCrnCommandParam commandParam : commandList) { |
| | | SendDualCrnCommandParam processed = processStation(commandParam); |
| | | if(processed != null) { |
| | | newCommandList.add(processed); |
| | | } |
| | | } |
| | | |
| | | redisUtil.set(RedisKeyType.DUAL_CRN_COMMAND_.key + crnProtocol.getCrnNo(), JSON.toJSONString(newCommandList, SerializerFeature.DisableCircularReferenceDetect), 60 * 60 * 24); |
| | | Thread.sleep(100); |
| | | |
| | | if (crnProtocol.getMode() != DualCrnModeType.AUTO.id) { |
| | | continue; |
| | | } |
| | | |
| | | if (crnProtocol.getAlarm() != 0) { |
| | | continue; |
| | | } |
| | | |
| | | if (!((crnProtocol.getStatusType().equals(DualCrnStatusType.IDLE) || crnProtocol.getStatusType().equals(DualCrnStatusType.FETCH_COMPLETE)) |
| | | && (crnProtocol.getStatusTypeTwo().equals(DualCrnStatusType.IDLE) || crnProtocol.getStatusTypeTwo().equals(DualCrnStatusType.FETCH_COMPLETE))) |
| | | ) { |
| | | continue; |
| | | } |
| | | |
| | | List<SendDualCrnCommandParam> commandList = getDualCrnCommandList(); |
| | | for (SendDualCrnCommandParam commandParam : commandList) { |
| | | processStation(commandParam); |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | log.error("DualCrnCommand Fail", e); |
| | | } |
| | |
| | | commandThread.start(); |
| | | } |
| | | |
| | | private SendDualCrnCommandParam processStation(SendDualCrnCommandParam commandParam) { |
| | | private void processStation(SendDualCrnCommandParam commandParam) { |
| | | Integer station = commandParam.getStation(); |
| | | Integer idx = commandParam.getCommandIdx(); |
| | | List<DualCrnCommand> commandList = commandParam.getCommands(); |
| | | DualCrnCommand firstCommand = commandList.get(0); |
| | | Object idxObj = redisUtil.get(RedisKeyType.DUAL_CRN_COMMAND_IDX.key + firstCommand.getTaskNo()); |
| | | if (idxObj == null) { |
| | | return; |
| | | } |
| | | Integer idx = (Integer) idxObj; |
| | | if (idx >= commandList.size()) { |
| | | return commandParam; |
| | | return; |
| | | } |
| | | DualCrnCommand dualCommand = commandList.get(idx); |
| | | |
| | | boolean send = false; |
| | | //TODO 判断站点1,2任务类型是否一致 |
| | | if (station == 1) { |
| | | if (crnProtocol.getStatus().equals(DualCrnStatusType.FETCH_COMPLETE.id) |
| | | || crnProtocol.getStatus().equals(DualCrnStatusType.IDLE.id) |
| | | ) { |
| | | send = true; |
| | | log.info("工位2任务==========>{}, 任务模式---->{}", crnProtocol.getTaskNoTwo(), crnProtocol.getMode()); |
| | | log.info("工位1任务==========>{}, 任务模式---->{}", crnProtocol.getTaskNo(), crnProtocol.getMode()); |
| | | Integer taskNo = crnProtocol.getTaskNoTwo(); |
| | | if (crnProtocol.getTaskSend() == 0) { |
| | | //两个工位只允许放相同类型任务 |
| | | // if (taskNo != null && taskNo > 0) { |
| | | // WrkMastService mastService = SpringUtils.getBean(WrkMastService.class); |
| | | // WrkMast wrkMast = mastService.selectOne(new EntityWrapper<WrkMast>().eq("wrk_no", taskNo)); |
| | | // WrkMast wrkMast1 = mastService.selectOne(new EntityWrapper<WrkMast>().eq("wrk_no", dualCommand.getTaskNo())); |
| | | // if (!Objects.isNull(wrkMast) && !Objects.isNull(wrkMast1)) { |
| | | // if (wrkMast1.getIoType() != wrkMast.getIoType()) { |
| | | //// return; |
| | | // } |
| | | // } |
| | | // } |
| | | // && sendComm(taskNo, dualCommand.getTaskNo()) |
| | | if (dualCommand.getTaskMode().intValue() == DualCrnTaskModeType.PICK.id) { |
| | | if (crnProtocol.getStatus().equals(DualCrnStatusType.IDLE.id)) { |
| | | send = true; |
| | | } |
| | | } else if (dualCommand.getTaskMode().intValue() == DualCrnTaskModeType.PUT.id) { |
| | | if (crnProtocol.getStatus().equals(DualCrnStatusType.FETCH_COMPLETE.id)) { |
| | | send = true; |
| | | } |
| | | } |
| | | } |
| | | }else { |
| | | if (crnProtocol.getStatusTwo().equals(DualCrnStatusType.FETCH_COMPLETE.id) |
| | | || crnProtocol.getStatusTwo().equals(DualCrnStatusType.IDLE.id) |
| | | ) { |
| | | send = true; |
| | | } else { |
| | | log.info("工位1任务==========>{}, 任务模式---->{}", crnProtocol.getTaskNo(), crnProtocol.getMode()); |
| | | log.info("工位2任务==========>{}, 任务模式---->{}", crnProtocol.getTaskNoTwo(), crnProtocol.getMode()); |
| | | Integer taskNo = crnProtocol.getTaskNo(); |
| | | // && sendComm(taskNo, dualCommand.getTaskNo()) |
| | | if (crnProtocol.getTaskSendTwo() == 0) { |
| | | if (dualCommand.getTaskMode().intValue() == DualCrnTaskModeType.PICK.id) { |
| | | if (crnProtocol.getStatusTwo().equals(DualCrnStatusType.IDLE.id)) { |
| | | send = true; |
| | | } |
| | | } else if (dualCommand.getTaskMode().intValue() == DualCrnTaskModeType.PUT.id) { |
| | | if (crnProtocol.getStatusTwo().equals(DualCrnStatusType.FETCH_COMPLETE.id)) { |
| | | send = true; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (idx == 0) { |
| | | if(send) { |
| | | if (send) { |
| | | idx++; |
| | | commandParam.setCommandIdx(idx); |
| | | redisUtil.set(RedisKeyType.DUAL_CRN_COMMAND_IDX.key + firstCommand.getTaskNo(), idx, 60 * 60 * 24); |
| | | sendCommand(dualCommand); |
| | | redisUtil.set(RedisKeyType.DUAL_CRN_PICK_WAIT_NEXT_TASK.key + crnProtocol.getCrnNo(), "lock", 5); |
| | | redisUtil.set(RedisKeyType.DUAL_CRN_PICK_WAIT_NEXT_TASK.key + crnProtocol.getCrnNo(), "lock", 3); |
| | | } |
| | | return commandParam; |
| | | }else { |
| | | return; |
| | | } else { |
| | | if (dualCommand.getTaskMode() == DualCrnTaskModeType.PUT.id.shortValue()) { |
| | | //等待下一个任务 |
| | | Object wait = redisUtil.get(RedisKeyType.DUAL_CRN_PICK_WAIT_NEXT_TASK.key + crnProtocol.getCrnNo()); |
| | | if (wait != null) { |
| | | return commandParam; |
| | | return; |
| | | } |
| | | |
| | | Integer taskNo = dualCommand.getTaskNo(); |
| | |
| | | StationObjModel stationObjModel = JSON.parseObject(outTaskStationInfoObj.toString(), StationObjModel.class); |
| | | StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, stationObjModel.getDeviceNo()); |
| | | if (stationThread == null) { |
| | | return commandParam; |
| | | return; |
| | | } |
| | | |
| | | Map<Integer, StationProtocol> statusMap = stationThread.getStatusMap(); |
| | | StationProtocol stationProtocol = statusMap.get(stationObjModel.getStationId()); |
| | | if (stationProtocol == null) { |
| | | return commandParam; |
| | | return; |
| | | } |
| | | |
| | | if (!stationProtocol.isAutoing()) { |
| | | return commandParam; |
| | | return; |
| | | } |
| | | |
| | | if (stationProtocol.isLoading()) { |
| | | return commandParam; |
| | | return; |
| | | } |
| | | |
| | | if (stationProtocol.getTaskNo() > 0) { |
| | | return commandParam; |
| | | return; |
| | | } |
| | | } |
| | | } |
| | | |
| | | if(send) { |
| | | if (send) { |
| | | idx++; |
| | | commandParam.setCommandIdx(idx); |
| | | redisUtil.set(RedisKeyType.DUAL_CRN_COMMAND_IDX.key + firstCommand.getTaskNo(), idx, 60 * 60 * 24); |
| | | sendCommand(dualCommand); |
| | | } |
| | | return commandParam; |
| | | return; |
| | | } |
| | | } |
| | | |
| | | public boolean sendComm(Integer taskNo, Integer current) { |
| | | //两个工位只允许放相同类型任务 |
| | | if (taskNo != null && taskNo > 0) { |
| | | WrkMastService mastService = SpringUtils.getBean(WrkMastService.class); |
| | | WrkMast wrkMast = mastService.selectOne(new EntityWrapper<WrkMast>().eq("wrk_no", taskNo)); |
| | | WrkMast wrkMast1 = mastService.selectOne(new EntityWrapper<WrkMast>().eq("wrk_no", current)); |
| | | if (!Objects.isNull(wrkMast) && !Objects.isNull(wrkMast1)) { |
| | | if (wrkMast1.getIoType() != wrkMast.getIoType()) { |
| | | return false; |
| | | } |
| | | } |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | |
| | | |
| | | //工位1 |
| | | crnProtocol.setTaskNo(0); |
| | | crnProtocol.setDeviceTaskNo(0); |
| | | crnProtocol.setStatus(-1); |
| | | crnProtocol.setBay(0); |
| | | crnProtocol.setLevel(0); |
| | |
| | | |
| | | //工位2 |
| | | crnProtocol.setTaskNoTwo(0); |
| | | crnProtocol.setDeviceTaskNoTwo(0); |
| | | crnProtocol.setStatusTwo(-1); |
| | | crnProtocol.setBayTwo(0); |
| | | crnProtocol.setLevelTwo(0); |
| | |
| | | BasDualCrnpService basDualCrnpService = null; |
| | | try { |
| | | basDualCrnpService = SpringUtils.getBean(BasDualCrnpService.class); |
| | | }catch (Exception e){ |
| | | } catch (Exception e) { |
| | | |
| | | } |
| | | if (basDualCrnpService != null) { |
| | | BasDualCrnp basDualCrnp = basDualCrnpService.selectOne(new EntityWrapper<BasDualCrnp>().eq("crn_no", deviceConfig.getDeviceNo())); |
| | | if(basDualCrnp == null) { |
| | | if (basDualCrnp == null) { |
| | | basDualCrnp = new BasDualCrnp(); |
| | | basDualCrnp.setCrnNo(deviceConfig.getDeviceNo()); |
| | | basDualCrnp.setStatus(1); |
| | |
| | | /** |
| | | * 读取状态 |
| | | */ |
| | | private void readStatus(){ |
| | | private void readStatus() { |
| | | ZyDualCrnStatusEntity crnStatus = zyDualCrnConnectDriver.getStatus(); |
| | | if (crnStatus == null) { |
| | | OutputQueue.DUAL_CRN.offer(MessageFormat.format("【{0}】读取双工位堆垛机plc状态信息失败 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), deviceConfig.getDeviceNo(), deviceConfig.getIp(), deviceConfig.getPort())); |
| | |
| | | crnProtocol.setMode(crnStatus.getMode()); |
| | | |
| | | //工位1 |
| | | crnProtocol.setTaskNo(crnStatus.getTaskNo()); |
| | | crnProtocol.setDeviceTaskNo(crnStatus.getTaskNo()); |
| | | crnProtocol.setStatus(crnStatus.getStatus()); |
| | | crnProtocol.setForkPos(crnStatus.getForkPos()); |
| | | crnProtocol.setLoaded(crnStatus.getLoaded()); |
| | | crnProtocol.setTaskReceive(crnStatus.getTaskReceive()); |
| | | crnProtocol.setTaskSend(crnStatus.getTaskSend()); |
| | | |
| | | //工位2 |
| | | crnProtocol.setTaskNoTwo(crnStatus.getTaskNoTwo()); |
| | | crnProtocol.setDeviceTaskNoTwo(crnStatus.getTaskNoTwo()); |
| | | crnProtocol.setStatusTwo(crnStatus.getStatusTwo()); |
| | | crnProtocol.setForkPosTwo(crnStatus.getForkPosTwo()); |
| | | crnProtocol.setLoadedTwo(crnStatus.getLoadedTwo()); |
| | | crnProtocol.setTaskReceiveTwo(crnStatus.getTaskReceiveTwo()); |
| | | crnProtocol.setTaskSendTwo(crnStatus.getTaskSendTwo()); |
| | | |
| | | crnProtocol.setBay(crnStatus.getBay()); |
| | | crnProtocol.setLevel(crnStatus.getLevel()); |
| | |
| | | crnProtocol.setGoodsType(crnStatus.getGoodsType()); |
| | | crnProtocol.setBarcode(crnStatus.getBarcode()); |
| | | |
| | | OutputQueue.DUAL_CRN.offer(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功",DateUtils.convert(new Date()), deviceConfig.getDeviceNo())); |
| | | OutputQueue.DUAL_CRN.offer(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功", DateUtils.convert(new Date()), deviceConfig.getDeviceNo())); |
| | | |
| | | if (crnProtocol.getAlarm() > 0) { |
| | | crnProtocol.setLastCommandTime(-1L); |
| | |
| | | //更新采集时间 |
| | | crnProtocol.setDeviceDataLog(System.currentTimeMillis()); |
| | | } |
| | | |
| | | |
| | | try { |
| | | BasDualCrnpErrLogService errLogService = SpringUtils.getBean(BasDualCrnpErrLogService.class); |
| | | if (errLogService != null) { |
| | |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception ignore) {} |
| | | } catch (Exception ignore) { |
| | | } |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | @Override |
| | | public DualCrnCommand getResetCommand(Integer crnNo, Integer station) { |
| | | public DualCrnCommand getResetCommand(Integer taskNo, Integer crnNo, Integer station) { |
| | | DualCrnCommand crnCommand = new DualCrnCommand(); |
| | | crnCommand.setCrnNo(crnNo); // 堆垛机编号 |
| | | crnCommand.setTaskNo(0); // 工作号 |
| | | crnCommand.setTaskNo(taskNo); // 工作号 |
| | | crnCommand.setTaskMode(DualCrnTaskModeType.CONFIRM.id); // 任务模式: 确认 |
| | | crnCommand.setSourcePosX(0); // 源库位排 |
| | | crnCommand.setSourcePosY(0); // 源库位列 |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | public List<SendDualCrnCommandParam> getDualCrnCommandList() { |
| | | List<SendDualCrnCommandParam> commandList = new ArrayList<>(); |
| | | SendDualCrnCommandParam command1 = getDualCrnCommandList(1); |
| | | SendDualCrnCommandParam command2 = getDualCrnCommandList(2); |
| | | if (command1 != null) { |
| | | commandList.add(command1); |
| | | } |
| | | |
| | | if (command2 != null) { |
| | | commandList.add(command2); |
| | | } |
| | | |
| | | return commandList; |
| | | } |
| | | |
| | | public SendDualCrnCommandParam getDualCrnCommandList(int station) { |
| | | SendDualCrnCommandParam sendDualCrnCommandParam = null; |
| | | String key = null; |
| | | if (station == 1 && crnProtocol.getTaskNo() > 0) { |
| | | key = RedisKeyType.DUAL_CRN_COMMAND_.key + crnProtocol.getTaskNo(); |
| | | } else if (station == 2 && crnProtocol.getTaskNoTwo() > 0) { |
| | | key = RedisKeyType.DUAL_CRN_COMMAND_.key + crnProtocol.getTaskNoTwo(); |
| | | } |
| | | |
| | | if (key == null) { |
| | | return null; |
| | | } |
| | | Object commandObj = redisUtil.get(key); |
| | | |
| | | if (commandObj == null) { |
| | | return null; |
| | | } |
| | | |
| | | sendDualCrnCommandParam = JSON.parseObject(commandObj.toString(), SendDualCrnCommandParam.class); |
| | | if (sendDualCrnCommandParam == null) { |
| | | return null; |
| | | } |
| | | |
| | | if (station == 1) { |
| | | if (crnProtocol.getTaskNoTwo() > 0) { |
| | | Object object = redisUtil.get(RedisKeyType.DUAL_CRN_COMMAND_.key + crnProtocol.getTaskNoTwo()); |
| | | if (object != null) { |
| | | SendDualCrnCommandParam jsonObject = JSON.parseObject(object.toString(), SendDualCrnCommandParam.class); |
| | | ; |
| | | if (!jsonObject.getCommands().get(0).getTaskMode().equals(sendDualCrnCommandParam.getCommands().get(0).getTaskMode())) { |
| | | return null; |
| | | } |
| | | } |
| | | } |
| | | } else { |
| | | if (crnProtocol.getTaskNo() > 0) { |
| | | WrkMastService mastService = SpringUtils.getBean(WrkMastService.class); |
| | | WrkMast wrkMast = mastService.selectOne(new EntityWrapper<WrkMast>().eq("wrk_no", crnProtocol.getTaskNo())); |
| | | WrkMast wrkMast1 = mastService.selectOne(new EntityWrapper<WrkMast>().eq("wrk_no", crnProtocol.getTaskNoTwo())); |
| | | if (!Objects.isNull(wrkMast) && !Objects.isNull(wrkMast1)) { |
| | | if (!wrkMast1.getIoType().equals(wrkMast.getIoType())) { |
| | | return null; |
| | | } |
| | | } |
| | | // Object object = redisUtil.get(RedisKeyType.DUAL_CRN_COMMAND_.key + crnProtocol.getTaskNo()); |
| | | // if (object != null) { |
| | | // SendDualCrnCommandParam jsonObject = JSON.parseObject(object.toString(), SendDualCrnCommandParam.class); |
| | | // ; |
| | | // if (!jsonObject.getCommands().get(0).getTaskMode().equals(sendDualCrnCommandParam.getCommands().get(0).getTaskMode())) { |
| | | // return null; |
| | | // } |
| | | // } |
| | | } |
| | | } |
| | | |
| | | return sendDualCrnCommandParam; |
| | | } |
| | | } |