| | |
| | | // 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()); |
| | |
| | | } |
| | | array[1] = command.getTaskNo(); |
| | | array[2] = command.getTaskMode(); |
| | | array[3] = command.getSourcePosZ(); |
| | | array[4] = command.getSourcePosX(); |
| | | array[5] = command.getSourcePosY(); |
| | | array[6] = command.getDestinationPosZ(); |
| | | array[7] = command.getDestinationPosX(); |
| | | array[8] = command.getDestinationPosY(); |
| | | array[3] = command.getSourcePosX(); |
| | | array[4] = command.getSourcePosY(); |
| | | array[5] = command.getSourcePosZ(); |
| | | array[6] = command.getDestinationPosX(); |
| | | array[7] = command.getDestinationPosY(); |
| | | array[8] = command.getDestinationPosZ(); |
| | | array[9] = command.getCommand(); |
| | | OperateResult result18 = siemensNet.Write("DB100.18", (short)0); |
| | | try{ |
| | | Thread.sleep(100L); |
| | | } catch (Exception e){} |
| | | // 作业信息 |
| | | OperateResult result = siemensNet.Write("DB100.0", array); |
| | | // int i=0; |
| | | // do{ |
| | | // //堆垛机任务写入后,回读一次,看是否成功 |
| | | // try{ |
| | | // Thread.sleep(100L); |
| | | // } catch (Exception e){} |
| | | // OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB100.0", (short) 20); |
| | | // if (resultRead.IsSuccess) { |
| | | // CrnCommand one = new CrnCommand(); |
| | | // one.setTaskNo(siemensNet.getByteTransform().TransInt16(resultRead.Content, 2)); |
| | | // one.setTaskMode(siemensNet.getByteTransform().TransInt16(resultRead.Content, 4)); |
| | | // one.setSourcePosX(siemensNet.getByteTransform().TransInt16(resultRead.Content, 6)); |
| | | // one.setSourcePosY(siemensNet.getByteTransform().TransInt16(resultRead.Content, 8)); |
| | | // one.setSourcePosZ(siemensNet.getByteTransform().TransInt16(resultRead.Content, 10)); |
| | | // one.setDestinationPosX(siemensNet.getByteTransform().TransInt16(resultRead.Content, 12)); |
| | | // one.setDestinationPosY(siemensNet.getByteTransform().TransInt16(resultRead.Content, 14)); |
| | | // one.setDestinationPosZ(siemensNet.getByteTransform().TransInt16(resultRead.Content, 16)); |
| | | // if (!command.getTaskNo().equals(one.getTaskNo()) || !command.getTaskMode().equals(one.getTaskMode()) |
| | | // || !command.getSourcePosX().equals(one.getSourcePosX()) || !command.getSourcePosY().equals(one.getSourcePosY()) |
| | | // || !command.getSourcePosZ().equals(one.getSourcePosZ()) || !command.getDestinationPosX().equals(one.getDestinationPosX()) |
| | | // || !command.getDestinationPosY().equals(one.getDestinationPosY()) || !command.getDestinationPosZ().equals(one.getDestinationPosZ()) |
| | | // ){ |
| | | // i++; |
| | | // log.error("堆垛机命令地址写入后回读失败[id:{}]>>>>重写[{}] >>>>> 写入[{}],===>>回读[{}]", slave.getId(), i,JSON.toJSON(command),JSON.toJSON(one)); |
| | | // result = siemensNet.Write("DB100.0", array); |
| | | // }else{ |
| | | // break; |
| | | // } |
| | | // } |
| | | // }while(i<5); |
| | | |
| | | if (command.getAckFinish() == 0) { |
| | | short commandFinish = 1; |
| | | try{ |
| | | Thread.sleep(100L); |
| | | } catch (Exception e){} |
| | | result = siemensNet.Write("DB100.18", commandFinish); |
| | | int signFinish = 1; |
| | | while (signFinish<5){ |
| | | OperateResultExOne<byte[]> result10018 = siemensNet.Read("DB100.18", (short) 2); |
| | | short transInt16 = siemensNet.getByteTransform().TransInt16(result10018.Content, 0); |
| | | if (transInt16 != commandFinish){ |
| | | log.info("下发DB100.18 回读失败" + "commandFinish:"+commandFinish); |
| | | log.info("下发DB100.18 回读失败" + "array:"+ JSON.toJSONString(array)); |
| | | result = siemensNet.Write("DB100.18", commandFinish); |
| | | signFinish++; |
| | | }else { |
| | | log.info("下发DB100.18" + "commandFinish:"+commandFinish); |
| | | log.info("下发DB100.18" + "array:"+ JSON.toJSONString(array)); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | if (command.getAckFinish() != 1) { |
| | | BasCrnOptService bean = SpringUtils.getBean(BasCrnOptService.class); |
| | | BasCrnOpt basCrnOpt = new BasCrnOpt( |
| | | command.getTaskNo().intValue(), // 任务号 |
| | | command.getCrnNo(), // 堆垛机[非空] |
| | | new Date(), // 下发时间 |
| | | command.getTaskModeType() == null ? null : command.getTaskModeType().toString(), // 模式 |
| | | command.getSourcePosZ().intValue(), // 源排 |
| | | command.getSourcePosX().intValue(), // 源列 |
| | | command.getSourcePosY().intValue(), // 源层 |
| | | null, // 源站 |
| | | command.getDestinationPosZ().intValue(), // 目标排 |
| | | command.getDestinationPosX().intValue(), // 目标列 |
| | | command.getDestinationPosY().intValue(), // 目标层 |
| | | null, // 目标站 |
| | | null, // 响应结果 |
| | | null, // 修改时间 |
| | | null // 修改人员 |
| | | ); |
| | | bean.insert(basCrnOpt); |
| | | } |
| | | |
| | | 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; |
| | | } 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.setSourcePosX(siemensNet.getByteTransform().TransInt16(resultRead.Content, 6)); |
| | | one.setSourcePosY(siemensNet.getByteTransform().TransInt16(resultRead.Content, 8)); |
| | | one.setSourcePosZ(siemensNet.getByteTransform().TransInt16(resultRead.Content, 10)); |
| | | one.setDestinationPosX(siemensNet.getByteTransform().TransInt16(resultRead.Content, 12)); |
| | | one.setDestinationPosY(siemensNet.getByteTransform().TransInt16(resultRead.Content, 14)); |
| | | one.setDestinationPosZ(siemensNet.getByteTransform().TransInt16(resultRead.Content, 16)); |
| | | // one.setSourceStaNo(siemensNet.getByteTransform().TransInt16(resultRead.Content, 18)); |
| | | // one.setDestinationStaNo(siemensNet.getByteTransform().TransInt16(resultRead.Content, 20)); |
| | | if (!one.getTaskNo().equals(array[1]) || !one.getAckFinish().equals(array[0]) |
| | | || !one.getSourcePosZ().equals(array[5]) || !one.getSourcePosX().equals(array[3]) |
| | | || !one.getSourcePosY().equals(array[4]) |
| | | || !one.getDestinationPosZ().equals(array[8]) || !one.getDestinationPosX().equals(array[6]) |
| | | || !one.getDestinationPosY().equals(array[7]) |
| | | ){ |
| | | log.error("传参==堆垛机命令地址写入后回读失败[id:{}] >>>>> 写入[{}],===>>回读[{}]", slave.getId(), JSON.toJSON(command),JSON.toJSON(one)); |
| | | 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("堆垛机命令地址写入后回读出错"); |
| | | log.error("堆垛机命令地址写入后回读出错:异常信息:"+e); |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * 写入数据 |
| | | */ |
| | | private boolean write2(CrnCommand command){ |
| | | if (null == command) { |
| | | 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) 999); |
| | | } |
| | | |
| | | command.setCrnNo(slave.getId()); |
| | | short[] array = new short[10]; |
| | | if (Cools.isEmpty(command.getAckFinish())) { |
| | | array[0] = 5; |
| | | } else { |
| | | array[0] = command.getAckFinish(); |
| | | } |
| | | array[1] = command.getTaskNo(); |
| | | array[2] = command.getTaskMode(); |
| | | array[3] = command.getSourcePosX(); |
| | | array[4] = command.getSourcePosY(); |
| | | array[5] = command.getSourcePosZ(); |
| | | array[6] = command.getDestinationPosX(); |
| | | array[7] = command.getDestinationPosY(); |
| | | array[8] = command.getDestinationPosZ(); |
| | | array[9] = command.getCommand(); |
| | | OperateResult result18 = siemensNet.Write("DB100.18", (short)0); |
| | | try{ |
| | | Thread.sleep(100L); |
| | | } catch (Exception e){} |
| | | // 作业信息 |
| | | OperateResult result = siemensNet.Write("DB100.0", array); |
| | | |
| | | // int i=0; |
| | | // do{ |
| | | // //堆垛机任务写入后,回读一次,看是否成功 |
| | | // try{ |
| | | // Thread.sleep(100L); |
| | | // } catch (Exception e){} |
| | | // OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB100.0", (short) 20); |
| | | // if (resultRead.IsSuccess) { |
| | | // CrnCommand one = new CrnCommand(); |
| | | // one.setTaskNo(siemensNet.getByteTransform().TransInt16(resultRead.Content, 2)); |
| | | // one.setTaskMode(siemensNet.getByteTransform().TransInt16(resultRead.Content, 4)); |
| | | // one.setSourcePosX(siemensNet.getByteTransform().TransInt16(resultRead.Content, 6)); |
| | | // one.setSourcePosY(siemensNet.getByteTransform().TransInt16(resultRead.Content, 8)); |
| | | // one.setSourcePosZ(siemensNet.getByteTransform().TransInt16(resultRead.Content, 10)); |
| | | // one.setDestinationPosX(siemensNet.getByteTransform().TransInt16(resultRead.Content, 12)); |
| | | // one.setDestinationPosY(siemensNet.getByteTransform().TransInt16(resultRead.Content, 14)); |
| | | // one.setDestinationPosZ(siemensNet.getByteTransform().TransInt16(resultRead.Content, 16)); |
| | | // if (!command.getTaskNo().equals(one.getTaskNo()) || !command.getTaskMode().equals(one.getTaskMode()) |
| | | // || !command.getSourcePosX().equals(one.getSourcePosX()) || !command.getSourcePosY().equals(one.getSourcePosY()) |
| | | // || !command.getSourcePosZ().equals(one.getSourcePosZ()) || !command.getDestinationPosX().equals(one.getDestinationPosX()) |
| | | // || !command.getDestinationPosY().equals(one.getDestinationPosY()) || !command.getDestinationPosZ().equals(one.getDestinationPosZ()) |
| | | // ){ |
| | | // i++; |
| | | // log.error("堆垛机命令地址写入后回读失败[id:{}]>>>>重写[{}] >>>>> 写入[{}],===>>回读[{}]", slave.getId(), i,JSON.toJSON(command),JSON.toJSON(one)); |
| | | // result = siemensNet.Write("DB100.0", array); |
| | | // }else{ |
| | | // break; |
| | | // } |
| | | // } |
| | | // }while(i<5); |
| | | |
| | | if (command.getAckFinish() == 0) { |
| | | short commandFinish = 1; |
| | | try{ |
| | | Thread.sleep(100L); |
| | | } catch (Exception e){} |
| | | result = siemensNet.Write("DB100.18", commandFinish); |
| | | int signFinish = 1; |
| | | while (signFinish<5){ |
| | | OperateResultExOne<byte[]> result10018 = siemensNet.Read("DB100.18", (short) 2); |
| | | short transInt16 = siemensNet.getByteTransform().TransInt16(result10018.Content, 0); |
| | | if (transInt16 != commandFinish){ |
| | | log.info("下发DB100.18 回读失败" + "commandFinish:"+commandFinish); |
| | | log.info("下发DB100.18 回读失败" + "array:"+ JSON.toJSONString(array)); |
| | | result = siemensNet.Write("DB100.18", commandFinish); |
| | | signFinish++; |
| | | }else { |
| | | log.info("下发DB100.18" + "commandFinish:"+commandFinish); |
| | | log.info("下发DB100.18" + "array:"+ JSON.toJSONString(array)); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | // 日志记录 |
| | | if (command.getAckFinish() != 1) { |
| | | BasCrnOptService bean = SpringUtils.getBean(BasCrnOptService.class); |
| | | BasCrnOpt basCrnOpt = new BasCrnOpt( |
| | |
| | | ); |
| | | bean.insert(basCrnOpt); |
| | | } |
| | | |
| | | 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; |
| | | } 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; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 写入数据 |
| | | */ |
| | | private boolean write2(CrnCommand command){ |
| | | if (null == command) { |
| | | log.error("堆垛机写入命令为空"); |
| | | return false; |
| | | } |
| | | if (command.getTaskNo() == 0 && command.getAckFinish() == 0 && command.getAuto() != 1) { |
| | | command.setTaskNo((short) 9999); |
| | | } |
| | | |
| | | command.setCrnNo(slave.getId()); |
| | | short[] array = new short[10]; |
| | | if (Cools.isEmpty(command.getAckFinish())) { |
| | | array[0] = 5; |
| | | } else { |
| | | array[0] = command.getAckFinish(); |
| | | } |
| | | array[1] = command.getTaskNo(); |
| | | array[2] = command.getTaskMode(); |
| | | array[3] = command.getSourcePosZ(); |
| | | array[4] = command.getSourcePosX(); |
| | | array[5] = command.getSourcePosY(); |
| | | array[6] = command.getDestinationPosZ(); |
| | | array[7] = command.getDestinationPosX(); |
| | | array[8] = command.getDestinationPosY(); |
| | | array[9] = command.getCommand(); |
| | | // 作业信息 |
| | | OperateResult result = siemensNet.Write("DB100.0", array); |
| | | // 日志记录 |
| | | // try { |
| | | if (command.getAckFinish() != 1) { |
| | | BasCrnOptService bean = SpringUtils.getBean(BasCrnOptService.class); |
| | | BasCrnOpt basCrnOpt = new BasCrnOpt( |
| | | command.getTaskNo().intValue(), // 任务号 |
| | | command.getCrnNo(), // 堆垛机[非空] |
| | | new Date(), // 下发时间 |
| | | command.getTaskModeType() == null ? null : command.getTaskModeType().toString(), // 模式 |
| | | command.getSourcePosX().intValue(), // 源排 |
| | | command.getSourcePosY().intValue(), // 源列 |
| | | command.getSourcePosZ().intValue(), // 源层 |
| | | null, // 源站 |
| | | command.getDestinationPosX().intValue(), // 目标排 |
| | | command.getDestinationPosY().intValue(), // 目标列 |
| | | command.getDestinationPosZ().intValue(), // 目标层 |
| | | null, // 目标站 |
| | | null, // 响应结果 |
| | | null, // 修改时间 |
| | | null // 修改人员 |
| | | ); |
| | | bean.insert(basCrnOpt); |
| | | } |
| | | // } catch (Exception ignore) {} |
| | | |
| | | //更新命令日志 |
| | |
| | | |
| | | |
| | | 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 (command.getTaskNo() == 0 && command.getAckFinish() == 0 && command.getAuto() != 1) { |
| | | command.setTaskNo((short) 999); |
| | | } |
| | | |
| | | command.setCrnNo(slave.getId()); |
| | | short[] array = new short[10]; |
| | | if (Cools.isEmpty(command.getAckFinish())) { |
| | | array[0] = 5; |
| | | } else { |
| | | array[0] = command.getAckFinish(); |
| | | } |
| | | array[1] = command.getTaskNo(); |
| | | array[2] = command.getTaskMode(); |
| | | array[3] = command.getSourcePosX(); |
| | | array[4] = command.getSourcePosY(); |
| | | array[5] = command.getSourcePosZ(); |
| | | array[6] = command.getDestinationPosX(); |
| | | array[7] = command.getDestinationPosY(); |
| | | array[8] = command.getDestinationPosZ(); |
| | | array[9] = command.getCommand(); |
| | | // 作业信息 |
| | | OperateResult result = siemensNet.Write("DB100.0", array); |
| | | * */ |
| | | 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.setSourcePosX(siemensNet.getByteTransform().TransInt16(resultRead.Content, 6)); |
| | | one.setSourcePosY(siemensNet.getByteTransform().TransInt16(resultRead.Content, 8)); |
| | | one.setSourcePosZ(siemensNet.getByteTransform().TransInt16(resultRead.Content, 10)); |
| | | one.setDestinationPosX(siemensNet.getByteTransform().TransInt16(resultRead.Content, 12)); |
| | | one.setDestinationPosY(siemensNet.getByteTransform().TransInt16(resultRead.Content, 14)); |
| | | one.setDestinationPosZ(siemensNet.getByteTransform().TransInt16(resultRead.Content, 16)); |
| | | // one.setSourceStaNo(siemensNet.getByteTransform().TransInt16(resultRead.Content, 18)); |
| | | // one.setDestinationStaNo(siemensNet.getByteTransform().TransInt16(resultRead.Content, 20)); |
| | | if (!one.getTaskNo().equals(array[1]) || !one.getAckFinish().equals(array[0]) |
| | | || !one.getSourcePosZ().equals(array[5]) || !one.getSourcePosX().equals(array[3]) |
| | | || !one.getSourcePosY().equals(array[4]) |
| | | || !one.getDestinationPosZ().equals(array[8]) || !one.getDestinationPosX().equals(array[6]) |
| | | || !one.getDestinationPosY().equals(array[7]) |
| | | ){ |
| | | 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){ |