carrytiger
carrytiger

Reputation: 103

Connecting to local RSLinx Classic Single Node using OpcNetApi

My C# OPC client uses OpcNetApi and OpcNetApi.Com and is installed on the same machine as RSLinx Classic Single Node.

My client had no problem connecting to RSLinx Classic Gateway, when that version was used on the same machine.

But now that we've replaced Gateway with Single Node, I'm getting the following error sourced from OpcNetApi:

E_NETWORK_ERROR Could not connect to server. Inner Exception: CoCReateInstanceEx: Class is not licensed for use.

I've double checked all DCOM config and I'm using the standard connection code:

fact = new OpcCom.Factory();
server = new Opc.Da.Server(fact, null);
url = new Opc.URL("opcda://localhost/RSLinx OPC Server");
server.Url = url;
server.Connect();

I've also tried:

server.Connect(url, new Opc.ConnectData(new System.Net.NetworkCredential()));

But both give me the same error.

So, the question is: how do I connect to the local RSLinx Classic Single Node from a client running on the same machine using OpcNetApi/OpcNetApi.Com?

We thought that Single Node meant OPC communications are restricted to be on one device, which is what we're doing. . .

Please help!

Upvotes: 1

Views: 3869

Answers (2)

Jeff Roe
Jeff Roe

Reputation: 3206

Googling got me to this question.

My solution ended up being a little different, so I'll add this answer in case it helps someone in the future.

Trying to make a local OPC connection was failing with:

Create Instance Failed: 0x80040112

The problem appeared to be that the call to Connect failed to recognize that we were trying to make a local connection, and it was instead attempting to make a remote connection:

string computer = // get it from somewhere, perhaps getting "127.0.0.1" or "localhost"
string server = "RSLinx OPC Server";
var opcServer = new OpcServer();
opcServer.Connect(computer, server);

Though that really should have recognized that this was a local connection, it didn't. So the solution was to do the following to call a Connect method which is only for local connections.

string computer = // get it from somewhere, perhaps getting "127.0.0.1" or "localhost"
string server = "RSLinx OPC Server";
var opcServer = new OpcServer();
if (computer == "127.0.0.1" || computer == "localhost")
{
    opcServer.Connect(server);
}
else
{
    opcServer.Connect(computer, server);
}

Upvotes: 1

ZbynekZ
ZbynekZ

Reputation: 1608

If you are on a 64-bit machine, the solution may be to force your .NET code to run in a 32-bit process (e.g. by switching the target of the project from AnyCPU to x86, or by using CORFLAGS utility).

If I remember well, RSLinx OPC servers are implemented in a (32-bit) DLL. When they are invoked locally, this DLL expects to be run inside the process of the OPC client. When it detects otherwise, it thinks it is being used remotely (in a wrapper process provided by DCOM), and when not licensed for remote use, gives this error.

When an OPC client is a local 64-bit process, it cannot, however, load the 32-bit DLL, and DCOM creates a wrapper process as well. The poor RSLinx then thinks it runs remotely...

Upvotes: 0

Related Questions