change - UA 数据读取测试

master
wenjy 3 months ago
parent 16e193557e
commit 801086a215

@ -80,7 +80,7 @@ public class DeviceCollectionBusiness
}); });
} }
Task.Delay(1000 * 10).Wait(); Task.Delay(1000 * 1).Wait();
} }
} while (isFalg); } while (isFalg);
} }
@ -112,6 +112,8 @@ public class DeviceCollectionBusiness
//var infos = _opcService.BrowseNodesAsync("ns=2;s=Devices/分厂一/车间一/测试空设备"); //var infos = _opcService.BrowseNodesAsync("ns=2;s=Devices/分厂一/车间一/测试空设备");
await _opcUaService.DisconnectAsync();
return infos; return infos;
} }
@ -133,7 +135,7 @@ public class DeviceCollectionBusiness
paramValues = deviceParams paramValues = deviceParams
.GroupJoin(opcItemValues, .GroupJoin(opcItemValues,
param => param.paramName, param => param.paramAddr,
value => value.NodeId, value => value.NodeId,
(param, values) => new { Param = param, Values = values }) (param, values) => new { Param = param, Values = values })
.SelectMany( .SelectMany(
@ -147,7 +149,7 @@ public class DeviceCollectionBusiness
paramAddr = x.Param.paramAddr, paramAddr = x.Param.paramAddr,
paramType = x.Param.paramType, paramType = x.Param.paramType,
isFlag = x.Param.isFlag, isFlag = x.Param.isFlag,
paramValue = value?.Value.ToString(), paramValue = value.Value.ToString(),
}) })
.ToList(); .ToList();

@ -111,22 +111,28 @@ public class OpcDaService : IOpcService, IDisposable
if (values[0].Error.Failed) if (values[0].Error.Failed)
throw new Exception($"读取失败: {values[0].Error}"); throw new Exception($"读取失败: {values[0].Error}");
//return new OpcNode var indexedNodeIds = nodeId.Select((value, index) => new { Index = index, Value = value });
//{
// NodeId = nodeId,
// DisplayName = nodeId,
// Value = values[0].Value,
// SourceTimestamp = values[0].Timestamp,
// DataType = values[0].Value?.GetType().Name ?? "Unknown"
//};
return null; List<OpcNode> result = new List<OpcNode>();
foreach (var item in indexedNodeIds)
{
var dataValue = values[item.Index];
result.Add(new OpcNode()
{
NodeId = item.Value,
DisplayName = item.Value,
Value = dataValue.Value,
SourceTimestamp = dataValue.Timestamp,
DataType = values[0].Value?.GetType().Name ?? "Unknown"
});
}
return result;
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
Console.WriteLine($"读取节点时出错: {ex.Message}"); throw new InvalidOperationException($"OPC DA 读取节点时出错:{ex.Message}");
throw;
} }
} }

@ -163,7 +163,7 @@ public class OpcUaService : IOpcService, IDisposable
} }
catch (Exception ex) catch (Exception ex)
{ {
throw new InvalidOperationException($"读取节点时出错:{ex.Message}"); throw new InvalidOperationException($"OPC UA 读取节点时出错:{ex.Message}");
} }
} }

@ -91,6 +91,7 @@ namespace Sln.Imm.Daemon
new SqliteCache(new SqliteCacheOptions new SqliteCache(new SqliteCacheOptions
{ {
CachePath = "F:\\桌面\\数据缓存\\FusionCache.db" CachePath = "F:\\桌面\\数据缓存\\FusionCache.db"
//CachePath = "/Users/wenxiansheng/Public/WorkSpace/Mesnac/项目资料/澳柯玛注塑车间MES项目/数据缓存/FusionCache.db"
})); }));
} }
} }

@ -5,6 +5,7 @@
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<SatelliteResourceLanguages>zh-Hans</SatelliteResourceLanguages>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

Loading…
Cancel
Save