| | |
| | | import HslCommunication.Profinet.Siemens.SiemensPLCS; |
| | | import HslCommunication.Profinet.Siemens.SiemensS7Net; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.core.common.Cools; |
| | | import com.core.common.DateUtils; |
| | | import com.core.common.SpringUtils; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.entity.BasSte; |
| | | import com.zy.asrs.entity.BasSteOpt; |
| | | import com.zy.asrs.entity.WrkCharge; |
| | | import com.zy.asrs.service.BasSteOptService; |
| | | import com.zy.asrs.service.BasSteService; |
| | | import com.zy.common.model.enums.WrkChargeType; |
| | | import com.zy.core.DevpThread; |
| | | import com.zy.core.News; |
| | | import com.zy.core.ThreadHandler; |
| | | import com.zy.core.cache.MessageQueue; |
| | | import com.zy.core.cache.OutputQueue; |
| | | import com.zy.core.cache.SlaveConnection; |
| | | import com.zy.core.enums.SlaveType; |
| | | import com.zy.core.enums.SteStatusType; |
| | | import com.zy.core.model.SteSlave; |
| | |
| | | private SteProtocol steProtocol; |
| | | private short heartBeatVal = 1; |
| | | private boolean resetFlag = false; |
| | | |
| | | private Integer lastRow; |
| | | private Integer lastBay; |
| | | private Integer lastLev; |
| | | |
| | | public SteThread(SteSlave slave) { |
| | | this.slave = slave; |
| | |
| | | steProtocol.setSteNo(slave.getId().shortValue()); |
| | | steProtocol.setMode((short) 0); |
| | | steProtocol.setStatus(SteStatusType.OFF_LINE); |
| | | steProtocol.setTaskNo(0); |
| | | steProtocol.setTaskNo((short) 0); |
| | | steProtocol.setExecute(false); |
| | | steProtocol.setWaiting(false); |
| | | } |
| | |
| | | OperateResult connect = siemensS7Net.ConnectServer(); |
| | | if(connect.IsSuccess){ |
| | | result = true; |
| | | OutputQueue.CRN.offer(MessageFormat.format( "【{0}】穿梭车plc连接成功 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort())); |
| | | log.info("穿梭车plc连接成功 ===>> [id:{}] [ip:{}] [port:{}]", 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.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()); |
| | | OutputQueue.STE.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()); |
| | | initSte(); |
| | | } |
| | | // melsecMcNet.ConnectClose(); |
| | |
| | | if (result.IsSuccess) { |
| | | if (null == steProtocol) { |
| | | steProtocol = new SteProtocol(); |
| | | steProtocol.setSteNo(slave.getId().shortValue()); |
| | | } |
| | | steProtocol.setSteNo(siemensS7Net.getByteTransform().TransInt16(result.Content, 0)); |
| | | // steProtocol.setSteNo(siemensS7Net.getByteTransform().TransInt16(result.Content, 0)); |
| | | steProtocol.setMode(siemensS7Net.getByteTransform().TransInt16(result.Content, 2)); |
| | | steProtocol.setStatus(siemensS7Net.getByteTransform().TransInt16(result.Content, 4)); |
| | | OperateResultExOne<Boolean> executeRes = siemensS7Net.ReadBool("V2001.0"); |
| | |
| | | OperateResultExOne<Boolean> waitingRes = siemensS7Net.ReadBool("V2001.1"); |
| | | if (waitingRes.IsSuccess) { |
| | | steProtocol.setWaiting(waitingRes.Content); |
| | | } |
| | | OperateResultExOne<Boolean> inEmptyRes = siemensS7Net.ReadBool("V2001.2"); |
| | | if (inEmptyRes.IsSuccess) { |
| | | steProtocol.setInEmpty(inEmptyRes.Content); |
| | | } |
| | | OperateResultExOne<Boolean> outEmptyRes = siemensS7Net.ReadBool("V2001.3"); |
| | | if (outEmptyRes.IsSuccess) { |
| | | steProtocol.setOutEmpty(outEmptyRes.Content); |
| | | } |
| | | steProtocol.setAlarm(siemensS7Net.getByteTransform().TransInt16(result.Content, 6)); |
| | | steProtocol.setAlarm0(siemensS7Net.getByteTransform().TransInt16(result.Content, 8)); |
| | |
| | | steProtocol.setPos(siemensS7Net.getByteTransform().TransInt16(result.Content, 18)); |
| | | steProtocol.setLoad(siemensS7Net.getByteTransform().TransInt16(result.Content, 20)); |
| | | steProtocol.setTrack(siemensS7Net.getByteTransform().TransInt16(result.Content, 22)); |
| | | steProtocol.setTaskNo(siemensS7Net.getByteTransform().TransInt32(result.Content, 24)); |
| | | steProtocol.setTaskNo(siemensS7Net.getByteTransform().TransInt16(result.Content, 24)); |
| | | steProtocol.setTaskType(siemensS7Net.getByteTransform().TransInt16(result.Content, 28)); |
| | | steProtocol.setRow(siemensS7Net.getByteTransform().TransInt16(result.Content, 30)); |
| | | steProtocol.setBay(siemensS7Net.getByteTransform().TransInt16(result.Content, 32)); |
| | |
| | | steProtocol.setCrnStopRun(siemensS7Net.getByteTransform().TransInt16(result.Content, 38)); |
| | | steProtocol.setCrnStopFork(siemensS7Net.getByteTransform().TransInt16(result.Content, 40)); |
| | | steProtocol.setCrnAllowRun(siemensS7Net.getByteTransform().TransInt16(result.Content, 42)); |
| | | // steProtocol.setCrnAllowRun(siemensS7Net.getByteTransform().TransInt16(result.Content, 44)); |
| | | SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, 1); |
| | | if (!devpThread.charge0 || devpThread.charge1){ |
| | | steProtocol.setChargeStatus((short)1); |
| | | }else { |
| | | steProtocol.setChargeStatus((short)0); |
| | | } |
| | | |
| | | OutputQueue.CRN.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())); |
| | | |
| | | //读取穿梭车设备信息,提供查询 |
| | | OperateResultExOne<byte[]> result1 = siemensS7Net.Read("V732", (short) 16); |
| | | if (result1.IsSuccess) { |
| | | boolean[] status = siemensS7Net.getByteTransform().TransBool(result1.Content, 0, 15); |
| | | steProtocol.setLiftErr(status[0]); |
| | | steProtocol.setInFetchErr(status[2]); |
| | | steProtocol.setOutFetchErr(status[3]); |
| | | steProtocol.setAntiErr(status[4]); |
| | | steProtocol.setLiftSwitchErr(status[5]); |
| | | steProtocol.setTrackErr(status[6]); |
| | | steProtocol.setTimeoutErr(status[7]); |
| | | steProtocol.setConnectErr(status[8]); |
| | | steProtocol.setEmergencyErr(status[9]); |
| | | steProtocol.setTaskTypeErr(status[10]); |
| | | steProtocol.setTaskNoErr(status[11]); |
| | | steProtocol.setNewTaskErr(status[12]); |
| | | steProtocol.setErrTaskErr(status[13]); |
| | | steProtocol.setStopErr(status[14]); |
| | | steProtocol.setOfflineTaskErr(status[15]); |
| | | steProtocol.setStartTaskErr(status[16]); |
| | | steProtocol.setVoltageTaskErr(status[17]); |
| | | |
| | | steProtocol.setDevpErr(status[63]); |
| | | |
| | | steProtocol.setOnline(status[64]); |
| | | steProtocol.setNotOnTrack(status[65]); |
| | | steProtocol.setLowVoltage(status[66]); |
| | | steProtocol.setElectricityLoss(status[67]); |
| | | steProtocol.setForcedTravel(status[68]); |
| | | steProtocol.setDemoMode(status[69]); |
| | | steProtocol.setBrushConnect(status[70]); |
| | | // if (status[70]){ |
| | | // steProtocol.setChargeStatus((short)1); |
| | | // } |
| | | steProtocol.setTaskManualForbid(status[71]); |
| | | steProtocol.setOnlineManualForbid(status[72]); |
| | | steProtocol.setDevpEmergency(status[73]); |
| | | steProtocol.setTaskInterrupt(status[74]); |
| | | steProtocol.setTaskClear(status[75]); |
| | | steProtocol.setTaskConfirmTimeout(status[76]); |
| | | steProtocol.setTaskWithCharge(status[77]); |
| | | |
| | | steProtocol.setPakInTask(status[96]); |
| | | steProtocol.setPakOutTask(status[97]); |
| | | steProtocol.setPakMoveTask(status[98]); |
| | | steProtocol.setGoHpTask(status[99]); |
| | | steProtocol.setGoOHpTask(status[100]); |
| | | steProtocol.setGoHpAvoid(status[101]); |
| | | steProtocol.setGoOHpAvoid(status[102]); |
| | | steProtocol.setPakInEmpty(status[104]); |
| | | steProtocol.setPakInFinish(status[105]); |
| | | steProtocol.setPakOutEmpty(status[106]); |
| | | steProtocol.setPakOutFinish(status[107]); |
| | | steProtocol.setGoHpAvoidFinish(status[108]); |
| | | steProtocol.setGoOHpAvoidFinish(status[109]); |
| | | steProtocol.setGoHpAvoidErr(status[110]); |
| | | steProtocol.setGoOHpAvoidErr(status[111]); |
| | | |
| | | steProtocol.setAutoMode(status[112]); |
| | | steProtocol.setVoltageLow(status[113]); |
| | | } |
| | | |
| | | // 复位信号 |
| | | if (steProtocol.getWaiting()) { |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | // 根据实时信息更新数据库 |
| | | BasSteService service = SpringUtils.getBean(BasSteService.class); |
| | | if (null != service) { |
| | | // 同步pakMk |
| | | BasSte one = service.selectById(slave.getId()); |
| | | if (one != null) { |
| | | steProtocol.setPakMk(one.getPakMk()); |
| | | } |
| | | |
| | | 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()); |
| | | News.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())); |
| | | 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(); |
| | | 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()); |
| | | // e.printStackTrace(); |
| | | OutputQueue.STE.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()); |
| | | initSte(); |
| | | } |
| | | |
| | |
| | | */ |
| | | private boolean write(SteCommand command){ |
| | | if (null == command) { |
| | | log.error("穿梭车写入命令为空"); |
| | | News.error("穿梭车写入命令为空"); |
| | | return false; |
| | | } |
| | | //判断小车是否在充电 |
| | | SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, 1); |
| | | if (devpThread.charge1){ |
| | | // led 异常显示 |
| | | LedThread ledThread1 = (LedThread) SlaveConnection.get(SlaveType.Led, 1); |
| | | LedThread ledThread2 = (LedThread) SlaveConnection.get(SlaveType.Led, 1); |
| | | LedThread ledThread3 = (LedThread) SlaveConnection.get(SlaveType.Led, 1); |
| | | if (ledThread1 != null && ledThread2 != null && ledThread3 != null) { |
| | | MessageQueue.offer(SlaveType.Led, 1, new Task(3, "穿梭车正在充电")); |
| | | MessageQueue.offer(SlaveType.Led, 2, new Task(3, "穿梭车正在充电")); |
| | | MessageQueue.offer(SlaveType.Led, 3, new Task(3, "穿梭车正在充电")); |
| | | } |
| | | News.error("穿梭车正在充电"); |
| | | return false; |
| | | }else if (!devpThread.charge0){ |
| | | // led 异常显示 |
| | | LedThread ledThread1 = (LedThread) SlaveConnection.get(SlaveType.Led, 1); |
| | | LedThread ledThread2 = (LedThread) SlaveConnection.get(SlaveType.Led, 1); |
| | | LedThread ledThread3 = (LedThread) SlaveConnection.get(SlaveType.Led, 1); |
| | | if (ledThread1 != null && ledThread2 != null && ledThread3 != null) { |
| | | MessageQueue.offer(SlaveType.Led, 1, new Task(3, "穿梭车可能在离线充电,检查电控柜穿梭车是否充电桩在线")); |
| | | MessageQueue.offer(SlaveType.Led, 2, new Task(3, "穿梭车可能在离线充电,检查电控柜穿梭车是否充电桩在线")); |
| | | MessageQueue.offer(SlaveType.Led, 3, new Task(3, "穿梭车可能在离线充电,检查电控柜穿梭车是否充电桩在线")); |
| | | } |
| | | News.error("穿梭车可能在离线充电,检查电控柜穿梭车是否充电桩在线"); |
| | | return false; |
| | | } |
| | | command.setSteNo(slave.getId()); |
| | | OperateResult result = null; |
| | | // 开始任务 |
| | | if (!command.getComplete()) { |
| | | |
| | | //组织任务前,先清空写任务确认位,以及任务完成确认位 |
| | | siemensS7Net.Write("V2000.0", false); |
| | | siemensS7Net.Write("V2000.1", false); |
| | | // 1.任务号 |
| | | OperateResult result0 = siemensS7Net.Write("V998", command.getTaskNo().shortValue()); |
| | | try { |
| | | Thread.sleep(200); |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | // 作业 |
| | | if (command.getTaskMode() != 0) { |
| | | // 1.任务号 |
| | | OperateResult result0 = siemensS7Net.Write("V998", command.getTaskNo().shortValue()); |
| | | try { |
| | | Thread.sleep(200); |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | // 2.作业 |
| | | OperateResult result1 = siemensS7Net.Write("V1000", command.getTaskMode()); |
| | | // 3.确认开始任务 |
| | | if (result0.IsSuccess && result1.IsSuccess) { |
| | | result = siemensS7Net.Write("V2000.0", true); |
| | | siemensS7Net.Write("V2000.1", false); |
| | | } |
| | | |
| | | // 其他指令 |
| | |
| | | |
| | | // 任务完成 |
| | | } else { |
| | | siemensS7Net.Write("V2000.0", false); |
| | | siemensS7Net.Write("V998", (short) 0); |
| | | siemensS7Net.Write("V1000", (short) 0); |
| | | result = siemensS7Net.Write("V2000.1", true); |
| | | } |
| | | |
| | |
| | | if (result != null && result.IsSuccess) { |
| | | // 维护数据库排列层 |
| | | if (!steProtocol.getWaiting()) { |
| | | this.modifyPos(command.getRow().intValue(), command.getBay().intValue(), command.getLev().intValue()); |
| | | if (!Cools.isEmpty(command.getRow(), command.getBay(), command.getLev())) { |
| | | this.modifyPos(command.getRow().intValue(), command.getBay().intValue(), 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))); |
| | | News.info("穿梭车命令下发[id:{}] >>>>> {}", slave.getId(), JSON.toJSON(command)); |
| | | OutputQueue.STE.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()); |
| | | OutputQueue.STE.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()); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | public void modifyPos(Integer row, Integer bay, Integer lev) { |
| | | this.lastRow = row; |
| | | this.lastBay = bay; |
| | | this.lastLev = lev; |
| | | BasSteService service = SpringUtils.getBean(BasSteService.class); |
| | | if (!service.updatePos(this.slave.getId(), row, bay, lev)) { |
| | | News.error("更新{}号穿梭车定位失败 ===>> 排:【{}】, 列:【{}】,层:【{}】", this.slave.getId(), row, bay, 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) { |
| | | // 更新plc数据块 |
| | | short[] arr = new short[] {this.lastRow.shortValue(), this.lastBay.shortValue(), this.lastLev.shortValue()}; |
| | | OperateResult result = siemensS7Net.Write("V1002", 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()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | BasSteService service = SpringUtils.getBean(BasSteService.class); |
| | | BasSte basSte = service.selectById(slave.getId()); |
| | | if (basSte != null) { |
| | | // 更新plc数据块 |
| | | short[] arr = new short[] {basSte.getRow().shortValue(), basSte.getBay().shortValue(), basSte.getLev().shortValue()}; |
| | | OperateResult result = siemensS7Net.Write("V1002", arr); |
| | | if (result.IsSuccess) { |
| | | // 更新数据库 |
| | | if (service.updatePakMk(this.slave.getId(), "N")) { |
| | | return true; |
| | | } else { |
| | | News.error("{}号穿梭车修改数据库定位失败!!!", slave.getId()); |
| | | } |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | public boolean modifyPosHandle(Integer row, Integer bay, Integer lev) { |
| | | 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); |
| | | return false; |
| | | } |
| | | BasSteService service = SpringUtils.getBean(BasSteService.class); |
| | | if (!service.updatePos(this.slave.getId(), row, bay, lev)) { |
| | | News.error("更新{}号穿梭车定位失败 ===>> 排:【{}】, 列:【{}】,层:【{}】", this.slave.getId(), row, bay, lev); |
| | | return false; |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | OperateResult write = siemensS7Net.Write("D10", heartBeatVal); |
| | | if (!write.IsSuccess) { |
| | | log.error("输送线plc编号={} 心跳失败", slave.getId()); |
| | | News.error("输送线plc编号={} 心跳失败", slave.getId()); |
| | | } |
| | | } |
| | | |
| | | // public void modifyPos(int wrkNo, int row, int bay, int lev) { |
| | | // BasSteService service = SpringUtils.getBean(BasSteService.class); |
| | | // if (!service.updatePos(wrkNo,this.slave.getId(), row, bay, lev)) { |
| | | // News.error("更新{}号穿梭车定位失败 ===>> 排:【{}】, 列:【{}】,层:【{}】", this.slave.getId(), row, bay, lev); |
| | | // } |
| | | // } |
| | | |
| | | /******************************************************************************************/ |
| | | /**************************************** 测试专用 *****************************************/ |