|
@@ -62,50 +62,6 @@ public class OpcAsyncTask {
|
|
|
return new AsyncResult(xx);
|
|
|
}
|
|
|
|
|
|
- public void KepServerReadItemList(ServerInformation serverInformation, List<ChannelSetting> channelSettingList) {
|
|
|
- log.info("KepServer:" + serverInformation.getIpAddress() + "开始读取数据");
|
|
|
- try {
|
|
|
- String opcServerDaPoolKey = KepOpcServerUtil.generateOpcPoolKey(serverInformation);
|
|
|
- if (KepOpcServerUtil.validationKey(opcServerDaPoolKey)) {
|
|
|
- Server server = KepOpcServerUtil.getServer(opcServerDaPoolKey);
|
|
|
- if (null == server.getServerState()) {
|
|
|
- throw new CustomException(ResultEnum.NOT_FOUND.getRespCode(), "连接失败");
|
|
|
- }
|
|
|
- if (OPCSERVERSTATE.OPC_STATUS_RUNNING == server.getServerState().getServerState()) {
|
|
|
- Group group = server.addGroup();
|
|
|
- group.addItems();
|
|
|
- //循环读值需要使用到的
|
|
|
- final AccessBase access = new SyncAccess(server, 1000);
|
|
|
- //开始读值
|
|
|
- access.bind();
|
|
|
- //停止读值
|
|
|
- access.unbind();
|
|
|
- Iterator<ChannelSetting> iterator = channelSettingList.iterator();
|
|
|
- while (iterator.hasNext()) {
|
|
|
- Item item = group.addItem(iterator.next().getChannelName());
|
|
|
- Map<String, Object> value = getVal(item.read(true).getValue());
|
|
|
- System.err.println(iterator.next().getChannelName() + ":" + value);
|
|
|
- }
|
|
|
- KepOpcServerUtil.returnServer(opcServerDaPoolKey, server);
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- throw new CustomException(ResultEnum.REQUEST_TIME_OUT.getRespCode(), e.getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public void KepServerCloseReadItemList(ServerInformation serverInformation, List<ChannelSetting> channelSettingList) {
|
|
|
- log.info("KepServer:" + serverInformation.getIpAddress() + "停止读取数据");
|
|
|
- }
|
|
|
-
|
|
|
- public void OpcServerUaReadItemList(ServerInformation serverInformation, List<ChannelSetting> channelSettingList) {
|
|
|
- log.info("OpcServerUa:opc.tcp://" + serverInformation.getIpAddress() + ":" + serverInformation.getIpPort() + "开始读取数据");
|
|
|
- }
|
|
|
-
|
|
|
- public void OpcServerUaCloseReadItemList(ServerInformation serverInformation, List<ChannelSetting> channelSettingList) {
|
|
|
- log.info("OpcServerUa:opc.tcp://" + serverInformation.getIpAddress() + ":" + serverInformation.getIpPort() + "停止读取数据");
|
|
|
- }
|
|
|
-
|
|
|
//异步读取kepserver
|
|
|
public void runKepServer(ItemGroup itemGroup, DataSource dataSource) {
|
|
|
Integer id = itemGroup.getId();
|
|
@@ -164,7 +120,7 @@ public class OpcAsyncTask {
|
|
|
List<NodeId> nodeIdList = OpcUaUtil.genNodeId(itemList);
|
|
|
while (flage) {
|
|
|
List<RawData> rawDataList = new ArrayList<>();
|
|
|
- List<DataValue> valueList = opcUaClient.readValues(0.0, TimestampsToReturn.Neither, nodeIdList).get();
|
|
|
+ List<DataValue> valueList = opcUaClient.readValues(0.0, TimestampsToReturn.Both, nodeIdList).get();
|
|
|
Date date = new Date();
|
|
|
for (DataValue dataValue : valueList) {
|
|
|
StatusCode statusCode = dataValue.getStatusCode();
|