.net OPC 客户端 - 如何从远程 OPC 服务器读取

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4921943/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 15:14:11  来源:igfitidea点击:

OPC Client - how to read from Remote OPC Server

.netopc

提问by cnd

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

我使用了OPCDotNetLib但无法从那里的远程 OPC 服务器读取数据。

I can connect , like

我可以连接,比如

Type typeofOPCserver = Type.GetTypeFromProgID(clsidOPCserver, ip);

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

但是查看方法 DataChanged 或 ReadCompleted 不起作用或工作错误。

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.

我在本地 OPC Server 上进行了相同的测试,效果很好,使用远程 OPC Server 我可以连接,我可以添加项目并可以读取数据。远程机器上的 OPC Server 显示我读取了它们,但我看不到任何数据。似乎我需要另一种解决方法来解决远程 OPC 服务器的 OPCDotNetLib。

I even found a comment there

我什至在那里找到了评论

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

这个库/dll 不能在远程服务器上工作,只能在本地使用。

Is there some another available OPC Client .NET Libraries ?

是否有其他可用的 OPC 客户端 .NET 库?

回答by Greg Buehler

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.

您有几个 OPC 兼容性选项。您可以使用 OPC Foundation 提供的经典 COM 包装器,也可以使用为 .Net 设计的较新的 OPC 库。

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.dllto initialize a connection and subscribe to the DataChangedevent:

我没有亲自切换到新的图书馆还没有,但是这是一个突破的如何使用下来OpcNetApi.dllOpcNetApi.Com.dllOpcRcw.Da.dll初始化连接,订阅DataChanged事件:

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;

回答by doogie

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 hereclick on Archives tab if you need previous versions. It took me forever to find them so I hope this may help someone.

我知道已经有一段时间了,但要帮助那些需要图书馆的人。同意 Greg Buehlers 的回答。它们是免费的,是核心 OPC 基金会的一部分,如果您需要以前的版本,请单击“存档”选项卡在此处找到。我花了很长时间才找到它们,所以我希望这可以帮助某人。