| | |
| | | import HslCommunication.Profinet.Siemens.SiemensPLCS; |
| | | import HslCommunication.Profinet.Siemens.SiemensS7Net; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.core.common.DateUtils; |
| | | import com.core.common.SpringUtils; |
| | | import com.zy.asrs.entity.BasCircularShuttle; |
| | | import com.zy.asrs.entity.BasRgv; |
| | | import com.zy.asrs.entity.BasRgvErrLog; |
| | | import com.zy.asrs.entity.BasRgvOpt; |
| | | import com.zy.asrs.service.BasCircularShuttleService; |
| | | import com.zy.asrs.service.BasRgvErrLogService; |
| | | import com.zy.asrs.service.BasRgvOptService; |
| | | import com.zy.asrs.service.BasRgvService; |
| | | import com.zy.asrs.utils.NumUtils; |
| | | import com.zy.core.ThreadHandler; |
| | | import com.zy.core.cache.MessageQueue; |
| | | import com.zy.core.cache.OutputQueue; |
| | |
| | | @SuppressWarnings("InfiniteLoopStatement") |
| | | public void run() { |
| | | connectRgv = this.connect(); |
| | | while(!connectRgv){ |
| | | try { |
| | | connectRgv = this.connect(); |
| | | Thread.sleep(100); |
| | | } catch (Exception e){ |
| | | |
| | | } |
| | | } |
| | | |
| | | // 启动线程自动重连 |
| | | new Thread(this::rgvConnect).start(); |
| | |
| | | Thread.sleep(1000); |
| | | if(!connectRgv){ |
| | | try { |
| | | // 根据实时信息更新数据库 |
| | | BasCircularShuttleService basCircularShuttleService = SpringUtils.getBean(BasCircularShuttleService.class); |
| | | BasCircularShuttle basCircularShuttle = basCircularShuttleService.selectOne(new EntityWrapper<BasCircularShuttle>().eq("rgv_no", slave.getId())); |
| | | if (basCircularShuttle.getStatus() != 0){ |
| | | continue; |
| | | } |
| | | } catch (Exception ignore) { |
| | | |
| | | } |
| | | try { |
| | | connectRgv = this.connect(); |
| | | Thread.sleep(100); |
| | | } catch (Exception e){ |
| | |
| | | rgvProtocol.setxDistance((short) 0); |
| | | rgvProtocol.setxDuration((short) 0); |
| | | log.error("连接中断:RGV号:"+slave.getId()); |
| | | try { |
| | | // 根据实时信息更新数据库 |
| | | BasRgvService basRgvService = SpringUtils.getBean(BasRgvService.class); |
| | | BasRgv basRgv = new BasRgv(); |
| | | basRgv.setRgvNo(slave.getId()); |
| | | basRgv.setRgvSts((int)rgvProtocol.getMode()); |
| | | basRgv.setLoaded2(rgvProtocol.getLoaded2().intValue()); |
| | | if (!basRgvService.updateById(rgvProtocol.toSqlModel(basRgv))){ |
| | | log.error("RGV plc数据库更新失败 ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot()); |
| | | } |
| | | } catch (Exception ignore) { |
| | | } |
| | | } |
| | | |
| | | // /** |
| | | // * 初始化RGV状态 |
| | | // */ |
| | | // private void initRgv() { |
| | | // if (null == rgvProtocol) { |
| | | // rgvProtocol = new RgvProtocol(); |
| | | // } |
| | | // rgvProtocol.setRgvNo(slave.getId()); |
| | | // rgvProtocol.setMode((short) 3); |
| | | // rgvProtocol.setStatus((short)0); |
| | | // rgvProtocol.setTaskNo1((short)0); |
| | | // rgvProtocol.setStatus1((short)0); |
| | | // rgvProtocol.setLoaded1((short)0); |
| | | // rgvProtocol.setWalkPos((short)0); |
| | | // rgvProtocol.setRgvPos(slave.getId()*100000L); |
| | | // rgvProtocol.setTaskNo2((short)0); |
| | | // rgvProtocol.setStatus2((short)0); |
| | | // rgvProtocol.setLoaded2((short)0); |
| | | // rgvProtocol.setAlarm((short)0); |
| | | // rgvProtocol.setxSpeed((short) 0); |
| | | // rgvProtocol.setxDistance((short) 0); |
| | | // rgvProtocol.setxDuration((short) 0); |
| | | // } |
| | | |
| | | @Override |
| | | public boolean connect() { |
| | |
| | | alarmChangeSign = new HashSet<>(alarmList).equals(new HashSet<>(rgvProtocol.getAlarmList())); |
| | | rgvProtocol.setAlarmList(alarmList); |
| | | |
| | | // rgvProtocol.setRgvPos((long)NumUtils.GetRandomIntInRange(1737000)); |
| | | // rgvProtocol.setRgvPos((long) NumUtils.GetRandomIntInRange(1737000)); |
| | | OutputQueue.RGV.offer(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功",DateUtils.convert(new Date()), slave.getId())); |
| | | |
| | | |