| | |
| | | package com.iailab.module.data.channel.kio.collector; |
| | | |
| | | import com.iailab.module.data.channel.kio.entity.ChannelKioDeviceEntity; |
| | | import com.iailab.module.data.channel.kio.service.ChannelKioDeviceService; |
| | | import com.iailab.module.data.channel.opcua.collector.OpcUaUtils; |
| | | import com.iailab.module.data.common.enums.CommonConstant; |
| | | import com.iailab.module.data.common.enums.DataSourceType; |
| | | import com.iailab.module.data.common.utils.TagUtils; |
| | | import com.iailab.module.data.channel.kio.dto.ChannelKioDeviceDTO; |
| | | import com.iailab.module.data.channel.kio.service.ChannelKioDeviceService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import javax.annotation.Resource; |
| | | import org.eclipse.milo.opcua.sdk.client.OpcUaClient; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | |
| | | |
| | | private Map<String, KingIOClient> clientMap = new ConcurrentHashMap<>(); |
| | | |
| | | private Map<String, ChannelKioDeviceDTO> deviceMap = new HashMap<>(); |
| | | private Map<String, ChannelKioDeviceEntity> deviceMap = new HashMap<>(); |
| | | |
| | | public synchronized KingIOClient getClient(String sourceId) throws Exception { |
| | | if (!clientMap.containsKey(sourceId)) { |
| | | ChannelKioDeviceDTO deviceDto = channelKioDeviceService.get(sourceId); |
| | | deviceMap.put(sourceId, deviceDto); |
| | | KingIOClient kingIOClient = new KingIOClient(deviceDto.getInstanceName()); |
| | | ChannelKioDeviceEntity deviceEntity = channelKioDeviceService.info(sourceId); |
| | | deviceMap.put(sourceId, deviceEntity); |
| | | KingIOClient kingIOClient = new KingIOClient(deviceEntity.getInstanceName()); |
| | | clientMap.put(sourceId, kingIOClient); |
| | | if (!kingIOClient.login(deviceDto.getAddress(), deviceDto.getPort(), deviceDto.getUsername(), deviceDto.getPassword())) { |
| | | if (!kingIOClient.login(deviceEntity.getAddress(), deviceEntity.getPort(), deviceEntity.getUsername(), deviceEntity.getPassword())) { |
| | | throw new Exception("登录异常"); |
| | | } |
| | | } |
| | |
| | | return kingIOClient; |
| | | } |
| | | |
| | | public String getTagValue(String sourceId, String tagName) throws Exception { |
| | | KingIOClient client = this.getClient(sourceId); |
| | | String value = client.getTagValue(tagName); |
| | | public String getTagValue(String sourceId, String tagName) { |
| | | String value = CommonConstant.BAD_VALUE.toString(); |
| | | try{ |
| | | KingIOClient client = this.getClient(sourceId); |
| | | value = client.getTagValue(tagName); |
| | | }catch (Exception ex){ |
| | | ex.printStackTrace(); |
| | | return value; |
| | | } |
| | | return value; |
| | | } |
| | | |