| | |
| | | import HslCommunication.Core.Types.OperateResultExOne; |
| | | import HslCommunication.Profinet.Siemens.SiemensPLCS; |
| | | import HslCommunication.Profinet.Siemens.SiemensS7Net; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.core.common.DateUtils; |
| | | import com.core.common.SpringUtils; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.entity.BasCrnp; |
| | | import com.zy.asrs.service.BasCrnpService; |
| | | import com.zy.asrs.entity.BasSte; |
| | | import com.zy.asrs.service.BasSteService; |
| | | import com.zy.core.ThreadHandler; |
| | | import com.zy.core.cache.MessageQueue; |
| | | import com.zy.core.cache.OutputQueue; |
| | |
| | | private short heartBeatVal = 1; |
| | | private boolean resetFlag = false; |
| | | |
| | | private Integer lastRow; |
| | | private Integer lastBay; |
| | | private Integer lastLev; |
| | | |
| | | public SteThread(SteSlave slave) { |
| | | this.slave = slave; |
| | | } |
| | |
| | | // 写入数据 |
| | | case 2: |
| | | write((SteCommand) task.getData()); |
| | | break; |
| | | // 复位 |
| | | case 3: |
| | | SteCommand command = (SteCommand) task.getData(); |
| | | if (null == command) { |
| | | command = new SteCommand(); |
| | | } |
| | | // command.setSteNo(slave.getId()); // 穿梭车编号 |
| | | // 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); // 目标库位层 |
| | | write(command); |
| | | break; |
| | | default: |
| | | break; |
| | |
| | | */ |
| | | private void readStatus(){ |
| | | try { |
| | | // if (this.slave.getId() == 1 && flag1.equals(0)) { |
| | | // Thread.sleep(3000); |
| | | // flag1=1; |
| | | // System.out.println("==="); |
| | | // } |
| | | OperateResultExOne<byte[]> result = siemensS7Net.Read("V20", (short) 70); |
| | | if (result.IsSuccess) { |
| | | if (null == steProtocol) { |
| | | steProtocol = new SteProtocol(); |
| | | } |
| | | // steProtocol.setMode(siemensS7Net.getByteTransform().TransInt16(result.Content, 0)); |
| | | // steProtocol.setTaskNo(siemensS7Net.getByteTransform().TransInt16(result.Content, 2)); |
| | | // steProtocol.setStatus(siemensS7Net.getByteTransform().TransInt16(result.Content, 4)); |
| | | // steProtocol.setBay(siemensS7Net.getByteTransform().TransInt16(result.Content, 6)); |
| | | // steProtocol.setLevel(siemensS7Net.getByteTransform().TransInt16(result.Content, 8)); |
| | | // steProtocol.setForkPos(siemensS7Net.getByteTransform().TransInt16(result.Content, 10)); |
| | | // steProtocol.setLiftPos(siemensS7Net.getByteTransform().TransInt16(result.Content, 12)); |
| | | // steProtocol.setWalkPos(siemensS7Net.getByteTransform().TransInt16(result.Content, 14)); |
| | | // steProtocol.setLoaded(siemensS7Net.getByteTransform().TransInt16(result.Content, 16)); |
| | | // steProtocol.setAlarm(siemensS7Net.getByteTransform().TransInt16(result.Content, 18)); |
| | | // steProtocol.setSteNo(); |
| | | // steProtocol.setMode(); |
| | | // steProtocol.setStatus(); |
| | | // steProtocol.setExecute(); |
| | | // steProtocol.setWaiting(); |
| | | // steProtocol.setAlarm(); |
| | | // steProtocol.setAlarm0(); |
| | | // steProtocol.setCharge(); |
| | | // steProtocol.setFullCharge(); |
| | | // steProtocol.setLowCharge(); |
| | | // steProtocol.setFeed(); |
| | | // steProtocol.setLoca(); |
| | | // 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(); |
| | | |
| | | OutputQueue.CRN.offer(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功",DateUtils.convert(new Date()), slave.getId())); |
| | | |
| | |
| | | if (resetFlag) { |
| | | SteCommand steCommand = new SteCommand(); |
| | | // steCommand.setAckFinish((short)1); |
| | | if (write(steCommand)) { |
| | | if (write(steCommand) && confirmPos()) { |
| | | resetFlag = false; |
| | | } |
| | | } |
| | |
| | | |
| | | |
| | | // 根据实时信息更新数据库 |
| | | BasCrnpService basCrnpService = SpringUtils.getBean(BasCrnpService.class); |
| | | BasCrnp basCrnp = new BasCrnp(); |
| | | basCrnp.setCrnErr(steProtocol.getAlarm()==null?0:steProtocol.getAlarm().longValue()); |
| | | basCrnp.setCrnNo(slave.getId()); |
| | | if (!basCrnpService.updateById(steProtocol.toSqlModel(basCrnp))){ |
| | | 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()); |
| | | } |
| | | |
| | |
| | | * 写入数据 |
| | | */ |
| | | private boolean write(SteCommand command){ |
| | | return true; |
| | | // if (null == command) { |
| | | // log.error("穿梭车写入命令为空"); |
| | | // return false; |
| | | // } |
| | | // command.setCrnNo(slave.getId()); |
| | | // short[] array = new short[10]; |
| | | if (null == command) { |
| | | log.error("穿梭车写入命令为空"); |
| | | return false; |
| | | } |
| | | command.setSteNo(slave.getId()); |
| | | short[] array = new short[10]; |
| | | // array[0] = command.getAckFinish(); |
| | | // array[1] = command.getTaskNo(); |
| | | // array[2] = command.getTaskMode(); |
| | |
| | | // array[7] = command.getDestinationPosY(); |
| | | // array[8] = command.getDestinationPosZ(); |
| | | // array[9] = command.getCommand(); |
| | | // OperateResult result = siemensS7Net.Write("D0", array); |
| | | // |
| | | OperateResult result = siemensS7Net.Write("D0", array); |
| | | |
| | | // if (command.getAckFinish() == 0) { |
| | | // short commandFinish = 1; |
| | | // result = siemensS7Net.Write("D9", commandFinish); |
| | | // } |
| | | // |
| | | // try { |
| | | // // 日志记录 |
| | | |
| | | try { |
| | | // 日志记录 |
| | | // BasCrnOptService bean = SpringUtils.getBean(BasCrnOptService.class); |
| | | // BasCrnOpt basCrnOpt = new BasCrnOpt( |
| | | // command.getTaskNo().intValue(), // 任务号 |
| | |
| | | // null // 修改人员 |
| | | // ); |
| | | // bean.insert(basCrnOpt); |
| | | // } catch (Exception ignore) {} |
| | | // |
| | | // if (result.IsSuccess) { |
| | | // 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))); |
| | | // 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())); |
| | | // log.error("写入穿梭车plc数据失败 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); |
| | | // return false; |
| | | // } |
| | | } catch (Exception ignore) {} |
| | | |
| | | if (result.IsSuccess) { |
| | | // 维护数据库排列层 |
| | | // this.modifyPos(); |
| | | |
| | | 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))); |
| | | 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())); |
| | | log.error("写入穿梭车plc数据失败 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | public void modifyPos(Integer row, Integer bay, Integer lev) { |
| | | this.lastRow = row; |
| | | this.lastBay = bay; |
| | | this.lastLev = lev; |
| | | } |
| | | |
| | | public boolean confirmPos() { |
| | | if (this.lastRow != null && this.lastRow != 0) { |
| | | if (this.lastBay != null && this.lastBay != 0) { |
| | | if (this.lastLev != null && this.lastLev != 0) { |
| | | 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()); |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | @Override |