| | |
| | | break; |
| | | // 写入数据 |
| | | case 2: |
| | | write2((CrnCommand) task.getData()); |
| | | write5((CrnCommand) task.getData()); |
| | | break; |
| | | // 复位 |
| | | case 3: |
| | |
| | | |
| | | 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(); |
| | |
| | | // 作业信息 |
| | | OperateResult result = siemensNet.Write("DB100.0", array); |
| | | |
| | | 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; |
| | | 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 write5(CrnCommand command) throws InterruptedException { |
| | | String methodName = Thread.currentThread().getStackTrace()[1].getMethodName(); |
| | | |
| | | try{ |
| | | if (null == command) { |
| | | log.error("堆垛机写入命令为空"); |
| | | return false; |
| | | } |
| | | // convertRow(command); |
| | | command.setCrnNo(slave.getId()); |
| | | short[] array = new short[10]; |
| | | 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.getSourceStaNo(); |
| | | // array[10] = command.getDestinationStaNo(); |
| | | array[9] = command.getCommand(); |
| | | |
| | | OperateResult result = siemensNet.Write("DB100.0", array); |
| | | |
| | | int i=0; |
| | | do{ |
| | | //堆垛机任务写入后,回读一次,看是否成功 |
| | | Thread.sleep(500); |
| | | OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB100.0", (short) 24); |
| | | Thread.sleep(200); |
| | | OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB100.0", (short) 20); |
| | | 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.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]) |
| | | 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()) |
| | | ){ |
| | | 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; |
| | | i++; |
| | | log.error("堆垛机命令地址写入后回读失败[id:{}]>>>>重写[{}] >>>>> 写入[{}],===>>回读[{}]", slave.getId(), i,JSON.toJSON(command),JSON.toJSON(one)); |
| | | result = siemensNet.Write("DB100.0", array); |
| | | } else { |
| | | log.info("堆垛机命令地址写入后回读成功[id:{}] >>>>> 写入[{}],===>>回读[{}]", slave.getId(), JSON.toJSON(command),JSON.toJSON(one)); |
| | | i=5; |
| | | } |
| | | } |
| | | }while(i<5); |
| | | |
| | | |
| | | try { |
| | | // 日志记录 |
| | | BasCrnOptService bean = SpringUtils.getBean(BasCrnOptService.class); |
| | | BasCrnOpt basCrnOpt = new BasCrnOpt( |
| | | command.getTaskNo().intValue(), // 任务号 |
| | | command.getCrnNo(), // 堆垛机[非空] |
| | | new Date(), // 下发时间 |
| | | 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 != null && result.IsSuccess) { |
| | | Thread.sleep(200); |
| | | this.readStatus(); |
| | | log.info(methodName + ":堆垛机命令下发[id:{}] >>>>> {}", slave.getId(), JSON.toJSON(command)); |
| | | 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; |
| | | } else { |
| | | OutputQueue.CRN.offer(MessageFormat.format("【{0}】写入堆垛机plc数据失败 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort())); |
| | | log.error(methodName + ":写入堆垛机plc数据失败 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | CommandInfoLog commandInfoLog = JSON.parseObject(JSON.toJSONString(commandInfo), CommandInfoLog.class); |
| | | commandInfoLog.setId(null); |
| | | // CommandInfoLog commandInfoLog = new CommandInfoLog(); |
| | | // if (commandInfo != null) { |
| | | // commandInfoLog = JSON.parseObject(JSON.toJSONString(commandInfo), CommandInfoLog.class); |
| | | // commandInfoLog.setId(null); |
| | | // }else { |
| | | // Date now = new Date(); |
| | | // commandInfoLog.setCommand(JSON.toJSONString(command)); |
| | | // commandInfoLog.setCommandStatus(3); |
| | | // commandInfoLog.setStartTime(now); |
| | | // commandInfoLog.setExecuteTime(now); |
| | | // commandInfoLog.setCompleteTime(now); |
| | | // commandInfoLog.setDevice(SlaveType.Devp.toString()); |
| | | // commandInfoLog.setWrkNo(9999); |
| | | // commandInfoLog.setTaskNo("9999"); |
| | | // commandInfoLog.setCommandDesc("手动命令"); |
| | | // } |
| | | |
| | | |
| | | if (result.IsSuccess) { |
| | | // log.warn("堆垛机命令下发[id:{},时间:{}] >>>>> {}", slave.getId(), DateUtils.convert(new Date(), DateUtils.yyyyMMddHHmmsssss_F), JSON.toJSON(command)); |
| | | |
| | | Date now = new Date(); |
| | | //更新指令日志 |
| | | commandInfoLog.setDeviceLog("指令下发成功"); |
| | |
| | | } 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()); |
| | | |
| | | //更新指令日志 |
| | | commandInfoLog.setDeviceLog("指令下发失败"); |
| | | 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; |
| | | } |