| | |
| | | crnProtocol.setWalkPos((short) 0); |
| | | crnProtocol.setLoaded((short) 0); |
| | | crnProtocol.setAlarm((short) 0); |
| | | crnProtocol.setxSpeed((short) 0); |
| | | crnProtocol.setySpeed((short) 0); |
| | | crnProtocol.setzSpeed((short) 0); |
| | | crnProtocol.setxDistance((short) 0); |
| | | crnProtocol.setyDistance((short) 0); |
| | | crnProtocol.setxDuration((short) 0); |
| | | crnProtocol.setyDuration((short) 0); |
| | | crnProtocol.setxSpeed((float) 0); |
| | | crnProtocol.setySpeed((float) 0); |
| | | crnProtocol.setzSpeed((float) 0); |
| | | crnProtocol.setxDistance((float) 0); |
| | | crnProtocol.setyDistance((float) 0); |
| | | crnProtocol.setxDuration((float) 0); |
| | | crnProtocol.setyDuration((float) 0); |
| | | } |
| | | |
| | | @Override |
| | |
| | | */ |
| | | private void readStatus() { |
| | | try { |
| | | OperateResultExOne<byte[]> result = siemensNet.Read("DB101.0", (short) 56); |
| | | OperateResultExOne<byte[]> result = siemensNet.Read("DB101.0", (short) 66); |
| | | if (result.IsSuccess) { |
| | | if (null == crnProtocol) { |
| | | crnProtocol = new CrnProtocol(); |
| | |
| | | crnProtocol.setAlarm(siemensNet.getByteTransform().TransInt16(result.Content, 32)); |
| | | |
| | | |
| | | |
| | | //crnProtocol.setTemp1(siemensNet.getByteTransform().TransInt16(result.Content, 20)); |
| | | //crnProtocol.setTemp2(siemensNet.getByteTransform().TransInt16(result.Content, 22)); |
| | | //crnProtocol.setTemp3(siemensNet.getByteTransform().TransInt16(result.Content, 24)); |
| | | //crnProtocol.setTemp4(siemensNet.getByteTransform().TransInt16(result.Content, 26)); |
| | | crnProtocol.setxSpeed(siemensNet.getByteTransform().TransInt16(result.Content, 34)); |
| | | crnProtocol.setySpeed(siemensNet.getByteTransform().TransInt16(result.Content, 38)); |
| | | crnProtocol.setzSpeed(siemensNet.getByteTransform().TransInt16(result.Content, 42)); |
| | | crnProtocol.setxDistance(siemensNet.getByteTransform().TransInt16(result.Content, 46)); |
| | | crnProtocol.setyDistance(siemensNet.getByteTransform().TransInt16(result.Content, 50)); |
| | | crnProtocol.setxDuration(siemensNet.getByteTransform().TransInt16(result.Content, 54)); |
| | | crnProtocol.setyDuration(siemensNet.getByteTransform().TransInt16(result.Content, 58)); |
| | | crnProtocol.setxSpeed((float) siemensNet.getByteTransform().TransInt16(result.Content, 34)); |
| | | crnProtocol.setySpeed((float) siemensNet.getByteTransform().TransInt16(result.Content, 38)); |
| | | crnProtocol.setzSpeed((float) siemensNet.getByteTransform().TransInt16(result.Content, 42)); |
| | | crnProtocol.setxDistance((float) siemensNet.getByteTransform().TransInt16(result.Content, 50) / 10000); |
| | | crnProtocol.setyDistance((float) siemensNet.getByteTransform().TransInt16(result.Content, 54) / 10000); |
| | | crnProtocol.setxDuration((float) siemensNet.getByteTransform().TransInt16(result.Content, 58) / 10000); |
| | | crnProtocol.setyDuration((float) siemensNet.getByteTransform().TransInt16(result.Content, 62) / 10000); |
| | | |
| | | //2工位 |
| | | crnProtocol.setTaskNoTwo(siemensNet.getByteTransform().TransInt16(result.Content, 14)); |
| | |
| | | |
| | | // 复位信号 |
| | | if (!Cools.isEmpty(crnProtocol.getStatusType()) && crnProtocol.getStatusType().equals(CrnStatusType.WAITING)) { |
| | | News.error("---第一步、[堆垛机号:{}, 工作号:{}, 载货台信号:{}]==>> 状态为10,等待确认!!", |
| | | // if (crnProtocol.getTaskNo() == 0){ |
| | | // News.error("堆垛机工位1工作号为0,不予确认,工位1{}",crnProtocol.getLoaded() == 1 ? "有物" : "无物"); |
| | | // return; |
| | | // } |
| | | News.error("---第一步、[堆垛机号:{}, 工作号:{}, 载货台1信号:{}]==>> 状态为10,等待确认!!", |
| | | slave.getId(), crnProtocol.getTaskNo(), crnProtocol.getLoaded() == 1 ? "有物" : "无物"); |
| | | if (resetFlag) { |
| | | if (crnProtocol.getTaskNo() == 9999) { |
| | |
| | | crnCommand.setAckFinish((short) 1); |
| | | if (write(crnCommand)) { |
| | | resetFlag = false; |
| | | News.error("---第二步、[堆垛机号:{}, 工作号:{}]==>> 复位resetFlag标记成功{}!!", |
| | | News.error("---第二步、[堆垛机号:{}, 工作号:{}]==>> 工位1复位resetFlag标记成功{}!!", |
| | | slave.getId(), wrkNo, resetFlag); |
| | | } |
| | | } |
| | |
| | | |
| | | // 复位信号 |
| | | if (!Cools.isEmpty(crnProtocol.getStatusType()) && crnProtocol.getStatusTypeTwo().equals(CrnStatusType.WAITING)) { |
| | | News.error("---第一步、[堆垛机号:{}, 工作号:{}, 载货台信号:{}]==>> 状态为10,等待确认!!", |
| | | slave.getId(), crnProtocol.getTaskNo(), crnProtocol.getLoaded() == 1 ? "有物" : "无物"); |
| | | // if (crnProtocol.getTaskNoTwo() == 0){ |
| | | // News.error("堆垛机工位2工作号为0,不予确认,工位2{}",crnProtocol.getLoadedTwo() == 1 ? "有物" : "无物"); |
| | | // return; |
| | | // } |
| | | News.error("---第一步、[堆垛机号:{}, 工作号:{}, 载货台2信号:{}]==>> 状态为10,等待确认!!", |
| | | slave.getId(), crnProtocol.getTaskNoTwo(), crnProtocol.getLoadedTwo() == 1 ? "有物" : "无物"); |
| | | if (resetFlagTwo) { |
| | | if (crnProtocol.getTaskNo() == 9999) { |
| | | backHpFlag = false; |
| | |
| | | crnCommand.setAckFinish((short) 1); |
| | | if (write2(crnCommand)) { |
| | | resetFlagTwo = false; |
| | | News.error("---第二步、[堆垛机号:{}, 工作号:{}]==>> 复位resetFlag标记成功{}!!", |
| | | News.error("---第二步、[堆垛机号:{}, 工作号:{}]==>> 工位2复位resetFlag标记成功{}!!", |
| | | slave.getId(), wrkNo, resetFlag); |
| | | } |
| | | } |
| | |
| | | */ |
| | | private boolean write(CrnCommand command) throws InterruptedException { |
| | | if (null == command) { |
| | | News.error("堆垛机写入命令为空"); |
| | | News.error("堆垛机工位1写入命令为空"); |
| | | return false; |
| | | } |
| | | // 向堆垛机发任务前的堆垛机状态 |
| | |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | News.error("堆垛机命令地址写入后回读出错"); |
| | | News.error("堆垛机工位1命令地址写入后回读出错"); |
| | | } |
| | | // convertRow(command); |
| | | command.setCrnNo(slave.getId()); |
| | | // short[] array = new short[10]; |
| | | short[] array = new short[9]; |
| | | short[] array = new short[10]; |
| | | array[0] = command.getAckFinish(); // 任务完成确认位 |
| | | array[1] = command.getTaskNo(); // 任务号 |
| | | array[2] = command.getTaskMode(); // 模式 |
| | |
| | | array[6] = command.getDestinationPosX(); // 目标位置排号 |
| | | array[7] = command.getDestinationPosY(); // 目标位置列号 |
| | | array[8] = command.getDestinationPosZ(); // 目标位置层号 |
| | | array[9] = command.getCommand(); |
| | | // array[10] = 0; //备用1 |
| | | |
| | | |
| | | OperateResult result = siemensNet.Write("DB100.0", array); |
| | | News.info("堆垛机命令下发[id:{}] >>>>> {}", slave.getId(), array); |
| | | News.info("堆垛机工位1命令下发[id:{}] >>>>> {}", slave.getId(), array); |
| | | |
| | | //堆垛机任务写入后,回读一次,看是否成功 |
| | | Thread.sleep(200); |
| | |
| | | try { |
| | | if (!result.IsSuccess) { |
| | | // if (!resetFlag){ |
| | | News.error("写入堆垛机plc数据失败,重新下发任务 写入直接失败 ===>> [id:{}],{},[写入次数:{}]", slave.getId(), JSON.toJSON(command), writeCount1); |
| | | News.error("写入堆垛机工位1plc数据失败,重新下发任务 写入直接失败 ===>> [id:{}],{},[写入次数:{}]", slave.getId(), JSON.toJSON(command), writeCount1); |
| | | result = siemensNet.Write("DB100.0", array); |
| | | |
| | | // } |
| | |
| | | || !command.getAckFinish().equals(one.getAckFinish()) |
| | | ) { |
| | | try { |
| | | News.error("堆垛机命令地址写入后回读失败==>不一致[id:{}] >>>>> 写入[{}],===>>回读[{}]", slave.getId(), JSON.toJSON(command), JSON.toJSON(one)); |
| | | News.error("堆垛机工位1命令地址写入后回读失败==>不一致[id:{}] >>>>> 写入[{}],===>>回读[{}]", slave.getId(), JSON.toJSON(command), JSON.toJSON(one)); |
| | | } catch (Exception e) { |
| | | try { |
| | | News.error("日志打印失败:===>>参数one报错 [id:{}],{}", slave.getId(), JSON.toJSON(command), JSON.toJSON(resultRead)); |
| | |
| | | |
| | | } |
| | | // if (!resetFlag){ |
| | | News.error("写入堆垛机plc数据失败,重新下发任务 回读不一致 ===>> [id:{}],{},[写入次数:{}]", slave.getId(), JSON.toJSON(command), writeCount1); |
| | | News.error("写入堆垛机工位1plc数据失败,重新下发任务 回读不一致 ===>> [id:{}],{},[写入次数:{}]", slave.getId(), JSON.toJSON(command), writeCount1); |
| | | result = siemensNet.Write("DB100.0", array); |
| | | // } |
| | | writeCount1++; |
| | | continue; |
| | | } else { |
| | | News.info("堆垛机命令地址写入后回读成功[id:{}] >>>>> 写入[{}],===>>回读[{}]", slave.getId(), JSON.toJSON(command), JSON.toJSON(one)); |
| | | News.info("堆垛机工位1命令地址写入后回读成功[id:{}] >>>>> 写入[{}],===>>回读[{}]", slave.getId(), JSON.toJSON(command), JSON.toJSON(one)); |
| | | break; |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | News.error("堆垛机命令地址写入后回读出错,异常:" + e); |
| | | News.error("堆垛机工位1命令地址写入后回读出错,异常:" + e); |
| | | } |
| | | writeCount1++; |
| | | } while (writeCount1 < 6); |
| | |
| | | if (resultRead.IsSuccess) { |
| | | commandFinish = siemensNet.getByteTransform().TransInt16(resultRead.Content, 0); |
| | | if (commandFinish != 1) { |
| | | News.error("堆垛机任务确认位" + commandFinish + "写入数据与回读数据不一致!" + "循环执行次数:" + writeCount2 + "次"); |
| | | News.error("堆垛机工位1任务确认位" + commandFinish + "写入数据与回读数据不一致!" + "循环执行次数:" + writeCount2 + "次"); |
| | | } else { |
| | | //任务命令写入成功 |
| | | News.info("堆垛机任务确认位" + commandFinish + "回读成功!" + "循环执行次数:" + writeCount2 + "次"); |
| | | News.info("堆垛机工位1任务确认位" + commandFinish + "回读成功!" + "循环执行次数:" + writeCount2 + "次"); |
| | | break; |
| | | } |
| | | } else { |
| | | News.error("堆垛机任务确认位" + commandFinish + "回读失败!" + "循环执行次数:" + writeCount2 + "次"); |
| | | News.error("堆垛机工位1任务确认位" + commandFinish + "回读失败!" + "循环执行次数:" + writeCount2 + "次"); |
| | | } |
| | | } else { |
| | | News.error("堆垛机任务确认位" + commandFinish + "写入失败!" + "循环执行次数:" + writeCount2 + "次"); |
| | | News.error("堆垛机工位1任务确认位" + commandFinish + "写入失败!" + "循环执行次数:" + writeCount2 + "次"); |
| | | } |
| | | } while (writeCount2 < 5); |
| | | } |
| | |
| | | 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}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort())); |
| | | News.error("写入堆垛机plc数据失败 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); |
| | | OutputQueue.CRN.offer(MessageFormat.format("【{0}】写入堆垛机工位1plc数据失败 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort())); |
| | | News.error("写入堆垛机工位1plc数据失败 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); |
| | | return false; |
| | | } |
| | | } |
| | |
| | | */ |
| | | private boolean write2(CrnCommand command) throws InterruptedException { |
| | | if (null == command) { |
| | | News.error("堆垛机写入命令为空"); |
| | | News.error("堆垛机工位2写入命令为空"); |
| | | return false; |
| | | } |
| | | // 向堆垛机发任务前的堆垛机状态 |
| | | try { |
| | | OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB100.20", (short) 18); |
| | | OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB100.20", (short) 20); |
| | | if (resultRead.IsSuccess) { |
| | | CrnCommand one = new CrnCommand(); |
| | | one.setTaskNo(siemensNet.getByteTransform().TransInt16(resultRead.Content, 2)); |
| | |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | News.error("堆垛机命令地址写入后回读出错"); |
| | | News.error("堆垛机工位2命令地址写入后回读出错"); |
| | | } |
| | | // convertRow(command); |
| | | command.setCrnNo(slave.getId()); |
| | |
| | | array2[0] = command.getAckFinish(); |
| | | OperateResult result = siemensNet.Write("DB100.20", array); |
| | | OperateResult result2 = siemensNet.Write("DB100.0", array2); |
| | | News.info("堆垛机命令下发[id:{}] >>>>> {}", slave.getId(), array); |
| | | News.info("堆垛机工位2命令下发[id:{}] >>>>> {}", slave.getId(), array); |
| | | |
| | | int writeCount1 = 1; |
| | | do { |
| | | try { |
| | | if (!result.IsSuccess || !result2.IsSuccess) { |
| | | // if (!resetFlag){ |
| | | News.error("写入堆垛机plc数据失败,重新下发任务 写入直接失败 ===>> [id:{}],{},[写入次数:{}]", slave.getId(), JSON.toJSON(command), writeCount1); |
| | | News.error("写入堆垛机工位2plc数据失败,重新下发任务 写入直接失败 ===>> [id:{}],{},[写入次数:{}]", slave.getId(), JSON.toJSON(command), writeCount1); |
| | | result = siemensNet.Write("DB100.0", array); |
| | | // } |
| | | Thread.sleep(100); |
| | | writeCount1++; |
| | | continue; |
| | | } |
| | | OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB100.20", (short) 18); |
| | | OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB100.0", (short) 36); |
| | | if (resultRead.IsSuccess) { |
| | | CrnCommand one = new CrnCommand(); |
| | | one.setAckFinish(siemensNet.getByteTransform().TransInt16(resultRead.Content, 0)); |
| | |
| | | || !command.getAckFinish().equals(one.getAckFinish()) |
| | | ) { |
| | | try { |
| | | News.error("堆垛机命令地址写入后回读失败==>不一致[id:{}] >>>>> 写入[{}],===>>回读[{}]", slave.getId(), JSON.toJSON(command), JSON.toJSON(one)); |
| | | News.error("堆垛机工位2命令地址写入后回读失败==>不一致[id:{}] >>>>> 写入[{}],===>>回读[{}]", slave.getId(), JSON.toJSON(command), JSON.toJSON(one)); |
| | | } catch (Exception e) { |
| | | try { |
| | | News.error("日志打印失败:===>>参数one报错 [id:{}],{}", slave.getId(), JSON.toJSON(command), JSON.toJSON(resultRead)); |
| | |
| | | |
| | | } |
| | | // if (!resetFlag){ |
| | | News.error("写入堆垛机plc数据失败,重新下发任务 回读不一致 ===>> [id:{}],{},[写入次数:{}]", slave.getId(), JSON.toJSON(command), writeCount1); |
| | | News.error("写入堆垛机工位2plc数据失败,重新下发任务 回读不一致 ===>> [id:{}],{},[写入次数:{}]", slave.getId(), JSON.toJSON(command), writeCount1); |
| | | result = siemensNet.Write("DB100.0", array); |
| | | // } |
| | | writeCount1++; |
| | | continue; |
| | | } else { |
| | | News.info("堆垛机命令地址写入后回读成功[id:{}] >>>>> 写入[{}],===>>回读[{}]", slave.getId(), JSON.toJSON(command), JSON.toJSON(one)); |
| | | News.info("堆垛机工位2命令地址写入后回读成功[id:{}] >>>>> 写入[{}],===>>回读[{}]", slave.getId(), JSON.toJSON(command), JSON.toJSON(one)); |
| | | break; |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | News.error("堆垛机命令地址写入后回读出错,异常:" + e); |
| | | News.error("堆垛机工位2命令地址写入后回读出错2,异常:" + e); |
| | | } |
| | | writeCount1++; |
| | | } while (writeCount1 < 6); |
| | |
| | | if (resultRead.IsSuccess) { |
| | | commandFinish = siemensNet.getByteTransform().TransInt16(resultRead.Content, 0); |
| | | if (commandFinish != 1) { |
| | | News.error("堆垛机任务确认位" + commandFinish + "写入数据与回读数据不一致!" + "循环执行次数:" + writeCount2 + "次"); |
| | | News.error("堆垛机工位2任务确认位" + commandFinish + "写入数据与回读数据不一致!" + "循环执行次数:" + writeCount2 + "次"); |
| | | } else { |
| | | //任务命令写入成功 |
| | | // News.info("堆垛机任务确认位"+commandFinish+"回读成功!"+"循环执行次数:"+writeCount2+"次"); |
| | | break; |
| | | } |
| | | } else { |
| | | News.error("堆垛机任务确认位" + commandFinish + "回读失败!" + "循环执行次数:" + writeCount2 + "次"); |
| | | News.error("堆垛机工位2任务确认位" + commandFinish + "回读失败!" + "循环执行次数:" + writeCount2 + "次"); |
| | | } |
| | | } else { |
| | | News.error("堆垛机任务确认位" + commandFinish + "写入失败!" + "循环执行次数:" + writeCount2 + "次"); |
| | | News.error("堆垛机工位2任务确认位" + commandFinish + "写入失败!" + "循环执行次数:" + writeCount2 + "次"); |
| | | } |
| | | } while (writeCount2 < 5); |
| | | } |
| | |
| | | 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())); |
| | | News.error("写入堆垛机plc数据失败 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); |
| | | News.error("写入堆垛机工位2plc数据失败 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); |
| | | return false; |
| | | } |
| | | } |