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

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

@ -163,7 +163,7 @@ public class OpcUaService : IOpcService, IDisposable
}
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
{
CachePath = "F:\\桌面\\数据缓存\\FusionCache.db"
//CachePath = "/Users/wenxiansheng/Public/WorkSpace/Mesnac/项目资料/澳柯玛注塑车间MES项目/数据缓存/FusionCache.db"
}));
}
}

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

Loading…
Cancel
Save