| | |
| | | package com.zy.core.thread.impl; |
| | | |
| | | import HslCommunication.Profinet.Siemens.SiemensPLCS; |
| | | import HslCommunication.Profinet.Siemens.SiemensS7Net; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.zy.asrs.entity.BasDevp; |
| | |
| | | import com.core.common.SpringUtils; |
| | | import com.zy.asrs.entity.DeviceConfig; |
| | | import com.zy.asrs.entity.DeviceDataLog; |
| | | import com.zy.asrs.service.DeviceDataLogService; |
| | | import com.zy.common.utils.RedisUtil; |
| | | import com.zy.core.network.ZyStationConnectDriver; |
| | | import com.zy.core.cache.MessageQueue; |
| | | import com.zy.core.cache.OutputQueue; |
| | | import com.zy.core.enums.RedisKeyType; |
| | | import com.zy.core.enums.SlaveType; |
| | | import com.zy.core.model.CommandResponse; |
| | | import com.zy.core.model.Task; |
| | |
| | | import com.zy.core.network.entity.ZyStationStatusEntity; |
| | | |
| | | import java.text.MessageFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | |
| | | import lombok.Data; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | @SuppressWarnings("InfiniteLoopStatement") |
| | | public void run() { |
| | | this.connect(); |
| | | |
| | | //设备读取 |
| | | Thread readThread = new Thread(() -> { |
| | | while (true) { |
| | | try { |
| | | readStatus(); |
| | | Thread.sleep(200); |
| | | } catch (Exception e) { |
| | | log.error("StationThread Fail", e); |
| | | } |
| | | } |
| | | }); |
| | | readThread.start(); |
| | | |
| | | while (true) { |
| | | try { |
| | | int step = 1; |
| | |
| | | step = task.getStep(); |
| | | } |
| | | switch (step) { |
| | | // 读数据 |
| | | case 1: |
| | | readStatus(); |
| | | break; |
| | | case 2: |
| | | sendCommand((StationCommand) task.getData()); |
| | | break; |
| | |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功",DateUtils.convert(new Date()), deviceConfig.getDeviceNo())); |
| | | |
| | | if (System.currentTimeMillis() - deviceDataLogTime > 1000 * 1) { |
| | | //采集时间超过1s,保存一次数据记录 |
| | | //保存数据记录 |
| | | DeviceDataLogService deviceDataLogService = SpringUtils.getBean(DeviceDataLogService.class); |
| | | DeviceDataLog deviceDataLog = new DeviceDataLog(); |
| | | deviceDataLog.setOriginData(JSON.toJSONString(zyStationStatusEntities)); |
| | | deviceDataLog.setWcsData(JSON.toJSONString(statusList)); |
| | | deviceDataLog.setType(String.valueOf(SlaveType.Devp)); |
| | | deviceDataLog.setDeviceNo(deviceConfig.getDeviceNo()); |
| | | deviceDataLog.setCreateTime(new Date()); |
| | | deviceDataLogService.insert(deviceDataLog); |
| | | |
| | | redisUtil.set(RedisKeyType.DEVICE_LOG_KEY.key + System.currentTimeMillis(), deviceDataLog, 60 * 60 * 24); |
| | | //更新采集时间 |
| | | deviceDataLogTime = System.currentTimeMillis(); |
| | | } |
| | |
| | | |
| | | @Override |
| | | public boolean connect() { |
| | | SiemensS7Net siemensS7Net = new SiemensS7Net(SiemensPLCS.S1200, deviceConfig.getIp()); |
| | | zyStationConnectDriver = new ZyStationConnectDriver(siemensS7Net, deviceConfig); |
| | | zyStationConnectDriver = new ZyStationConnectDriver(deviceConfig); |
| | | new Thread(zyStationConnectDriver).start(); |
| | | DeviceConnectPool.put(SlaveType.Devp, deviceConfig.getDeviceNo(), zyStationConnectDriver); |
| | | return true; |
| | |
| | | return commandResponse; |
| | | } |
| | | |
| | | @Override |
| | | public Map<Integer, StationProtocol> getStatusMap() { |
| | | Map<Integer, StationProtocol> map = new HashMap<>(); |
| | | for (StationProtocol stationProtocol : statusList) { |
| | | map.put(stationProtocol.getStationId(), stationProtocol); |
| | | } |
| | | return map; |
| | | } |
| | | } |