C# opc-client .net api

eba picture eba · Sep 16, 2010 · Viewed 12.6k times · Source

I'm writing opc client, using .NET API from opc foundation.

In samples I only see, where item's names are hardcoded like:

items[0] = new Opc.Da.Item();
items[0].ItemName = "blahblahblah";

What I want, is not to write names of all items by my hands. I want to load all items from server, into tree for example. How can I do it?

Answer

user449562 picture user449562 · Sep 16, 2010

You can browse the server with the following construct:

using Opc.Da;
using Server=Opc.Da.Server;
using Factory=OpcCom.Factory;

string urlstring = string.Format("opcda://{0}/{1}/{{{2}}}", _hostName, _serverName, serverid);
Server s = new Server(new Factory(), new URL(urlstring));
s.Connect();
ItemIdentifier itemId = null;
BrowsePosition position;
BrowseFilters filters = new BrowseFilters() {BrowseFilter = browseFilter.item};
BrowseElement[] elements = s.Browse(itemId, filters, out position);

The tags are in elements[i].Name.