0
值我使用從這裏NetCoreConsoleClient樣本:https://github.com/OPCFoundation/UA-.NETStandardLibrary使用OPC UA .NET讀「Channel1.Device1.Tag1」從Kepserver
我定製的代碼,並能夠通過整個服務器瀏覽和取像時間戳值,描述,數據類型等,用於服務器上的每個節點。
結點「Channel1.Device1.Tag1」我能夠獲取所有屬性/ vlaues(如數據類型,地址,說明),但我沒有得到這舉辦「Tag1中」
的實際值的屬性在Kepserver上,我注意到對於「Channel1.Device.Tag1」,沒有任何名稱爲「Value」的屬性保存了實際的標籤值。
當我使用KepServer提供的「快速客戶端」時,出現「Tag1」值。
我需要使用我自己的客戶端以某種方式獲取「標籤」值。
改性一段代碼:
`Console.WriteLine("4 - Browse the OPC UA server namespace.");
ReferenceDescriptionCollection references;
Byte[] continuationPoint;
references = session.FetchReferences(ObjectIds.ObjectsFolder);
session.Browse(
null,
null,
ObjectIds.ObjectsFolder,
//ObjectIds.RootFolder,
0u,
BrowseDirection.Forward,
ReferenceTypeIds.HierarchicalReferences,
true,
(uint)NodeClass.Variable | (uint)NodeClass.Object | (uint)NodeClass.Method,
out continuationPoint,
out references);
Console.WriteLine(" DisplayName, BrowseName, NodeClass");
foreach (var rd in references)
{
Console.WriteLine(" {0}, {1}, {2}", rd.DisplayName, rd.BrowseName, rd.NodeClass);
ReferenceDescriptionCollection nextRefs;
byte[] nextCp;
session.Browse(
null,
null,
ExpandedNodeId.ToNodeId(rd.NodeId, session.NamespaceUris),
0u,
BrowseDirection.Forward,
ReferenceTypeIds.HierarchicalReferences,
true,
(uint)NodeClass.Variable | (uint)NodeClass.Object | (uint)NodeClass.Method,
out nextCp,
out nextRefs);
foreach (var nextRd in nextRefs)
{
Console.WriteLine(" + {0}, {1}, {2}", nextRd.DisplayName, nextRd.BrowseName, nextRd.NodeClass);
ReferenceDescriptionCollection nextRefs1;
byte[] nextCp1;
session.Browse(
null,
null,
ExpandedNodeId.ToNodeId(nextRd.NodeId, session.NamespaceUris),
0u,
BrowseDirection.Forward,
ReferenceTypeIds.HierarchicalReferences,
true,
(uint)NodeClass.Variable | (uint)NodeClass.Object | (uint)NodeClass.Method,
out nextCp1,
out nextRefs1);
foreach (var nextRd1 in nextRefs1)
{
Console.WriteLine(" + {0}, {1}, {2}", nextRd1.DisplayName, nextRd1.BrowseName, nextRd1.NodeClass);
ReferenceDescriptionCollection nextRefs2;
byte[] nextCp2;
var res = session.Browse(
null, null,
ExpandedNodeId.ToNodeId(nextRd1.NodeId, session.NamespaceUris), 0u, BrowseDirection.Forward,
ReferenceTypeIds.HierarchicalReferences, true,
(uint)NodeClass.Variable | (uint)NodeClass.Object | (uint)NodeClass.Method, out nextCp2, out nextRefs2);
double maxAge = 0; //Pick 0 millisecond old value directly from device not from the cache.
DataValueCollection results;
DiagnosticInfoCollection diagInfos;
ReadValueIdCollection readValueIds;
foreach (var nextRd2 in nextRefs2)
{
try
{
if (!nextRd2.NodeId.IsNull)
{
var node = ExpandedNodeId.ToNodeId(nextRd2.NodeId, session.NamespaceUris);
if (node != null)
{
DataValue dv = session.ReadValue(node);
ReferenceDescriptionCollection nextRefs3;
byte[] nextCp3;
var res1 = session.Browse(null, null,
ExpandedNodeId.ToNodeId(nextRd2.NodeId, session.NamespaceUris), 0u, BrowseDirection.Forward,
ReferenceTypeIds.HierarchicalReferences, true,
(uint)NodeClass.Variable | (uint)NodeClass.Object | (uint)NodeClass.Method, out nextCp3, out nextRefs3);
foreach (var nextRd3 in nextRefs3)
{
if (!nextRd3.NodeId.IsNull)
{
var node1 = ExpandedNodeId.ToNodeId(nextRd3.NodeId, session.NamespaceUris);
if (node1 != null)
{
DataValue dv2 = session.ReadValue(node1);
}
}
}
}
}
}
catch (ServiceResultException srex)
{
//eat exception yum yum yum!
}
catch (Exception ex)
{
//eat exception yum yum yum!
}`
請說明您的意思「我無法獲得價值....」。觀察到的行爲是什麼? – ZbynekZ
我能夠獲得服務器上的所有節點的所有屬性/值和節點「Channel1.Device1.Tag1」我可以獲取所有屬性/值(如DataType,Address,Description),但我是沒有得到持有「Tag1」實際價值的財產 –