| | |
| | | command.setTaskNo((short) 0); // 工作号 |
| | | command.setAckFinish((short) 1); // 任务完成确认位 |
| | | command.setTaskMode(CrnTaskModeType.NONE); // 任务模式 |
| | | command.setSourcePosX((short)0); // 源库位排 |
| | | command.setSourcePosY((short)0); // 源库位列 |
| | | command.setSourcePosZ((short)0); // 源库位层 |
| | | command.setDestinationPosX((short)0); // 目标库位排 |
| | | command.setDestinationPosY((short)0); // 目标库位列 |
| | | command.setDestinationPosZ((short)0); // 目标库位层 |
| | | command.setSourcePosX((short) 0); // 源库位排 |
| | | command.setSourcePosY((short) 0); // 源库位列 |
| | | command.setSourcePosZ((short) 0); // 源库位层 |
| | | command.setDestinationPosX((short) 0); // 目标库位排 |
| | | command.setDestinationPosY((short) 0); // 目标库位列 |
| | | command.setDestinationPosZ((short) 0); // 目标库位层 |
| | | write(command); |
| | | break; |
| | | default: |
| | |
| | | } |
| | | crnProtocol.setMode((short) -1); |
| | | // crnProtocol.setTaskNo((short)0); |
| | | crnProtocol.setStatus((short)-1); |
| | | crnProtocol.setBay((short)0); |
| | | crnProtocol.setLevel((short)0); |
| | | crnProtocol.setStatus((short) -1); |
| | | crnProtocol.setBay((short) 0); |
| | | crnProtocol.setLevel((short) 0); |
| | | crnProtocol.setForkPos((short) -1); |
| | | crnProtocol.setLiftPos((short) -1); |
| | | crnProtocol.setWalkPos((short)0); |
| | | crnProtocol.setLoaded((short)0); |
| | | crnProtocol.setAlarm((short)0); |
| | | crnProtocol.setWalkPos((short) 0); |
| | | crnProtocol.setLoaded((short) 0); |
| | | crnProtocol.setAlarm((short) 0); |
| | | crnProtocol.setxSpeed((short) 0); |
| | | crnProtocol.setySpeed((short) 0); |
| | | crnProtocol.setzSpeed((short) 0); |
| | |
| | | siemensNet.setRack(slave.getRack().byteValue()); |
| | | siemensNet.setSlot(slave.getSlot().byteValue()); |
| | | OperateResult connect = siemensNet.ConnectServer(); |
| | | if(connect.IsSuccess){ |
| | | if (connect.IsSuccess) { |
| | | result = true; |
| | | 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())); |
| | | News.info("SiemensCrn"+" - 1"+" - 堆垛机plc连接成功 ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot()); |
| | | 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())); |
| | | News.info("SiemensCrn" + " - 1" + " - 堆垛机plc连接成功 ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot()); |
| | | } 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())); |
| | | News.error("SiemensCrn"+" - 2"+" - 堆垛机plc连接失败!!! ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot()); |
| | | News.error("SiemensCrn" + " - 2" + " - 堆垛机plc连接失败!!! ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot()); |
| | | initCrn(); |
| | | } |
| | | // siemensNet.ConnectClose(); |
| | |
| | | /** |
| | | * 读取状态 |
| | | */ |
| | | private void readStatus(){ |
| | | private void readStatus() { |
| | | try { |
| | | OperateResultExOne<byte[]> result = siemensNet.Read("DB101.0", (short) 66); |
| | | if (result.IsSuccess) { |
| | |
| | | crnProtocol.setyDuration(siemensNet.getByteTransform().TransInt16(result.Content, 62)); |
| | | |
| | | |
| | | OutputQueue.CRN.offer(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功",DateUtils.convert(new Date()), slave.getId())); |
| | | OutputQueue.CRN.offer(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功", DateUtils.convert(new Date()), slave.getId())); |
| | | |
| | | // 复位信号 |
| | | if (!Cools.isEmpty(crnProtocol.getStatusType()) && crnProtocol.getStatusType().equals(CrnStatusType.WAITING)) { |
| | | if (resetFlag) { |
| | | if(crnProtocol.getTaskNo()==9999){ |
| | | if (crnProtocol.getTaskNo() == 9999) { |
| | | backHpFlag = false; |
| | | } |
| | | CrnCommand crnCommand = new CrnCommand(); |
| | | crnCommand.setAckFinish((short)1); |
| | | crnCommand.setAckFinish((short) 1); |
| | | if (write(crnCommand)) { |
| | | resetFlag = false; |
| | | } |
| | |
| | | BasCrnpService basCrnpService = SpringUtils.getBean(BasCrnpService.class); |
| | | BasCrnp basCrnp = new BasCrnp(); |
| | | basCrnp.setCrnNo(slave.getId()); |
| | | basCrnp.setCrnSts((int)crnProtocol.getMode()); |
| | | if (!basCrnpService.updateById(crnProtocol.toSqlModel(basCrnp))){ |
| | | News.error("SiemensCrn"+" - 3"+" - 堆垛机plc数据库更新失败 ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot()); |
| | | basCrnp.setCrnSts((int) crnProtocol.getMode()); |
| | | if (!basCrnpService.updateById(crnProtocol.toSqlModel(basCrnp))) { |
| | | News.error("SiemensCrn" + " - 3" + " - 堆垛机plc数据库更新失败 ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot()); |
| | | } |
| | | } catch (Exception ignore){} |
| | | } catch (Exception ignore) { |
| | | } |
| | | |
| | | } else { |
| | | initCrn(); |
| | | 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())); |
| | | News.error("SiemensCrn"+" - 4"+" - 读取堆垛机plc状态信息失败 ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot()); |
| | | News.error("SiemensCrn" + " - 4" + " - 读取堆垛机plc状态信息失败 ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot()); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | 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("SiemensCrn"+" - 5"+" - 读取堆垛机plc状态信息失败 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); |
| | | News.error("SiemensCrn" + " - 5" + " - 读取堆垛机plc状态信息失败 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); |
| | | initCrn(); |
| | | } |
| | | } |
| | |
| | | */ |
| | | private boolean write(CrnCommand command) throws InterruptedException { |
| | | if (null == command) { |
| | | News.error("SiemensCrn"+" - 6"+" - 堆垛机写入命令为空"); |
| | | News.error("SiemensCrn" + " - 6" + " - 堆垛机写入命令为空"); |
| | | return false; |
| | | } |
| | | command.setCommand((short) 1); |
| | | System.out.println("------------------"); |
| | | System.out.println(command); |
| | | // convertRow(command); |
| | |
| | | array[11] = command.getDestinationPosXTwo(); |
| | | array[12] = command.getDestinationPosYTwo(); |
| | | array[13] = command.getDestinationPosZTwo(); |
| | | //array[14] = command.getCommand(); |
| | | array[14] = 1; |
| | | array[14] = command.getCommand(); |
| | | array[15] = command.getAckFinish(); |
| | | |
| | | // array[9] = command.getSourceStaNo(); |
| | |
| | | Thread.sleep(200); |
| | | int writeCount = 1; |
| | | do { |
| | | try{ |
| | | if(!result.IsSuccess){ |
| | | log.error("写入堆垛机plc数据失败,重新下发任务 写入直接失败 ===>> [id:{}],{},[写入次数:{}]", slave.getId(), JSON.toJSONString(command),writeCount); |
| | | try { |
| | | if (!result.IsSuccess) { |
| | | log.error("写入堆垛机plc数据失败,重新下发任务 写入直接失败 ===>> [id:{}],{},[写入次数:{}]", slave.getId(), JSON.toJSONString(command), writeCount); |
| | | result = siemensNet.Write("DB100.0", array); |
| | | Thread.sleep(100); |
| | | writeCount++; |
| | |
| | | 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.setSourcePosXTwo(siemensNet.getByteTransform().TransInt16(resultRead.Content, 18)); |
| | | one.setSourcePosYTwo(siemensNet.getByteTransform().TransInt16(resultRead.Content, 20)); |
| | | one.setSourcePosZTwo(siemensNet.getByteTransform().TransInt16(resultRead.Content, 22)); |
| | | one.setDestinationPosXTwo(siemensNet.getByteTransform().TransInt16(resultRead.Content, 24)); |
| | | one.setDestinationPosYTwo(siemensNet.getByteTransform().TransInt16(resultRead.Content, 26)); |
| | | one.setDestinationPosZTwo(siemensNet.getByteTransform().TransInt16(resultRead.Content, 28)); |
| | | one.setDestinationPosY(siemensNet.getByteTransform().TransInt16(resultRead.Content, 30)); |
| | | 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()) |
| | | ){ |
| | | try{ |
| | | log.error("堆垛机命令地址写入后回读失败==>不一致[id:{}] >>>>> 写入[{}],===>>回读[{}]", slave.getId(), JSON.toJSONString(command),JSON.toJSONString(one)); |
| | | }catch (Exception e){ |
| | | try{ |
| | | log.error("日志打印失败:===>>参数one报错 [id:{}],{}", slave.getId(), JSON.toJSONString(command),JSON.toJSONString(resultRead)); |
| | | }catch (Exception e1){ |
| | | || !command.getSourcePosXTwo().equals(one.getSourcePosXTwo()) || !command.getSourcePosYTwo().equals(one.getSourcePosYTwo()) |
| | | || !command.getSourcePosZTwo().equals(one.getSourcePosZTwo()) || !command.getDestinationPosXTwo().equals(one.getDestinationPosXTwo()) |
| | | || !command.getDestinationPosYTwo().equals(one.getDestinationPosYTwo()) || !command.getDestinationPosZTwo().equals(one.getDestinationPosZTwo()) |
| | | ) { |
| | | try { |
| | | log.error("堆垛机命令地址写入后回读失败==>不一致[id:{}] >>>>> 写入[{}],===>>回读[{}]", slave.getId(), JSON.toJSONString(command), JSON.toJSONString(one)); |
| | | } catch (Exception e) { |
| | | try { |
| | | log.error("日志打印失败:===>>参数one报错 [id:{}],{}", slave.getId(), JSON.toJSONString(command), JSON.toJSONString(resultRead)); |
| | | } catch (Exception e1) { |
| | | log.error("日志打印失败:===>> [id:{}],{}", slave.getId(), JSON.toJSONString(command)); |
| | | } |
| | | } |
| | | try{ |
| | | try { |
| | | Thread.sleep(100); |
| | | }catch (Exception e){ |
| | | } catch (Exception e) { |
| | | |
| | | } |
| | | log.error("写入堆垛机plc数据失败,重新下发任务 回读不一致 ===>> [id:{}],{},[写入次数:{}]", slave.getId(), JSON.toJSONString(command),writeCount); |
| | | log.error("写入堆垛机plc数据失败,重新下发任务 回读不一致 ===>> [id:{}],{},[写入次数:{}]", slave.getId(), JSON.toJSONString(command), writeCount); |
| | | result = siemensNet.Write("DB100.0", array); |
| | | writeCount++; |
| | | continue; |
| | | } else { |
| | | log.info("堆垛机命令地址写入后回读成功[id:{}] >>>>> 写入[{}],===>>回读[{}]", slave.getId(), JSON.toJSONString(command),JSON.toJSONString(one)); |
| | | log.info("堆垛机命令地址写入后回读成功[id:{}] >>>>> 写入[{}],===>>回读[{}]", slave.getId(), JSON.toJSONString(command), JSON.toJSONString(one)); |
| | | break; |
| | | } |
| | | } |
| | | }catch (Exception e){ |
| | | log.error("堆垛机命令地址写入后回读出错,异常:"+e); |
| | | } catch (Exception e) { |
| | | log.error("堆垛机命令地址写入后回读出错,异常:" + e); |
| | | } |
| | | writeCount++; |
| | | } while (writeCount<6); |
| | | } while (writeCount < 6); |
| | | |
| | | if (command.getAckFinish() == 0) { |
| | | short commandFinish = 1; |
| | | Thread.sleep(100L); |
| | | result = siemensNet.Write("DB100.30", commandFinish); |
| | | int signFinish = 1; |
| | | while (signFinish<5){ |
| | | while (signFinish < 5) { |
| | | OperateResultExOne<byte[]> result10018 = siemensNet.Read("DB100.30", (short) 2); |
| | | short transInt16 = siemensNet.getByteTransform().TransInt16(result10018.Content, 0); |
| | | if (transInt16 != commandFinish){ |
| | | log.info("下发DB100.30 回读失败" + "commandFinish:"+commandFinish); |
| | | log.info("下发DB100.30 回读失败" + "array:"+ JSON.toJSONString(array)); |
| | | if (transInt16 != commandFinish) { |
| | | log.info("下发DB100.30 回读失败" + "commandFinish:" + commandFinish); |
| | | log.info("下发DB100.30 回读失败" + "array:" + JSON.toJSONString(array)); |
| | | result = siemensNet.Write("DB100.18", commandFinish); |
| | | signFinish++; |
| | | }else { |
| | | log.info("下发DB100.30" + "commandFinish:"+commandFinish); |
| | | log.info("下发DB100.30" + "array:"+ JSON.toJSONString(array)); |
| | | } else { |
| | | log.info("下发DB100.30" + "commandFinish:" + commandFinish); |
| | | log.info("下发DB100.30" + "array:" + JSON.toJSONString(array)); |
| | | break; |
| | | } |
| | | } |
| | |
| | | null // 修改人员 |
| | | ); |
| | | bean.save(basCrnOpt); |
| | | } catch (Exception ignore) {} |
| | | } catch (Exception ignore) { |
| | | } |
| | | |
| | | if (result != null && result.IsSuccess) { |
| | | Thread.sleep(200); |
| | | this.readStatus(); |
| | | News.info("SiemensCrn"+" - 7"+" - 堆垛机命令下发[id:{}] >>>>> {}", slave.getId(), JSON.toJSON(command)); |
| | | News.info("SiemensCrn" + " - 7" + " - 堆垛机命令下发[id:{}] >>>>> {}", slave.getId(), 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}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort())); |
| | | News.error("SiemensCrn"+" - 8"+" - 写入堆垛机plc数据失败 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); |
| | | News.error("SiemensCrn" + " - 8" + " - 写入堆垛机plc数据失败 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); |
| | | return false; |
| | | } |
| | | } |