| | |
| | | import com.core.common.SpringUtils; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.entity.BasSte; |
| | | import com.zy.asrs.service.BasSteOptService; |
| | | import com.zy.asrs.service.BasSteService; |
| | | import com.zy.core.ThreadHandler; |
| | | import com.zy.core.cache.MessageQueue; |
| | | import com.zy.core.cache.OutputQueue; |
| | | import com.zy.core.enums.SlaveType; |
| | | import com.zy.core.enums.SteStatusType; |
| | | import com.zy.core.model.SteSlave; |
| | | import com.zy.core.model.Task; |
| | | import com.zy.core.model.command.SteCommand; |
| | |
| | | break; |
| | | } |
| | | // 心跳 |
| | | heartbeat(); |
| | | // heartbeat(); |
| | | Thread.sleep(500); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | |
| | | */ |
| | | private void readStatus(){ |
| | | try { |
| | | OperateResultExOne<byte[]> result = siemensS7Net.Read("V20", (short) 70); |
| | | OperateResultExOne<byte[]> result = siemensS7Net.Read("DB4", (short) 70); |
| | | if (result.IsSuccess) { |
| | | if (null == steProtocol) { |
| | | steProtocol = new SteProtocol(); |
| | | } |
| | | // steProtocol.setSteNo(); |
| | | // steProtocol.setMode(); |
| | | // steProtocol.setStatus(); |
| | | steProtocol.setSteNo(siemensS7Net.getByteTransform().TransInt16(result.Content, 0)); |
| | | steProtocol.setMode(siemensS7Net.getByteTransform().TransInt16(result.Content, 2)); |
| | | steProtocol.setStatus(siemensS7Net.getByteTransform().TransInt16(result.Content, 4)); |
| | | // steProtocol.setExecute(); |
| | | // steProtocol.setWaiting(); |
| | | // steProtocol.setAlarm(); |
| | | // steProtocol.setAlarm0(); |
| | | // steProtocol.setCharge(); |
| | | steProtocol.setAlarm(siemensS7Net.getByteTransform().TransInt32(result.Content, 6)); |
| | | steProtocol.setAlarm0(siemensS7Net.getByteTransform().TransInt32(result.Content, 10)); |
| | | steProtocol.setCharge(siemensS7Net.getByteTransform().TransInt16(result.Content, 14)); |
| | | // steProtocol.setFullCharge(); |
| | | // steProtocol.setLowCharge(); |
| | | // steProtocol.setFeed(); |
| | | // steProtocol.setLoca(); |
| | | steProtocol.setFeed(siemensS7Net.getByteTransform().TransInt16(result.Content, 16)); |
| | | steProtocol.setLoca(siemensS7Net.getByteTransform().TransInt16(result.Content, 18)); |
| | | // steProtocol.setCloser(); |
| | | // steProtocol.setSpeed(); |
| | | // steProtocol.setPos(); |
| | | // steProtocol.setLoad(); |
| | | // steProtocol.setTrack(); |
| | | // steProtocol.setTaskNo(); |
| | | // steProtocol.setTaskType(); |
| | | // steProtocol.setRow(); |
| | | // steProtocol.setBay(); |
| | | // steProtocol.setLev(); |
| | | // |
| | | // steProtocol.setHisTaskNo(); |
| | | // steProtocol.setHisTaskStatus(); |
| | | // steProtocol.setCheckQty(); |
| | | // steProtocol.setReady(); |
| | | // steProtocol.setChargeNo(); |
| | | // |
| | | // steProtocol.setHeart(); |
| | | // steProtocol.setCrnStopRun(); |
| | | // steProtocol.setCrnStopFork(); |
| | | // steProtocol.setCrnAllowRun(); |
| | | steProtocol.setPos(siemensS7Net.getByteTransform().TransInt16(result.Content, 28)); |
| | | steProtocol.setLoad(siemensS7Net.getByteTransform().TransInt16(result.Content, 30)); |
| | | steProtocol.setTrack(siemensS7Net.getByteTransform().TransInt16(result.Content, 32)); |
| | | steProtocol.setTaskNo(siemensS7Net.getByteTransform().TransInt32(result.Content, 38)); |
| | | steProtocol.setTaskType(siemensS7Net.getByteTransform().TransInt16(result.Content, 42)); |
| | | steProtocol.setRow(siemensS7Net.getByteTransform().TransInt16(result.Content, 44)); |
| | | steProtocol.setBay(siemensS7Net.getByteTransform().TransInt16(result.Content, 46)); |
| | | steProtocol.setLev(siemensS7Net.getByteTransform().TransInt16(result.Content, 48)); |
| | | |
| | | steProtocol.setHisTaskNo(siemensS7Net.getByteTransform().TransInt32(result.Content, 58)); |
| | | steProtocol.setHisTaskStatus(siemensS7Net.getByteTransform().TransInt16(result.Content, 62)); |
| | | steProtocol.setCheckQty(siemensS7Net.getByteTransform().TransInt16(result.Content, 64)); |
| | | steProtocol.setReady(siemensS7Net.getByteTransform().TransInt16(result.Content, 66)); |
| | | steProtocol.setChargeNo(siemensS7Net.getByteTransform().TransInt16(result.Content, 68)); |
| | | |
| | | steProtocol.setHeart(siemensS7Net.getByteTransform().TransInt16(result.Content, 72)); |
| | | steProtocol.setCrnStopRun(siemensS7Net.getByteTransform().TransInt16(result.Content, 74)); |
| | | steProtocol.setCrnStopFork(siemensS7Net.getByteTransform().TransInt16(result.Content, 76)); |
| | | steProtocol.setCrnAllowRun(siemensS7Net.getByteTransform().TransInt16(result.Content, 78)); |
| | | |
| | | OutputQueue.CRN.offer(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功",DateUtils.convert(new Date()), slave.getId())); |
| | | |
| | | // 复位信号 |
| | | if (steProtocol.getStatusType().equals(SteStatusType.WAITING)) { |
| | | if (steProtocol.getWaiting()) { |
| | | if (resetFlag) { |
| | | SteCommand steCommand = new SteCommand(); |
| | | // steCommand.setAckFinish((short)1); |
| | | steCommand.setComplete(true); |
| | | if (write(steCommand) && confirmPos()) { |
| | | resetFlag = false; |
| | | } |
| | |
| | | |
| | | // 根据实时信息更新数据库 |
| | | BasSteService service = SpringUtils.getBean(BasSteService.class); |
| | | BasSte basSte = new BasSte(); |
| | | basSte.setSteNo(slave.getId()); |
| | | if (!service.updateById(steProtocol.toSqlModel(basSte))){ |
| | | log.error("穿梭车plc数据库更新失败 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); |
| | | } |
| | | if (null != service) { |
| | | BasSte basSte = new BasSte(); |
| | | basSte.setSteNo(slave.getId()); |
| | | if (!service.updateById(steProtocol.toSqlModel(basSte))){ |
| | | log.error("穿梭车plc数据库更新失败 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); |
| | | } |
| | | |
| | | } |
| | | } else { |
| | | OutputQueue.CRN.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())); |
| | |
| | | return false; |
| | | } |
| | | command.setSteNo(slave.getId()); |
| | | short[] array = new short[10]; |
| | | // array[0] = command.getAckFinish(); |
| | | // array[1] = command.getTaskNo(); |
| | | // array[2] = command.getTaskMode(); |
| | | // array[3] = command.getSourcePosX(); |
| | | OperateResult result = null; |
| | | // 开始任务 |
| | | if (!command.getComplete()) { |
| | | OperateResult result0 = siemensS7Net.Write("D0", command.getTaskNo()); |
| | | short[] array = new short[10]; |
| | | array[0] = command.getTaskMode(); |
| | | // 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 = siemensS7Net.Write("D0", array); |
| | | |
| | | // if (command.getAckFinish() == 0) { |
| | | // short commandFinish = 1; |
| | | // result = siemensS7Net.Write("D9", commandFinish); |
| | | // } |
| | | OperateResult result1 = siemensS7Net.Write("D0", array); |
| | | // 确认开始任务 |
| | | if (result0.IsSuccess) { |
| | | result = siemensS7Net.Write("D0", true); |
| | | } |
| | | // 任务完成 |
| | | } else { |
| | | result = siemensS7Net.Write("D0", true); |
| | | } |
| | | |
| | | try { |
| | | // 日志记录 |
| | | // BasCrnOptService bean = SpringUtils.getBean(BasCrnOptService.class); |
| | | // BasCrnOpt basCrnOpt = new BasCrnOpt( |
| | | // command.getTaskNo().intValue(), // 任务号 |
| | | // command.getCrnNo(), // 穿梭车[非空] |
| | | BasSteOptService bean = SpringUtils.getBean(BasSteOptService.class); |
| | | // BasSteOpt basSteOpt = new BasSteOpt( |
| | | // command.getTaskNo(), // 任务号 |
| | | // command.getSteNo(), // 穿梭车[非空] |
| | | // new Date(), // 下发时间 |
| | | // command.getTaskModeType().toString(), // 模式 |
| | | // command.getTaskModeType().desc, // 模式 |
| | | // command.getSourcePosX().intValue(), // 源排 |
| | | // command.getSourcePosY().intValue(), // 源列 |
| | | // command.getSourcePosZ().intValue(), // 源层 |
| | |
| | | // null, // 修改时间 |
| | | // null // 修改人员 |
| | | // ); |
| | | // bean.insert(basCrnOpt); |
| | | // bean.insert(basSteOpt); |
| | | } catch (Exception ignore) {} |
| | | |
| | | if (result.IsSuccess) { |
| | | if (result != null && result.IsSuccess) { |
| | | // 维护数据库排列层 |
| | | // this.modifyPos(); |
| | | if (!steProtocol.getWaiting()) { |
| | | this.lastRow = command.getRow().intValue(); |
| | | this.lastBay = command.getBay().intValue(); |
| | | this.lastLev = command.getLev().intValue(); |
| | | } |
| | | |
| | | |
| | | log.info("穿梭车命令下发[id:{}] >>>>> {}", slave.getId(), JSON.toJSON(command)); |
| | | OutputQueue.CRN.offer(MessageFormat.format("【{0}】[id:{1}] >>>>> 命令下发: {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command))); |
| | |
| | | BasSteService service = SpringUtils.getBean(BasSteService.class); |
| | | BasSte basSte = service.selectById(slave.getId()); |
| | | if (basSte != null) { |
| | | if (service.updatePos(this.lastRow, this.lastBay, this.lastLev) > 0) { |
| | | return true; |
| | | } else { |
| | | log.error("{}号穿梭车修改数据库定位失败!!!", slave.getId()); |
| | | // 更新plc数据块 |
| | | short[] arr = new short[] {this.lastRow.shortValue(), this.lastBay.shortValue(), this.lastLev.shortValue()}; |
| | | OperateResult result = siemensS7Net.Write("D0", arr); |
| | | if (result.IsSuccess) { |
| | | // 更新数据库 |
| | | if (service.updatePos(this.lastRow, this.lastBay, this.lastLev) > 0) { |
| | | this.lastRow = null; |
| | | this.lastBay = null; |
| | | this.lastLev = null; |
| | | return true; |
| | | } else { |
| | | log.error("{}号穿梭车修改数据库定位失败!!!", slave.getId()); |
| | | } |
| | | } |
| | | } |
| | | |