开发者

OPC Client - how to read from Remote OPC Server

I used OPCDotNetLib but can't read data from remote OPC Server there .

I can connect , like

Type typ开发者_Go百科eofOPCserver = Type.GetTypeFromProgID(clsidOPCserver, ip);

But looking the methods DataChanged or ReadCompleted doesn't work or works wrong.

I tested same with local OPC Server and it works well , with remote OPC Server I can connect, I can add items and can read data. OPC Server on remote machine shows that I read them, but I can't see any data. Seems like I need another workaround on OPCDotNetLib for remote OPC Server.

I even found a comment there

This library / dll will not work on a remote server, only local use is possible.

Is there some another available OPC Client .NET Libraries ?


You've got a few options for OPC compatibility. You can use the classical COM wrappers provided by OPC Foundation, or you can use the newer OPC library designed for .Net.

I haven't personally switched over to the newer library yet, but this is a break down of how to use OpcNetApi.dll,OpcNetApi.Com.dll, and OpcRcw.Da.dll to initialize a connection and subscribe to the DataChanged event:

Opc.Da.Server scadaServer = null;
List<Opc.Da.Item> scadaItems = null;
Opc.Da.Subscription scadaSubscription = null;

string scadaUrl = string.Format("opcda://{0}/{1}", hostname,
                                                   opcServerVendor);

scadaServer = new Opc.Da.Server(new OpcCom.Factory(), new Opc.URL(scadaUrl));
scadaServer.Connect();

var scadaItems = new List<Opc.Da.Item>(); // I'm using a List<T>, but cast back to a simple array using ToArray();

// Repeat this next part for all the items you need to subscribe
Opc.Da.Item item = new Opc.Da.Item();
item.ItemName = TagPath; // Where TagPath is something like device.channel.tag001;
item.ClientHandle = handle; // handle is up to you, but i use a logical name for it
item.Active = true;
item.ActiveSpecified = true;

scadaItems.Add(item);

Opc.Da.SubscriptionState subscriptionState = new Opc.Da.SubscriptionState();
subscriptionState.Active = true;
subscriptionState.UpdateRate = 40;
subscriptionState.Deadband = 0;

scadaSubscription = scadaSubscription ?? (Opc.Da.Subscription)scadaServer.CreateSubscription(subscriptionState);

Opc.Da.ItemResult[] result = scadaSubscription.AddItems(scadaItems.ToArray());
for (int i = 0; i < result.Length; i++)
    scadaItems[i].ServerHandle = result[i].ServerHandle;

scadaSubscription.DataChanged += new Opc.Da.DataChangedEventHandler(OnDataChange);
scadaSubscription.State.Active = true;


I know it has been a while but to help those who need the libraries. To go along with Greg Buehlers answer. They are Free and part of the core OPC Foundation and can be found here click on Archives tab if you need previous versions. It took me forever to find them so I hope this may help someone.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜