| | |
| | | |
| | | import java.text.MessageFormat; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.ArrayList; |
| | | import com.zy.core.utils.WmsOperateUtils; |
| | | import com.zy.asrs.entity.BasCrnpErrLog; |
| | | import com.zy.asrs.service.BasCrnpErrLogService; |
| | | |
| | |
| | | private ZyCrnConnectDriver zyCrnConnectDriver; |
| | | private CrnProtocol crnProtocol; |
| | | private int deviceLogCollectTime = 200; |
| | | private List<Integer> lastReportedIndices = new ArrayList<>(); |
| | | |
| | | public ZySiemensCrnThread(DeviceConfig deviceConfig, RedisUtil redisUtil) { |
| | | this.deviceConfig = deviceConfig; |
| | |
| | | if (step == 2) { |
| | | sendCommand((CrnCommand) task.getData()); |
| | | } |
| | | if (step == 3) { |
| | | sendCommand1((CrnCommand) task.getData()); |
| | | } |
| | | if (step == 4) { |
| | | sendCommand2((CrnCommand) task.getData()); |
| | | } |
| | | if (step == 5) { |
| | | sendCommand3((CrnCommand) task.getData()); |
| | | } |
| | | |
| | | |
| | | Thread.sleep(100); |
| | | } catch (Exception e) { |
| | |
| | | crnProtocol.setYDistance(crnStatus.getYDistance()); |
| | | crnProtocol.setXDuration(crnStatus.getXDuration()); |
| | | crnProtocol.setYDuration(crnStatus.getYDuration()); |
| | | crnProtocol.setWeight(crnStatus.getWeight()); |
| | | crnProtocol.setDb110Data(crnStatus.getDb110Data()); |
| | | |
| | | // 上报堆垛机DB110状态数据 |
| | | short[] db110Data = crnProtocol.getDb110Data(); |
| | | List<Integer> currentIndices = new ArrayList<>(); |
| | | if (db110Data != null) { |
| | | for (int i = 0; i < db110Data.length; i++) { |
| | | if (db110Data[i] == 1) { |
| | | currentIndices.add(i); |
| | | } |
| | | } |
| | | } |
| | | //!currentIndices.equals(lastReportedIndices) |
| | | boolean changed = true; |
| | | |
| | | if (changed) { |
| | | try { |
| | | WmsOperateUtils wmsOperateUtils = SpringUtils.getBean(WmsOperateUtils.class); |
| | | if (wmsOperateUtils != null) { |
| | | wmsOperateUtils.reportCrnDb110Status(crnProtocol.getCrnNo(), currentIndices); |
| | | lastReportedIndices = new ArrayList<>(currentIndices); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("Report Crn Db110 Status Fail", e); |
| | | } |
| | | } |
| | | |
| | | OutputQueue.CRN.offer(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功",DateUtils.convert(new Date()), deviceConfig.getDeviceNo())); |
| | | |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public synchronized CommandResponse sendCommand1(CrnCommand command) { |
| | | this.crnProtocol.setLastCommandTime(System.currentTimeMillis()); |
| | | CommandResponse response = null; |
| | | try { |
| | | response = zyCrnConnectDriver.sendCommand1(command); |
| | | return response; |
| | | } finally { |
| | | String sourceLocNo = Utils.getLocNo(command.getSourcePosX(), command.getSourcePosY(), command.getSourcePosZ()); |
| | | String targetLocNo = Utils.getLocNo(command.getDestinationPosX(), command.getDestinationPosY(), command.getDestinationPosZ()); |
| | | BasCrnpOptService bean = SpringUtils.getBean(BasCrnpOptService.class); |
| | | ZyCrnStatusEntity statusEntity = zyCrnConnectDriver.getStatus(); |
| | | BasCrnpOpt basCrnpOpt = new BasCrnpOpt( |
| | | command.getTaskNo().intValue(), |
| | | command.getCrnNo(), |
| | | new Date(), |
| | | String.valueOf(command.getTaskMode()), |
| | | sourceLocNo, |
| | | targetLocNo, |
| | | null, |
| | | null, |
| | | null, |
| | | JSON.toJSONString(command), |
| | | JSON.toJSONString(statusEntity), |
| | | 1, |
| | | JSON.toJSONString(response) |
| | | ); |
| | | if (bean != null) { |
| | | bean.insert(basCrnpOpt); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 管理站点的白灯情况 |
| | | * 1(亮,闪烁,上位下发任务) |
| | | * 默认0(暗) |
| | | * @param command |
| | | * @return |
| | | */ |
| | | |
| | | @Override |
| | | public synchronized CommandResponse sendCommand2(CrnCommand command) { |
| | | this.crnProtocol.setLastCommandTime(System.currentTimeMillis()); |
| | | CommandResponse response = null; |
| | | try { |
| | | response = zyCrnConnectDriver.sendCommand2(command); |
| | | return response; |
| | | } finally { |
| | | String sourceLocNo = Utils.getLocNo(command.getSourcePosX(), command.getSourcePosY(), command.getSourcePosZ()); |
| | | String targetLocNo = Utils.getLocNo(command.getDestinationPosX(), command.getDestinationPosY(), command.getDestinationPosZ()); |
| | | BasCrnpOptService bean = SpringUtils.getBean(BasCrnpOptService.class); |
| | | ZyCrnStatusEntity statusEntity = zyCrnConnectDriver.getStatus(); |
| | | BasCrnpOpt basCrnpOpt = new BasCrnpOpt( |
| | | command.getTaskNo().intValue(), |
| | | command.getCrnNo(), |
| | | new Date(), |
| | | String.valueOf(command.getTaskMode()), |
| | | sourceLocNo, |
| | | targetLocNo, |
| | | null, |
| | | null, |
| | | null, |
| | | JSON.toJSONString(command), |
| | | JSON.toJSONString(statusEntity), |
| | | 1, |
| | | JSON.toJSONString(response) |
| | | ); |
| | | if (bean != null) { |
| | | bean.insert(basCrnpOpt); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 管理站点的黄色按钮状态及颜色 |
| | | * 1:人工按按钮确认 |
| | | * 2:上位机接收完成,运行给 |
| | | * 0:任务结束上位机清除状态 |
| | | * @param command |
| | | * @return |
| | | */ |
| | | @Override |
| | | public synchronized CommandResponse sendCommand3(CrnCommand command) { |
| | | this.crnProtocol.setLastCommandTime(System.currentTimeMillis()); |
| | | CommandResponse response = null; |
| | | try { |
| | | response = zyCrnConnectDriver.sendCommand3(command); |
| | | return response; |
| | | } finally { |
| | | String sourceLocNo = Utils.getLocNo(command.getSourcePosX(), command.getSourcePosY(), command.getSourcePosZ()); |
| | | String targetLocNo = Utils.getLocNo(command.getDestinationPosX(), command.getDestinationPosY(), command.getDestinationPosZ()); |
| | | BasCrnpOptService bean = SpringUtils.getBean(BasCrnpOptService.class); |
| | | ZyCrnStatusEntity statusEntity = zyCrnConnectDriver.getStatus(); |
| | | BasCrnpOpt basCrnpOpt = new BasCrnpOpt( |
| | | command.getTaskNo().intValue(), |
| | | command.getCrnNo(), |
| | | new Date(), |
| | | String.valueOf(command.getTaskMode()), |
| | | sourceLocNo, |
| | | targetLocNo, |
| | | null, |
| | | null, |
| | | null, |
| | | JSON.toJSONString(command), |
| | | JSON.toJSONString(statusEntity), |
| | | 1, |
| | | JSON.toJSONString(response) |
| | | ); |
| | | if (bean != null) { |
| | | bean.insert(basCrnpOpt); |
| | | } |
| | | } |
| | | } |
| | | } |