| | |
| | | private SteProtocol steProtocol; |
| | | private short heartBeatVal = 1; |
| | | private boolean resetFlag = false; |
| | | private int value = 0; |
| | | |
| | | |
| | | public SteThread(SteSlave slave) { |
| | | this.slave = slave; |
| | |
| | | // siemensS7Net.setRack(slave.getRack().byteValue()); |
| | | // siemensS7Net.setSlot(slave.getSlot().byteValue()); |
| | | OperateResult connect = siemensS7Net.ConnectServer(); |
| | | if(connect.IsSuccess){ |
| | | if (connect.IsSuccess) { |
| | | result = true; |
| | | OutputQueue.STE.offer(MessageFormat.format( "【{0}】穿梭车plc连接成功 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort())); |
| | | OutputQueue.STE.offer(MessageFormat.format("【{0}】穿梭车plc连接成功 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort())); |
| | | News.info("穿梭车plc连接成功 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); |
| | | } else { |
| | | OutputQueue.STE.offer(MessageFormat.format("【{0}】穿梭车plc连接失败!!! ===>> [id:{1}] [ip:{2}] [port:{3}] ", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort())); |
| | |
| | | /** |
| | | * 读取状态 |
| | | */ |
| | | private synchronized void readStatus(){ |
| | | private synchronized void readStatus() { |
| | | try { |
| | | OperateResultExOne<byte[]> result = siemensS7Net.Read("V800", (short) 70); |
| | | if (result.IsSuccess) { |
| | |
| | | steProtocol.setSteNo(slave.getId().shortValue()); |
| | | } |
| | | // steProtocol.setSteNo(siemensS7Net.getByteTransform().TransInt16(result.Content, 0)); |
| | | steProtocol.setMode(siemensS7Net.getByteTransform().TransInt16(result.Content, 2)); |
| | | short i = siemensS7Net.getByteTransform().TransInt16(result.Content, 2); |
| | | if (i == 0) { |
| | | value++; |
| | | } else { |
| | | value = 0; |
| | | } |
| | | if (value > 20) { |
| | | steProtocol.setMode((short) 0); |
| | | } else { |
| | | if (steProtocol.getMode() != null) { |
| | | steProtocol.setMode(steProtocol.getMode()); |
| | | } else { |
| | | steProtocol.setMode((short) 1); |
| | | } |
| | | } |
| | | steProtocol.setStatus(siemensS7Net.getByteTransform().TransInt16(result.Content, 4)); |
| | | OperateResultExOne<Boolean> executeRes = siemensS7Net.ReadBool("V2001.0"); |
| | | if (executeRes.IsSuccess) { |
| | |
| | | steProtocol.setCrnAllowRun(siemensS7Net.getByteTransform().TransInt16(result.Content, 42)); |
| | | steProtocol.setChargeStatus(siemensS7Net.getByteTransform().TransInt16(result.Content, 44)); |
| | | |
| | | OutputQueue.STE.offer(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功",DateUtils.convert(new Date()), slave.getId())); |
| | | OutputQueue.STE.offer(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功", DateUtils.convert(new Date()), slave.getId())); |
| | | |
| | | // 复位信号 |
| | | if (steProtocol.getWaiting()) { |
| | | News.info("-------------第一步、[穿梭车号:{}, 工作号:{}]==>> 状态为{},等待WCS确认!!{}", |
| | | slave.getId(),steProtocol.getTaskNo(),steProtocol.getStatus(), resetFlag); |
| | | slave.getId(), steProtocol.getTaskNo(), steProtocol.getStatus(), resetFlag); |
| | | if (resetFlag) { |
| | | SteCommand steCommand = new SteCommand(); |
| | | steCommand.setComplete(true); |
| | | if (write(steCommand) && confirmPos()) { |
| | | resetFlag = false; |
| | | News.info("第二步、发送复位命令成功 resetFlag = false,[穿梭车号:{}, 工作号:{}]==>> 状态为{},等待WCS确认!!{}", |
| | | slave.getId(),steProtocol.getTaskNo(),steProtocol.getStatus(), resetFlag); |
| | | slave.getId(), steProtocol.getTaskNo(), steProtocol.getStatus(), resetFlag); |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | BasSte basSte = new BasSte(); |
| | | basSte.setSteNo(slave.getId()); |
| | | if (!service.updateById(steProtocol.toSqlModel(basSte))){ |
| | | if (!service.updateById(steProtocol.toSqlModel(basSte))) { |
| | | News.error("穿梭车plc数据库更新失败 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); |
| | | } |
| | | |
| | | } |
| | | } else { |
| | | OutputQueue.STE.offer(MessageFormat.format("【{0}】{1}穿梭车plc状态信息失败",DateUtils.convert(new Date()), slave.getId())); |
| | | throw new CoolException(MessageFormat.format( "穿梭车plc状态信息失败 ===>> [id:{0}] [ip:{1}] [port:{2}]", slave.getId(), slave.getIp(), slave.getPort())); |
| | | OutputQueue.STE.offer(MessageFormat.format("【{0}】{1}穿梭车plc状态信息失败", DateUtils.convert(new Date()), slave.getId())); |
| | | throw new CoolException(MessageFormat.format("穿梭车plc状态信息失败 ===>> [id:{0}] [ip:{1}] [port:{2}]", slave.getId(), slave.getIp(), slave.getPort())); |
| | | } |
| | | } catch (Exception e) { |
| | | // e.printStackTrace(); |
| | |
| | | /** |
| | | * 写入数据 |
| | | */ |
| | | private synchronized boolean write(SteCommand command){ |
| | | private synchronized boolean write(SteCommand command) { |
| | | if (null == command) { |
| | | News.error("穿梭车写入命令为空"); |
| | | return false; |
| | |
| | | result = siemensS7Net.Write("V2000.0", true); |
| | | } |
| | | |
| | | // 其他指令 |
| | | // 其他指令 |
| | | } else { |
| | | // 控制模式 |
| | | if (command.getControlMode() != null) { |
| | | result = siemensS7Net.Write("V1010", command.getControlMode()); |
| | | // 复位信号 |
| | | result = siemensS7Net.Write("V1010", command.getControlMode()); |
| | | // 复位信号 |
| | | } else if (command.getReset() != null) { |
| | | result = siemensS7Net.Write("V2000.2", command.getReset()); |
| | | // 删除指令 |
| | | result = siemensS7Net.Write("V2000.2", command.getReset()); |
| | | // 删除指令 |
| | | } else if (command.getDelete() != null) { |
| | | result = siemensS7Net.Write("V2000.3", command.getDelete()); |
| | | // 无效指令 |
| | | } else if (command.getRun() != null) { |
| | | result = siemensS7Net.Write("V1016", command.getRun()); |
| | | result = siemensS7Net.Write("V2000.3", command.getDelete()); |
| | | // 无效指令 |
| | | }else { |
| | | } else if (command.getRun() != null) { |
| | | result = siemensS7Net.Write("V1016", command.getRun()); |
| | | // 无效指令 |
| | | } else { |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | // 任务完成 |
| | | // 任务完成 |
| | | } else { |
| | | News.info("收到穿梭板确认信号后准备给复位标记,穿梭板ID={}, 任务号={}, 穿梭板状态={}",slave.getId(), steProtocol.getTaskNo(),steProtocol.getStatus()); |
| | | News.info("收到穿梭板确认信号后准备给复位标记,穿梭板ID={}, 任务号={}, 穿梭板状态={}", slave.getId(), steProtocol.getTaskNo(), steProtocol.getStatus()); |
| | | siemensS7Net.Write("V998", (short) 0); |
| | | siemensS7Net.Write("V1000", (short) 0); |
| | | siemensS7Net.Write("V2000.0", false); |
| | |
| | | } |
| | | } |
| | | |
| | | } catch (Exception ignore) {} |
| | | } catch (Exception ignore) { |
| | | } |
| | | |
| | | if (result != null && result.IsSuccess) { |
| | | // 维护数据库排列层 |
| | |
| | | |
| | | try { |
| | | Thread.sleep(500); |
| | | } catch (Exception e){ |
| | | } catch (Exception e) { |
| | | |
| | | } |
| | | OperateResultExOne<byte[]> result1 = siemensS7Net.Read("V998", (short) 4); |
| | |
| | | short taskNo = siemensS7Net.getByteTransform().TransInt16(result1.Content, 0); |
| | | short taskType = siemensS7Net.getByteTransform().TransInt16(result1.Content, 2); |
| | | // readStatus(); |
| | | News.info("穿梭板任务下发成功后休眠200ms立即回读写入数据,穿梭板ID={}, 任务号={}, 作业类型={}",slave.getId(), taskNo, taskType); |
| | | News.info("穿梭板任务下发成功后休眠200ms立即回读穿梭板状态,穿梭板ID={}, 任务号={}, 穿梭板状态={}",slave.getId(), steProtocol.getTaskNo(),steProtocol.getStatus()); |
| | | News.info("穿梭板任务下发成功后休眠200ms立即回读写入数据,穿梭板ID={}, 任务号={}, 作业类型={}", slave.getId(), taskNo, taskType); |
| | | News.info("穿梭板任务下发成功后休眠200ms立即回读穿梭板状态,穿梭板ID={}, 任务号={}, 穿梭板状态={}", slave.getId(), steProtocol.getTaskNo(), steProtocol.getStatus()); |
| | | } |
| | | resetFlag = false; |
| | | return true; |
| | |
| | | BasSte basSte = service.selectById(slave.getId()); |
| | | if (basSte != null) { |
| | | // 更新plc数据块 |
| | | short[] arr = new short[] {basSte.getRow().shortValue(), basSte.getBay().shortValue(), basSte.getLev().shortValue()}; |
| | | short[] arr = new short[]{basSte.getRow().shortValue(), basSte.getBay().shortValue(), basSte.getLev().shortValue()}; |
| | | OperateResult result = siemensS7Net.Write("V1002", arr); |
| | | if (result.IsSuccess) { |
| | | // 更新数据库 |
| | |
| | | } |
| | | |
| | | public boolean modifyPosHandle(Integer row, Integer bay, Integer lev) { |
| | | short[] arr = new short[] {row.shortValue(), bay.shortValue(), lev.shortValue()}; |
| | | short[] arr = new short[]{row.shortValue(), bay.shortValue(), lev.shortValue()}; |
| | | OperateResult result = siemensS7Net.Write("V1002", arr); |
| | | if (!result.IsSuccess) { |
| | | News.error("更新{}号穿梭车定位失败 ===>> 排:【{}】, 列:【{}】,层:【{}】", this.slave.getId(), row, bay, lev); |
| | |
| | | /** |
| | | * 心跳 |
| | | */ |
| | | private void heartbeat(){ |
| | | private void heartbeat() { |
| | | if (heartBeatVal == 1) { |
| | | heartBeatVal = 2; |
| | | } else { |
| | |
| | | |
| | | // 穿梭车运行禁止 |
| | | SteCommand command = new SteCommand(); |
| | | command.setRun((short)0); |
| | | command.setRun((short) 0); |
| | | thread.write(command); |
| | | |
| | | } |