使用 QuickOPC 连接远程 OPC 服务器

Connect remote OPC server using QuickOPC

我目前正在使用 OPC Labs 的 QuickOPC 库。我目前的目的是编写一个 .NET 控制台应用程序以从 Matrikon Simulation OPC 服务器读取项目值。

模拟服务器运行在一台有IP地址的远程机器上,我需要输入用户名和密码才能登录到这台远程机器。

我目前的代码如下:

NetworkSecurity networkSecurity = new NetworkSecurity(UserName, Password, MachineName);
ServerDescriptor serverDescriptor = new ServerDescriptor("\\xxx.xxx.xxx.xxx\Matrikon.OPC.Simulation.1", networkSecurity);
serverDescriptor.Scheme = "opcda";
DAItemDescriptor itemDescriptor = new DAItemDescriptor(ItemID);

Console.WriteLine(client.ReadItemValue(serverDescriptor, itemDescriptor));

异常情况如下:

Exception: An OPC operation failure with error code -1073442759 (0xC0049039) occ urred, originating from 'OpcLabs.EasyOpcRaw.DataAccess.RawEasyDAClient'. The inn er exception contains details about the problem. Inner Exception: No method available to convert ProgID to CLSID.

如果我尝试使用 CLSID

ServerDescriptor("\\xxx.xxx.xxx.xxx\{F8582CF2-88FB-11D0-B850-00C0F0104305}", networkSecurity);

异常变为:

Exception: An OPC operation failure with error code -2147024891 (0x80070005) occ urred, originating from 'OpcLabs.EasyOpcRaw.DataAccess.RawEasyDAClient'. The inn er exception contains details about the problem. Inner Exception: Access is denied.

"Inner Exception: Access is denied",这意味着您必须在服务器和客户端之间启用 DCOM 通信。用于服务器应用程序和 OPCEnum 服务(用于将 ProgID 转换为 CLSID)。

https://www.google.com/search?q=dcom+configuration+for+opc