|  |  | 
 |  |  |                     case 1: | 
 |  |  |                         readStatus(); | 
 |  |  |                         break; | 
 |  |  |                     // 工位1、2写入数据 | 
 |  |  |                     //工位1写入数据 | 
 |  |  |                     case 2: | 
 |  |  |                         write((RgvCommand) task.getData()); | 
 |  |  |                         break; | 
 |  |  |                     //工位1写入数据 | 
 |  |  |                     case 4: | 
 |  |  |                         write1((RgvCommand) task.getData()); | 
 |  |  |                         break; | 
 |  |  |                     //工位2写入数据 | 
 |  |  |                     case 5: | 
 |  |  |                         write2((RgvCommand) task.getData()); | 
 |  |  |                         break; | 
 |  |  |                     // 复位 | 
 |  |  |                     case 3: | 
 |  |  |                         RgvCommand command = (RgvCommand) task.getData(); | 
 |  |  |                         if (null == command) { | 
 |  |  |                             command = new RgvCommand(); | 
 |  |  |                         } | 
 |  |  |                         command.setRgvNo(slave.getId()); // RGV编号 | 
 |  |  |                         command.setTaskNo1((short) 0); // 工作号 | 
 |  |  |                         command.setAckFinish1((short) 1);  // 任务完成确认位 | 
 |  |  |                         command.setTaskMode1(RgvTaskModeType.NONE); // 任务模式 | 
 |  |  |                         command.setSourceStaNo1((short)0);     // 源站 | 
 |  |  |                         command.setDestinationStaNo1((short)0);     // 目标站 | 
 |  |  |                         command.setTaskNo2((short) 0); // 工作号 | 
 |  |  |                         command.setAckFinish2((short) 1);  // 任务完成确认位 | 
 |  |  |                         command.setTaskMode2(RgvTaskModeType.NONE); // 任务模式 | 
 |  |  |                         command.setSourceStaNo2((short)0);     // 源站 | 
 |  |  |                         command.setDestinationStaNo2((short)0);     // 目标站 | 
 |  |  |                         command.setCommand((short)0); | 
 |  |  |                         write(command); | 
 |  |  |                         break; | 
 |  |  |                     // 回原点  避让 | 
 |  |  |                     case 9: | 
 |  |  |                         RgvCommand commandAvoidanceXY = (RgvCommand) task.getData(); | 
 |  |  |                         if (null == commandAvoidanceXY) { | 
 |  |  |                             commandAvoidanceXY = new RgvCommand(); | 
 |  |  |                         } | 
 |  |  |                         commandAvoidanceXY.setRgvNo(slave.getId()); // RGV编号 | 
 |  |  |                         commandAvoidanceXY.setTaskNo1((short) 32222); // 工作号 | 
 |  |  |                         commandAvoidanceXY.setAckFinish1((short) 1);  // 任务完成确认位 | 
 |  |  |                         commandAvoidanceXY.setTaskMode1(RgvTaskModeType.X_MOVE); // 任务模式 | 
 |  |  |                         commandAvoidanceXY.setSourceStaNo1((short)0);     // 源站 | 
 |  |  |                         commandAvoidanceXY.setDestinationStaNo1(slave.getId()==1? (short) 101:(short)116);     // 目标站 | 
 |  |  |                         commandAvoidanceXY.setTaskNo2((short) 0); // 工作号 | 
 |  |  |                         commandAvoidanceXY.setAckFinish2((short) 1);  // 任务完成确认位 | 
 |  |  |                         commandAvoidanceXY.setTaskMode2(RgvTaskModeType.X_MOVE); // 任务模式 | 
 |  |  |                         commandAvoidanceXY.setSourceStaNo2((short)0);     // 源站 | 
 |  |  |                         commandAvoidanceXY.setDestinationStaNo2(slave.getId()==1? (short) 101:(short)117);     // 目标站 | 
 |  |  |                         commandAvoidanceXY.setCommand((short)0); | 
 |  |  |                         write(commandAvoidanceXY); | 
 |  |  |                         break; | 
 |  |  |                     default: | 
 |  |  |                         break; | 
 |  |  | 
 |  |  |         rgvProtocol.setStatus1((short)-1); | 
 |  |  |         rgvProtocol.setLoaded1((short)0); | 
 |  |  |         rgvProtocol.setWalkPos((short)0); | 
 |  |  |         rgvProtocol.setRgvPos((short)0); | 
 |  |  |         rgvProtocol.setRgvPos(0L); | 
 |  |  |         rgvProtocol.setTaskNo2((short)0); | 
 |  |  |         rgvProtocol.setStatus2((short)-1); | 
 |  |  |         rgvProtocol.setLoaded2((short)0); | 
 |  |  | 
 |  |  |      */ | 
 |  |  |     private void readStatus(){ | 
 |  |  |         try { | 
 |  |  |             OperateResultExOne<byte[]> result = siemensNet.Read("DB101.0", (short) 34); | 
 |  |  |             OperateResultExOne<byte[]> result = siemensNet.Read("DB100.0", (short) 18); | 
 |  |  |             if (result.IsSuccess) { | 
 |  |  |                 if (null == rgvProtocol) { | 
 |  |  |                     rgvProtocol = new RgvProtocol(); | 
 |  |  |                     rgvProtocol.setRgvNo(slave.getId()); | 
 |  |  |                 } | 
 |  |  |                 rgvProtocol.setMode(siemensNet.getByteTransform().TransInt16(result.Content, 0)); | 
 |  |  |                 rgvProtocol.setStatus(siemensNet.getByteTransform().TransInt16(result.Content, 2)); | 
 |  |  |                 rgvProtocol.setTaskNo1(siemensNet.getByteTransform().TransInt16(result.Content, 4)); | 
 |  |  |                 rgvProtocol.setStatus1(siemensNet.getByteTransform().TransInt16(result.Content, 6)); | 
 |  |  |                 rgvProtocol.setLoaded1(siemensNet.getByteTransform().TransInt16(result.Content, 8)); | 
 |  |  |                 rgvProtocol.setRgvPos(RouteUtils.RgvPosSta(slave.getId(),siemensNet.getByteTransform().TransInt16(result.Content, 10))); | 
 |  |  |                 rgvProtocol.setWalkPos(siemensNet.getByteTransform().TransInt16(result.Content, 12)); | 
 |  |  |                 rgvProtocol.setTaskNo2(siemensNet.getByteTransform().TransInt16(result.Content, 14)); | 
 |  |  |                 rgvProtocol.setStatus2(siemensNet.getByteTransform().TransInt16(result.Content, 16)); | 
 |  |  |                 rgvProtocol.setLoaded2(siemensNet.getByteTransform().TransInt16(result.Content, 18)); | 
 |  |  |                 rgvProtocol.setAlarm(siemensNet.getByteTransform().TransInt16(result.Content, 20)); | 
 |  |  |                 rgvProtocol.setHeart(siemensNet.getByteTransform().TransInt16(result.Content, 22)); | 
 |  |  |                 rgvProtocol.setTemp1(siemensNet.getByteTransform().TransInt16(result.Content, 24)); | 
 |  |  |                 rgvProtocol.setTemp2(siemensNet.getByteTransform().TransInt16(result.Content, 26)); | 
 |  |  |                 rgvProtocol.setTemp3(siemensNet.getByteTransform().TransInt16(result.Content, 28)); | 
 |  |  |                 rgvProtocol.setTemp4(siemensNet.getByteTransform().TransInt16(result.Content, 30)); | 
 |  |  |                 rgvProtocol.setTemp5(siemensNet.getByteTransform().TransInt16(result.Content, 32)); | 
 |  |  | //                rgvProtocol.setxSpeed(siemensNet.getByteTransform().TransInt16(result.Content, 28)); | 
 |  |  | //                rgvProtocol.setxDistance(siemensNet.getByteTransform().TransInt16(result.Content, 40)); | 
 |  |  | //                rgvProtocol.setxDuration(siemensNet.getByteTransform().TransInt16(result.Content, 48)); | 
 |  |  |  | 
 |  |  |                 rgvProtocol.setStartSta(siemensNet.getByteTransform().TransInt16(result.Content, 2)); | 
 |  |  |                 rgvProtocol.setEndSta(siemensNet.getByteTransform().TransInt16(result.Content, 4)); | 
 |  |  |                 rgvProtocol.setTaskNo1(siemensNet.getByteTransform().TransInt16(result.Content, 6)); | 
 |  |  |                 rgvProtocol.setAlarm(siemensNet.getByteTransform().TransInt16(result.Content, 8)); | 
 |  |  |                 rgvProtocol.setStatus(siemensNet.getByteTransform().TransInt16(result.Content, 10)); | 
 |  |  |                 rgvProtocol.setxSpeed(siemensNet.getByteTransform().TransInt16(result.Content, 12)); | 
 |  |  |                 rgvProtocol.setRgvPos(siemensNet.getByteTransform().TransUInt32(result.Content, 14)); | 
 |  |  |                 rgvProtocol.setRgvPos(slave.getId().longValue()*100000); | 
 |  |  |                 OutputQueue.RGV.offer(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功",DateUtils.convert(new Date()), slave.getId())); | 
 |  |  |  | 
 |  |  |                 // 工位1复位信号 | 
 |  |  | 
 |  |  |                     } | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |                 // 工位2复位信号 | 
 |  |  |                 if (rgvProtocol.getStatusType2().equals(RgvStatusType.WAITING) | 
 |  |  |                         || rgvProtocol.getStatusType2().equals(RgvStatusType.FETCHWAITING)) { | 
 |  |  |                     if (resetFlag2) { | 
 |  |  |                         RgvCommand rgvCommand = new RgvCommand(); | 
 |  |  |                         rgvCommand.setAckFinish2((short)1); | 
 |  |  |                         if (write(rgvCommand)) { | 
 |  |  |                             resetFlag2 = false; | 
 |  |  |                         } | 
 |  |  |                     } | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |                 try { | 
 |  |  |                     // 根据实时信息更新数据库 | 
 |  |  |                     BasRgvService basRgvService = SpringUtils.getBean(BasRgvService.class); | 
 |  |  | 
 |  |  |                     if (!basRgvService.updateById(rgvProtocol.toSqlModel(basRgv))){ | 
 |  |  |                         log.error("RGV plc数据库更新失败 ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot()); | 
 |  |  |                     } | 
 |  |  |                 } catch (Exception ignore){} | 
 |  |  |                 } catch (Exception ignore) { | 
 |  |  |  | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |             } else { | 
 |  |  |                 initRgv(); | 
 |  |  | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 工位1、2同时写入数据 | 
 |  |  |      */ | 
 |  |  |     private boolean write(RgvCommand command) throws InterruptedException { | 
 |  |  |         if (null == command) { | 
 |  |  |             log.error("RGV写入命令为空"); | 
 |  |  |             return false; | 
 |  |  |         } | 
 |  |  | //        convertRow(command); | 
 |  |  |         command.setRgvNo(slave.getId()); | 
 |  |  |         short[] array = new short[11]; | 
 |  |  |         array[0] = command.getAckFinish1(); | 
 |  |  |         array[1] = command.getTaskNo1(); | 
 |  |  |         array[2] = command.getTaskMode1(); | 
 |  |  |         array[3] = command.getSourceStaNo1(); | 
 |  |  |         array[4] = command.getDestinationStaNo1(); | 
 |  |  |         array[5] = command.getAckFinish2(); | 
 |  |  |         array[6] = command.getTaskNo2(); | 
 |  |  |         array[7] = command.getTaskMode2(); | 
 |  |  |         array[8] = command.getSourceStaNo2(); | 
 |  |  |         array[9] = command.getDestinationStaNo2(); | 
 |  |  |         array[10] = command.getCommand(); | 
 |  |  |         OperateResult result = siemensNet.Write("DB100.0", array); | 
 |  |  |  | 
 |  |  |         if (command.getAckFinish1() == 0 && command.getAckFinish2() == 0) { | 
 |  |  |             short commandFinish = 3;  //工位1、2任务同时写入 | 
 |  |  |             Thread.sleep(100L); | 
 |  |  |             result = siemensNet.Write("DB100.20", commandFinish); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         try { | 
 |  |  |             // 日志记录 | 
 |  |  |             BasRgvOptService bean = SpringUtils.getBean(BasRgvOptService.class); | 
 |  |  |             BasRgvOpt basRgvOpt = new BasRgvOpt( | 
 |  |  |                     command.getTaskNo1().intValue(), | 
 |  |  |                     command.getTaskNo2().intValue(), | 
 |  |  |                     command.getRgvNo(), | 
 |  |  |                     new Date(), | 
 |  |  |                     command.getTaskModeType1().toString(), | 
 |  |  |                     command.getSourceStaNo1().intValue(), | 
 |  |  |                     command.getDestinationStaNo1().intValue(), | 
 |  |  |                     command.getSourceStaNo2().intValue(), | 
 |  |  |                     command.getDestinationStaNo2().intValue(), | 
 |  |  |                     null, | 
 |  |  |                     new Date(), | 
 |  |  |                     null | 
 |  |  |             ); | 
 |  |  |             bean.insert(basRgvOpt); | 
 |  |  |         } catch (Exception ignore) {} | 
 |  |  |  | 
 |  |  |         if (result != null && result.IsSuccess) { | 
 |  |  |             Thread.sleep(200); | 
 |  |  |             this.readStatus(); | 
 |  |  |             log.info("RGV 命令下发[id:{}] >>>>> {}", slave.getId(), JSON.toJSON(command)); | 
 |  |  |             OutputQueue.RGV.offer(MessageFormat.format("【{0}】[id:{1}] >>>>> 命令下发: {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command))); | 
 |  |  |             return true; | 
 |  |  |         } else { | 
 |  |  |             OutputQueue.RGV.offer(MessageFormat.format("【{0}】写入RGV plc数据失败 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort())); | 
 |  |  |             log.error("写入RGV plc数据失败 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); | 
 |  |  |             return false; | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 工位1写入数据 | 
 |  |  |      */ | 
 |  |  |     private boolean write1(RgvCommand command) throws InterruptedException { | 
 |  |  |     private boolean write(RgvCommand command) throws InterruptedException { | 
 |  |  |         if (null == command) { | 
 |  |  |             log.error("RGV写入命令为空"); | 
 |  |  |             return false; | 
 |  |  | 
 |  |  |         if (result != null && result.IsSuccess) { | 
 |  |  |             Thread.sleep(200); | 
 |  |  |             this.readStatus(); | 
 |  |  |             log.info("RGV 工位1命令下发[id:{}] >>>>> {}", slave.getId(), JSON.toJSON(command)); | 
 |  |  |             OutputQueue.RGV.offer(MessageFormat.format("【{0}】[id:{1}] >>>>> 工位1命令下发: {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command))); | 
 |  |  |             log.info("RGV 工位1命令下发[id:{}] >>>>> {}", slave.getId(), JSON.toJSONString(command)); | 
 |  |  |             OutputQueue.RGV.offer(MessageFormat.format("【{0}】[id:{1}] >>>>> 工位1命令下发: {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSONString(command))); | 
 |  |  |             return true; | 
 |  |  |         } else { | 
 |  |  |             OutputQueue.RGV.offer(MessageFormat.format("【{0}】写入RGV plc工位1数据失败 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort())); | 
 |  |  |             log.error("写入RGV plc工位1数据失败 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); | 
 |  |  |             return false; | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 工位2写入数据 | 
 |  |  |      */ | 
 |  |  |     private boolean write2(RgvCommand command) throws InterruptedException { | 
 |  |  |         if (null == command) { | 
 |  |  |             log.error("RGV写入命令为空"); | 
 |  |  |             return false; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         command.setRgvNo(slave.getId()); | 
 |  |  |         short[] array = new short[6]; | 
 |  |  |         array[0] = command.getAckFinish2();//任务完成确认位 | 
 |  |  |         array[1] = command.getTaskNo2();//任务号 | 
 |  |  |         array[2] = command.getTaskMode2();//任务模式 | 
 |  |  |         array[3] = command.getSourceStaNo2();//源站 | 
 |  |  |         array[4] = command.getDestinationStaNo2();//目标站 | 
 |  |  |         array[5] = command.getCommand();//任务下发确认 | 
 |  |  |  | 
 |  |  |         OperateResult result = siemensNet.Write("DB100.10", array); | 
 |  |  |  | 
 |  |  |         if (command.getAckFinish2() == 0) { | 
 |  |  |             short commandFinish = 2;  //工位2任务写入 | 
 |  |  |             Thread.sleep(100L); | 
 |  |  |             result = siemensNet.Write("DB100.20", commandFinish); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         try { | 
 |  |  |             // 日志记录 | 
 |  |  |             BasRgvOptService bean = SpringUtils.getBean(BasRgvOptService.class); | 
 |  |  |             BasRgvOpt basRgvOpt = new BasRgvOpt( | 
 |  |  |                     command.getTaskNo1().intValue(), | 
 |  |  |                     command.getTaskNo2().intValue(), | 
 |  |  |                     command.getRgvNo(), | 
 |  |  |                     new Date(), | 
 |  |  |                     command.getTaskModeType1().toString(), | 
 |  |  |                     command.getSourceStaNo1().intValue(), | 
 |  |  |                     command.getDestinationStaNo1().intValue(), | 
 |  |  |                     command.getSourceStaNo2().intValue(), | 
 |  |  |                     command.getDestinationStaNo2().intValue(), | 
 |  |  |                     null, | 
 |  |  |                     new Date(), | 
 |  |  |                     null | 
 |  |  |             ); | 
 |  |  |             bean.insert(basRgvOpt); | 
 |  |  |         } catch (Exception ignore) {} | 
 |  |  |  | 
 |  |  |         if (result != null && result.IsSuccess) { | 
 |  |  |             Thread.sleep(200); | 
 |  |  |             this.readStatus(); | 
 |  |  |             log.info("RGV 工位2命令下发[id:{}] >>>>> {}", slave.getId(), JSON.toJSON(command)); | 
 |  |  |             OutputQueue.RGV.offer(MessageFormat.format("【{0}】[id:{1}] >>>>> 工位2命令下发: {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command))); | 
 |  |  |             return true; | 
 |  |  |         } else { | 
 |  |  |             OutputQueue.RGV.offer(MessageFormat.format("【{0}】写入RGV plc工位2数据失败 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort())); | 
 |  |  |             log.error("写入RGV plc工位2数据失败 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); | 
 |  |  |             return false; | 
 |  |  |         } | 
 |  |  |     } |