| | |
| | | // deviceErrorService.addDeviceError("crn", slave.getId(), "堆垛机plc连接失败"); |
| | | initCrnProtocol(); |
| | | } |
| | | siemensNet.ConnectClose(); |
| | | // siemensNet.ConnectClose(); |
| | | return result; |
| | | } |
| | | |
| | |
| | | taskOverToWms.setTaskNo(taskWrk.getTaskNo()); //任务号 |
| | | taskOverToWms.setTaskType(tasktype); // 任务类型 |
| | | taskOverToWms.setContainerCode(taskWrk.getBarcode()); // 容器编码 |
| | | if (taskWrk.getIoType() ==1 || taskWrk.getIoType() == 3){ |
| | | if (taskWrk.getIoType() ==1){ |
| | | taskOverToWms.setEquipmentCode(String.valueOf(taskWrk.getCrnNo())); //设备编码 |
| | | taskOverToWms.setTargetLocationCode(taskWrk.getOriginTargetPoint()); //目标库位 |
| | | }else if (taskWrk.getIoType() ==2){ |
| | |
| | | map1.put(405,"G-1101"); |
| | | taskOverToWms.setEquipmentCode(map1.get(taskWrk.getTargetPoint())); //设备编码 |
| | | taskOverToWms.setSourceLocationCode(taskWrk.getOriginStartPoint()); //源库位 |
| | | } else if (taskWrk.getIoType() == 3) { |
| | | taskOverToWms.setEquipmentCode(String.valueOf(taskWrk.getCrnNo())); //设备编码 |
| | | taskOverToWms.setSourceLocationCode(taskWrk.getOriginStartPoint()); |
| | | taskOverToWms.setTargetLocationCode(taskWrk.getOriginTargetPoint()); //目标库位 |
| | | } |
| | | taskOverToWms.setTaskStatus("location_done"); //任务状态 |
| | | String response = null; |
| | |
| | | log.error("堆垛机写入命令为空"); |
| | | return false; |
| | | } |
| | | //转换前克隆一份 |
| | | CrnCommand crnCommand = new CrnCommand(); |
| | | crnCommand.setCrnNo(command.getCrnNo()); |
| | | crnCommand.setAckFinish(command.getAckFinish()); |
| | | crnCommand.setTaskNo(command.getTaskNo()); |
| | | crnCommand.setTaskMode(command.getTaskMode()); |
| | | crnCommand.setSourcePosX(command.getSourcePosX()); |
| | | crnCommand.setSourcePosY(command.getSourcePosY()); |
| | | crnCommand.setSourcePosZ(command.getSourcePosZ()); |
| | | crnCommand.setDestinationPosX(command.getDestinationPosX()); |
| | | crnCommand.setDestinationPosY(command.getDestinationPosY()); |
| | | crnCommand.setDestinationPosZ(command.getDestinationPosZ()); |
| | | // crnCommand.setSourceStaNo(command.getSourceStaNo()); |
| | | // crnCommand.setDestinationStaNo(command.getDestinationStaNo()); |
| | | crnCommand.setCommand(command.getCommand()); |
| | | if (command.getTaskNo() == 0 && command.getAckFinish() == 0 && command.getAuto() != 1) { |
| | | command.setTaskNo((short) 9999); |
| | | command.setTaskNo((short) 999); |
| | | } |
| | | |
| | | command.setCrnNo(slave.getId()); |
| | |
| | | command.getCrnNo(), // 堆垛机[非空] |
| | | new Date(), // 下发时间 |
| | | command.getTaskModeType() == null ? null : command.getTaskModeType().toString(), // 模式 |
| | | command.getSourcePosX().intValue(), // 源排 |
| | | command.getSourcePosY().intValue(), // 源列 |
| | | command.getSourcePosZ().intValue(), // 源层 |
| | | command.getSourcePosZ().intValue(), // 源排 |
| | | command.getSourcePosX().intValue(), // 源列 |
| | | command.getSourcePosY().intValue(), // 源层 |
| | | null, // 源站 |
| | | command.getDestinationPosX().intValue(), // 目标排 |
| | | command.getDestinationPosY().intValue(), // 目标列 |
| | | command.getDestinationPosZ().intValue(), // 目标层 |
| | | command.getDestinationPosZ().intValue(), // 目标排 |
| | | command.getDestinationPosX().intValue(), // 目标列 |
| | | command.getDestinationPosY().intValue(), // 目标层 |
| | | null, // 目标站 |
| | | null, // 响应结果 |
| | | null, // 修改时间 |
| | |
| | | } |
| | | |
| | | if (result.IsSuccess) { |
| | | log.warn("堆垛机命令下发[id:{},时间:{}] >>>>> {}", slave.getId(), DateUtils.convert(new Date(), DateUtils.yyyyMMddHHmmsssss_F), JSON.toJSON(command)); |
| | | OutputQueue.CRN.offer(MessageFormat.format("【{0}】[id:{1}] >>>>> 命令下发: {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command))); |
| | | return true; |
| | | // log.warn("堆垛机命令下发[id:{},时间:{}] >>>>> {}", slave.getId(), DateUtils.convert(new Date(), DateUtils.yyyyMMddHHmmsssss_F), JSON.toJSON(command)); |
| | | // OutputQueue.CRN.offer(MessageFormat.format("【{0}】[id:{1}] >>>>> 命令下发: {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command))); |
| | | // return true; |
| | | } else { |
| | | OutputQueue.CRN.offer(MessageFormat.format("【{0}】写入堆垛机plc数据失败 ===>> [id:{1}] [ip:{2}] [port:{3}] [rack:{4}] [slot:{5}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot())); |
| | | log.error("写入堆垛机plc数据失败 ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot()); |
| | | return false; |
| | | } |
| | | |
| | | |
| | | try{ |
| | | //堆垛机任务写入后,回读一次,看是否成功 |
| | | Thread.sleep(500); |
| | | OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB100.0", (short) 24); |
| | | if (resultRead.IsSuccess) { |
| | | CrnCommand one = new CrnCommand(); |
| | | one.setAckFinish(siemensNet.getByteTransform().TransInt16(resultRead.Content, 0)); |
| | | one.setTaskNo(siemensNet.getByteTransform().TransInt16(resultRead.Content, 2)); |
| | | //one.setTaskMode(siemensNet.getByteTransform().TransInt16(resultRead.Content, 4)); |
| | | one.setSourcePosZ(siemensNet.getByteTransform().TransInt16(resultRead.Content, 6)); |
| | | one.setSourcePosX(siemensNet.getByteTransform().TransInt16(resultRead.Content, 8)); |
| | | one.setSourcePosY(siemensNet.getByteTransform().TransInt16(resultRead.Content, 10)); |
| | | one.setDestinationPosZ(siemensNet.getByteTransform().TransInt16(resultRead.Content, 12)); |
| | | one.setDestinationPosX(siemensNet.getByteTransform().TransInt16(resultRead.Content, 14)); |
| | | one.setDestinationPosY(siemensNet.getByteTransform().TransInt16(resultRead.Content, 16)); |
| | | // one.setSourceStaNo(siemensNet.getByteTransform().TransInt16(resultRead.Content, 18)); |
| | | // one.setDestinationStaNo(siemensNet.getByteTransform().TransInt16(resultRead.Content, 20)); |
| | | if (!crnCommand.getTaskNo().equals(one.getTaskNo()) && !crnCommand.getAckFinish().equals(one.getAckFinish()) |
| | | && !crnCommand.getSourcePosZ().equals(one.getSourcePosZ()) && !crnCommand.getSourcePosX().equals(one.getSourcePosX()) && !crnCommand.getSourcePosY().equals(one.getSourcePosY()) |
| | | && !crnCommand.getDestinationPosZ().equals(one.getDestinationPosZ()) && !crnCommand.getDestinationPosX().equals(one.getDestinationPosX()) && !crnCommand.getDestinationPosY().equals(one.getDestinationPosY()) |
| | | ){ |
| | | log.error("堆垛机命令地址写入后回读失败[id:{}] >>>>> 写入[{}],===>>回读[{}]", slave.getId(), JSON.toJSON(command),JSON.toJSON(one)); |
| | | log.error("堆垛机命令回读失败后,重新添加任务到队列 ===>> [id:{}],{}", slave.getId(), JSON.toJSON(crnCommand)); |
| | | MessageQueue.offer(SlaveType.Crn, slave.getId(), new Task(5, crnCommand)); |
| | | Thread.sleep(100); |
| | | readStatus(); |
| | | return false; |
| | | } else { |
| | | log.info("堆垛机命令地址写入后回读成功[id:{}] >>>>> 写入[{}],===>>回读[{}]", slave.getId(), JSON.toJSON(command),JSON.toJSON(one)); |
| | | OutputQueue.CRN.offer(MessageFormat.format("【{0}】[id:{1}] >>>>> 命令下发: {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command))); |
| | | } |
| | | } |
| | | }catch (Exception e){ |
| | | log.error("堆垛机命令地址写入后回读出错"); |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | |
| | | log.error("堆垛机写入命令为空"); |
| | | return false; |
| | | } |
| | | //转换前克隆一份 |
| | | CrnCommand crnCommand = new CrnCommand(); |
| | | crnCommand.setCrnNo(command.getCrnNo()); |
| | | crnCommand.setAckFinish(command.getAckFinish()); |
| | | crnCommand.setTaskNo(command.getTaskNo()); |
| | | crnCommand.setTaskMode(command.getTaskMode()); |
| | | crnCommand.setSourcePosX(command.getSourcePosX()); |
| | | crnCommand.setSourcePosY(command.getSourcePosY()); |
| | | crnCommand.setSourcePosZ(command.getSourcePosZ()); |
| | | crnCommand.setDestinationPosX(command.getDestinationPosX()); |
| | | crnCommand.setDestinationPosY(command.getDestinationPosY()); |
| | | crnCommand.setDestinationPosZ(command.getDestinationPosZ()); |
| | | // crnCommand.setSourceStaNo(command.getSourceStaNo()); |
| | | // crnCommand.setDestinationStaNo(command.getDestinationStaNo()); |
| | | crnCommand.setCommand(command.getCommand()); |
| | | if (command.getTaskNo() == 0 && command.getAckFinish() == 0 && command.getAuto() != 1) { |
| | | command.setTaskNo((short) 9999); |
| | | command.setTaskNo((short) 999); |
| | | } |
| | | |
| | | command.setCrnNo(slave.getId()); |
| | |
| | | |
| | | |
| | | if (result.IsSuccess) { |
| | | log.warn("堆垛机命令下发[id:{},时间:{}] >>>>> {}", slave.getId(), DateUtils.convert(new Date(), DateUtils.yyyyMMddHHmmsssss_F), JSON.toJSON(command)); |
| | | OutputQueue.CRN.offer(MessageFormat.format("【{0}】[id:{1}] >>>>> 命令下发: {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command))); |
| | | // log.warn("堆垛机命令下发[id:{},时间:{}] >>>>> {}", slave.getId(), DateUtils.convert(new Date(), DateUtils.yyyyMMddHHmmsssss_F), JSON.toJSON(command)); |
| | | |
| | | Date now = new Date(); |
| | | |
| | | //更新指令日志 |
| | | commandInfoLog.setDeviceLog("指令下发成功"); |
| | | commandInfoLogService.insert(commandInfoLog); |
| | |
| | | taskWrkService.updateById(taskWrk); |
| | | } |
| | | |
| | | return true; |
| | | |
| | | } else { |
| | | OutputQueue.CRN.offer(MessageFormat.format("【{0}】写入堆垛机plc数据失败 ===>> [id:{1}] [ip:{2}] [port:{3}] [rack:{4}] [slot:{5}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot())); |
| | | log.error("写入堆垛机plc数据失败 ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot()); |
| | |
| | | commandInfoLogService.insert(commandInfoLog); |
| | | return false; |
| | | } |
| | | try{ |
| | | //堆垛机任务写入后,回读一次,看是否成功 |
| | | Thread.sleep(500); |
| | | OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB100.0", (short) 24); |
| | | if (resultRead.IsSuccess) { |
| | | CrnCommand one = new CrnCommand(); |
| | | one.setAckFinish(siemensNet.getByteTransform().TransInt16(resultRead.Content, 0)); |
| | | one.setTaskNo(siemensNet.getByteTransform().TransInt16(resultRead.Content, 2)); |
| | | //one.setTaskMode(siemensNet.getByteTransform().TransInt16(resultRead.Content, 4)); |
| | | one.setSourcePosZ(siemensNet.getByteTransform().TransInt16(resultRead.Content, 6)); |
| | | one.setSourcePosX(siemensNet.getByteTransform().TransInt16(resultRead.Content, 8)); |
| | | one.setSourcePosY(siemensNet.getByteTransform().TransInt16(resultRead.Content, 10)); |
| | | one.setDestinationPosZ(siemensNet.getByteTransform().TransInt16(resultRead.Content, 12)); |
| | | one.setDestinationPosX(siemensNet.getByteTransform().TransInt16(resultRead.Content, 14)); |
| | | one.setDestinationPosY(siemensNet.getByteTransform().TransInt16(resultRead.Content, 16)); |
| | | // one.setSourceStaNo(siemensNet.getByteTransform().TransInt16(resultRead.Content, 18)); |
| | | // one.setDestinationStaNo(siemensNet.getByteTransform().TransInt16(resultRead.Content, 20)); |
| | | if (!crnCommand.getTaskNo().equals(one.getTaskNo()) && !crnCommand.getAckFinish().equals(one.getAckFinish()) |
| | | && !crnCommand.getSourcePosZ().equals(one.getSourcePosZ()) && !crnCommand.getSourcePosX().equals(one.getSourcePosX()) && !crnCommand.getSourcePosY().equals(one.getSourcePosY()) |
| | | && !crnCommand.getDestinationPosZ().equals(one.getDestinationPosZ()) && !crnCommand.getDestinationPosX().equals(one.getDestinationPosX()) && !crnCommand.getDestinationPosY().equals(one.getDestinationPosY()) |
| | | ){ |
| | | log.error("堆垛机命令地址写入后回读失败[id:{}] >>>>> 写入[{}],===>>回读[{}]", slave.getId(), JSON.toJSON(command),JSON.toJSON(one)); |
| | | log.error("堆垛机命令回读失败后,重新添加任务到队列 ===>> [id:{}],{}", slave.getId(), JSON.toJSON(crnCommand)); |
| | | MessageQueue.offer(SlaveType.Crn, slave.getId(), new Task(5, crnCommand)); |
| | | Thread.sleep(100); |
| | | readStatus(); |
| | | return false; |
| | | } else { |
| | | log.info("堆垛机命令地址写入后回读成功[id:{}] >>>>> 写入[{}],===>>回读[{}]", slave.getId(), JSON.toJSON(command),JSON.toJSON(one)); |
| | | OutputQueue.CRN.offer(MessageFormat.format("【{0}】[id:{1}] >>>>> 命令下发: {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command))); |
| | | } |
| | | } |
| | | }catch (Exception e){ |
| | | log.error("堆垛机命令地址写入后回读出错"); |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | private boolean writeAuto(CrnCommand command){ |