#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously public async Task <OpcObject> InitializeTree() #pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously { var opcNode = new OpcObject(); this.ExpandTree(opcNode); return(opcNode); }
public void ExpandTree(OpcObject parent) { NodeId nodeId; if (parent.IsExtended) { return; } if (parent.Key != "$") { nodeId = ExpandedNodeId.ToNodeId(parent.ExpandedNodeId, this.session.NamespaceUris); } else { nodeId = ObjectIds.ObjectsFolder; } ReferenceDescriptionCollection refs; Byte[] cp; Browse( nodeId, (uint)NodeClass.Variable | (uint)NodeClass.Object, out refs, out cp); foreach (var rd in refs) { ReferenceDescriptionCollection nextRefs; byte[] nextCp; if (rd.NodeClass == NodeClass.Object) { Browse( ExpandedNodeId.ToNodeId(rd.NodeId, session.NamespaceUris), (uint)NodeClass.Object, out nextRefs, out nextCp); var obj = new OpcObject { Key = rd.DisplayName.ToString(), ExpandedNodeId = rd.NodeId, }; if (!nextRefs.Any()) { obj.HasChildren = false; } parent.Children.Add(obj); } else { var node = ExpandedNodeId.ToNodeId(rd.NodeId, session.NamespaceUris); DataValue nodeValue = this.session.ReadValue(node); var obj = new OpcValue { Key = rd.DisplayName.ToString(), Value = nodeValue.Value as double?, ExpandedNodeId = rd.NodeId, }; parent.Values.Add(obj); } } parent.IsExtended = true; }