hylasoft-usa / h-opc

OPC client made simpler, for UA and DA
MIT License
300 stars 144 forks source link

Connect to local DA Server #48

Closed johnmurphy01 closed 7 years ago

johnmurphy01 commented 7 years ago

I am trying to connect to a local OPC DA server. The server is created by Matrikon's Server for Simulation and Testing. I am trying to connect using the C# implementation as outlined by the Read.me file but the status consistently returns a status of NotConnected.

If I use the CLI, I am able to connect with no problems.

Here's my code in C#:

using (var client = new DaClient(new Uri(OpcConstants.OPC_DA_HOST_URL)))
{
    if (client.Status == Hylasoft.Opc.Common.OpcStatus.Connected)
    {
        // monitor for a specific tag
        client.Monitor<string>("Random.String1", (newValue, unSubscribe) =>
        {
            System.Diagnostics.Debug.WriteLine("Value of the.string is: " + newValue);
        });
    }
}

The value of OpcConstants.OPC_DA_HOST_URL is opcda://localhost/Matrikon.OPC.Simulation.1

For the CLI, I am running h-opc-cli.exe da opcda://localhost/Matrikon.OPC.Simulation.1

I know this question has been asked a few times, but I think the issue is specifically with the C# implementation. Any help would be appreciated

johnmurphy01 commented 7 years ago

Never mind, I just had to call client.Connect(). Dumb mistake on my part. But possibly that should be included in the Read.me

jmbeach commented 7 years ago

@johnmurphy01 I'll add it to the Readme in the next change. Glad you got it figured out.