简体   繁体   English

使用opc .net api连接到远程opc服务器

[英]connect to remote opc server using opc .net api

I'm partly developing opc client application using opc.net api and I have some trouble connecting remote opc server. 我正在部分使用opc.net api开发opc客户端应用程序,但在连接远程opc服务器时遇到了一些麻烦。 Below please see the code I wrote to connect to opc server. 下面请查看我编写的连接到opc服务器的代码。

Opc. URL url = new Opc. URL ( "opcda://network-pc/some-opc-server" );
Opc.Da. Server server = null ;
OpcCom. Factory fact = new OpcCom. Factory ();
server = new Opc.Da. Server (fact, null );
server.Connect(url, new Opc. ConnectData ( new System.Net. NetworkCredential ()));

After executing this code I am getting error: System.Runtime.InteropServices.ExternalException: CoCreateInstanceEx: Access is denied. 执行此代码后,我得到错误:System.Runtime.InteropServices.ExternalException:CoCreateInstanceEx:访问被拒绝。

In addition, both computers are in the same local network, and I can connect to opc server from my computer using third party opc clients. 此外,两台计算机都位于同一局域网中,我可以使用第三方opc客户端从我的计算机连接到opc服务器。

Is there anybody who faced with this kind of issue? 有人遇到这种问题吗? Thanks in advance. 提前致谢。

This may not be your C# source code issue. 这可能不是您的C#源代码问题。 This could be DCOM permission issue. 这可能是DCOM权限问题。 You have to configure DCOM permission based on your OPC Server guidance for client application. 您必须根据针对客户端应用程序的OPC Server指南配置DCOM权限。

Following documents for general reference for OPC and DCOM settings 以下文档可作为OPC和DCOM设置的一般参考

http://www.sytech.com/download/OPC_and_DCOM.pdf http://www.sytech.com/download/OPC_and_DCOM.pdf

http://www.automation.com/pdf_articles/Troubleshooting_OPC_and_DCOM.pdf http://www.automation.com/pdf_articles/Troubleshooting_OPC_and_DCOM.pdf

In addition to the answer from Zin Min, make sure that you are on the same domain. 除了Zin Min的答案外,请确保您位于同一域中。 As cross domain connections are not possible using OPC-DA, without tunnelling of some kind. 如果没有某种隧道,则无法使用OPC-DA进行跨域连接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM