public static void Overload2() { // Instantiate the client object var easyUAClient = new EasyUAClient(); // Obtain objects under "Server" node UANodeElementCollection nodeElementCollection = easyUAClient.BrowseObjects( "http://opcua.demo-this.com:51211/UA/SampleServer", // or "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer" UAObjectIds.Server); // Display results foreach (UANodeElement nodeElement in nodeElementCollection) { Console.WriteLine(); Console.WriteLine("nodeElement.NodeId: {0}", nodeElement.NodeId); Console.WriteLine("nodeElement.DisplayName: {0}", nodeElement.DisplayName); } // Example output: // //nodeElement.NodeId: nsu=http://opcfoundation.org/UA/;i=2268 //nodeElement.DisplayName: ServerCapabilities // //nodeElement.NodeId: nsu=http://opcfoundation.org/UA/;i=2274 //nodeElement.DisplayName: ServerDiagnostics // //nodeElement.NodeId: nsu=http://opcfoundation.org/UA/;i=2295 //nodeElement.DisplayName: VendorServerInfo // //nodeElement.NodeId: nsu=http://opcfoundation.org/UA/;i=2296 //nodeElement.DisplayName: ServerRedundancy }
static IEnumerable <UANodeElement> GetNode(string server, EasyUAClient client, IEnumerable <string> path, IEnumerable <UANodeElement> currentNodes) { var _currentNodes = currentNodes ?? new List <UANodeElement>(); if (!path.Any()) { return(currentNodes); } UANodeElementCollection nodes = new UANodeElementCollection(); if (!_currentNodes.Any()) { nodes = client.BrowseObjects(server); } else { nodes = client.BrowseVariables(server, currentNodes.Last()); } var node = nodes.SingleOrDefault(n => n.BrowseName.Name == path.First()); if (node != null) { return(GetNode(server, client, path.Skip(1), _currentNodes.Concat(new List <UANodeElement> { node }))); } return(new List <UANodeElement>()); }
// GET api/<controller> // GET api/<controller>/5 public object Get([FromUri] string[] path, string query = null) { var server = ConfigurationManager.AppSettings["opc-server"]; using (var client = new EasyUAClient()) { UANodeElementCollection nodes = new UANodeElementCollection(); path = path.Where(p => p != null).ToArray(); //.FirstOrDefault()?.Split('/'); var nodePath = new List <UANodeElement>(); if (!path.Any()) { nodes = client.BrowseObjects(server); } else { nodePath = GetNode(server, client, path, null).ToList(); if (!nodePath.Any()) { return(null); } nodes = client.BrowseVariables(server, nodePath.Last()); } return(new { path = path.Select((p, i) => new { browseName = p, node = NodeReturn(nodePath.ElementAtOrDefault(i)) }), children = nodes.Select(NodeReturn) }); } }
private static void BrowseFrom(UANodeDescriptor nodeDescriptor) { Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Parent node: {0}", nodeDescriptor); // Instantiate the client object var easyUAClient = new EasyUAClient(); // Obtain notifiers UANodeElementCollection notifierNodeElementCollection = easyUAClient.BrowseNotifiers( "opc.tcp://opcua.demo-this.com:62544/Quickstarts/AlarmConditionServer", nodeDescriptor); // Display notifiers Console.WriteLine(); Console.WriteLine("Notifiers:"); foreach (UANodeElement notifierNodeElement in notifierNodeElementCollection) { Console.WriteLine(notifierNodeElement); } // Obtain objects UANodeElementCollection objectNodeElementCollection = easyUAClient.BrowseObjects( "opc.tcp://opcua.demo-this.com:62544/Quickstarts/AlarmConditionServer", nodeDescriptor); // Recurse foreach (UANodeElement objectNodeElement in objectNodeElementCollection) { BrowseFrom(objectNodeElement); } }