| | |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | |
| | | /** |
| | | * 堆垛机接口 |
| | |
| | | @RestController |
| | | @RequestMapping("/crn") |
| | | public class CrnController { |
| | | private static AtomicInteger integer = new AtomicInteger(); |
| | | |
| | | @Autowired |
| | | private SlaveProperties slaveProperties; |
| | | @Autowired |
| | |
| | | StringBuilder str = new StringBuilder(); |
| | | String s; |
| | | int i = 0; |
| | | while( (s = OutputQueue.CRN.poll()) != null && i <=10) { |
| | | while((s = OutputQueue.CRN.poll()) != null && i <=10) { |
| | | str.append("\n").append(s); |
| | | i++; |
| | | } |
| | | // str = new StringBuilder("\n" + new Date().toLocaleString() + "【2020-5-29 13:14:22】扫描plcA 目标站--273283723728327636432343234323422732837237283276364323432343234227328372372832763643234323432342"); |
| | | return R.ok().add(str.toString()); |
| | | } |
| | | |
| | |
| | | return crnControl(command)?R.ok():R.error(); |
| | | } |
| | | |
| | | @ManagerAuth(memo = "坐标移动") |
| | | @PostMapping("/operator/coorMove") |
| | | public R crnCoorMove(CrnOperatorParam param){ |
| | | CrnCommand command = new CrnCommand(); |
| | | command.setCrnNo(param.getCrnNo()); // 堆垛机编号 |
| | | command.setTaskNo((short) 0); // 工作号 |
| | | command.setAckFinish((short) 0); // 任务完成确认位 |
| | | command.setTaskMode(CrnTaskModeType.OFFSET_MOVE); // 任务模式 |
| | | command.setSourcePosX((short) 0); // 源库位排 |
| | | command.setSourcePosY(param.getSourceBay()); // 源库位列 |
| | | command.setSourcePosZ(param.getSourceLev()); // 源库位层 |
| | | command.setDestinationPosX((short) 0); // 目标库位排 |
| | | command.setDestinationPosY(param.getBay()); // 目标库位列 |
| | | command.setDestinationPosZ(param.getLev()); // 目标库位层 |
| | | return crnControl(command)?R.ok():R.error(); |
| | | } |
| | | |
| | | @ManagerAuth(memo = "回原点") |
| | | @PostMapping("/operator/bacOrigin") |
| | | public R crnBacOrigin(CrnOperatorParam param){ |
| | |
| | | command.setSourcePosZ((short) 0); // 源库位层 |
| | | command.setDestinationPosX((short) 0); // 目标库位排 |
| | | command.setDestinationPosY((short) 0); // 目标库位列 |
| | | command.setDestinationPosZ((short) 1); // 目标库位层 |
| | | command.setDestinationPosZ((short) 0); // 目标库位层 |
| | | return crnControl(command)?R.ok():R.error(); |
| | | } |
| | | |
| | |
| | | command.setDestinationPosX((short) 0); // 目标库位排 |
| | | command.setDestinationPosY((short) 34); // 目标库位列 |
| | | command.setDestinationPosZ((short) 5); // 目标库位层 |
| | | return crnControl(command)?R.ok():R.error(); |
| | | } |
| | | |
| | | @ManagerAuth(memo = "坐标移动") |
| | | @PostMapping("/operator/coorMove") |
| | | public R crnCoorMove(CrnOperatorParam param){ |
| | | CrnCommand command = new CrnCommand(); |
| | | command.setCrnNo(param.getCrnNo()); // 堆垛机编号 |
| | | command.setTaskNo((short) 0); // 工作号 |
| | | command.setAckFinish((short) 0); // 任务完成确认位 |
| | | command.setTaskMode(CrnTaskModeType.OFFSET_MOVE); // 任务模式 |
| | | command.setSourcePosX(param.getSourceRow()); // 源库位排 |
| | | command.setSourcePosY(param.getSourceBay()); // 源库位列 |
| | | command.setSourcePosZ(param.getSourceLev()); // 源库位层 |
| | | command.setDestinationPosX(param.getRow()); // 目标库位排 |
| | | command.setDestinationPosY(param.getBay()); // 目标库位列 |
| | | command.setDestinationPosZ(param.getLev()); // 目标库位层 |
| | | return crnControl(command)?R.ok():R.error(); |
| | | } |
| | | |
| | |
| | | return R.ok("清除命令成功"); |
| | | } |
| | | |
| | | @ManagerAuth(memo = "手动复位") |
| | | @PostMapping("/operator/handleReset") |
| | | public R handleReset(CrnOperatorParam param) throws Exception { |
| | | if (param.getCrnNo() == null) { |
| | | throw new CoolException("请选择堆垛机"); |
| | | } |
| | | // 获取堆垛机缓存 |
| | | for (CrnSlave crn : slaveProperties.getCrn()) { |
| | | // 获取堆垛机信息 |
| | | if (param.getCrnNo().equals(crn.getId())) { |
| | | CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crn.getId()); |
| | | if (crnThread == null) { |
| | | throw new CoolException("堆垛机不在线"); |
| | | } |
| | | CrnProtocol crnProtocol = crnThread.getCrnProtocol(); |
| | | if (crnProtocol == null) { |
| | | throw new CoolException("堆垛机不在线"); |
| | | } |
| | | // 只有出现指定异常才进行复位 |
| | | if (crnProtocol.getCrnError2().leftTakeNoneErr |
| | | || crnProtocol.getCrnError2().rightTakeNoneErr |
| | | || crnProtocol.getCrnError2().leftPutLoadErr |
| | | || crnProtocol.getCrnError2().rightPutLoadErr) { |
| | | CrnCommand command = new CrnCommand(); |
| | | command.setCrnNo(param.getCrnNo()); // 堆垛机编号 |
| | | command.setAckFinish((short) 1); // 任务完成确认位 |
| | | command.setTaskMode(CrnTaskModeType.NONE); // 任务模式 |
| | | // 延时发送 |
| | | Thread.sleep(3000L); |
| | | if (MessageQueue.offer(SlaveType.Crn, crn.getId(), new Task(2, command))) { |
| | | return R.ok(); |
| | | } else { |
| | | throw new CoolException("命令下发失败"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | return R.error(); |
| | | } |
| | | |
| | | private boolean crnControl(CrnCommand command){ |
| | | if (command.getCrnNo() == null) { |
| | | throw new CoolException("请选择堆垛机"); |