Home

All documentation about the Autabee Opc Communication!

Autabee Opc Communicator

The autabee opc communicator is a rapper for the opc ua client c# library. It is made with the intention of making de development of an opc client easier. the whole scope of this repository has 4 parts:

FAQ

How can I connect to an OPC Server?

in the case that you have an opc ApplicationConfiguration you can use the following code:

var logger = new Logger();
var client = new Autabee.Communication.ManagedOpcClient(GetConfig(),logger);

await client.Connect("opc.tcp://localhost:4840");

Otherwise use the following code:

public async Task<> ConnectToServer()
{
    var logger = new Logger();
    string company = "company that the client is from";
    string product = "name of the client";
    string directory = "directory there the config need to be saved";
    var client = new Autabee.Communication.ManagedOpcClient(company,
                        product,directory,logger);
    
    await client.Connect("opc.tcp://localhost:4840");
    return client;
}

How can I read a node?

There are multiple ways but the 2 main are either via NodeId or NodeEntry.

NodeId in opc is the address of a value on the server. This can easily be called as followed:

var result = await client.ReadNode("ns=2;s=Demo.Dynamic.Scalar.Boolean");
var result = await client.ReadNode(new NodeId("ns=2;s=Demo.Dynamic.Scalar.Boolean"));

However when you are using a string based address you can request to get a registered node id. using this node for reading is slightly faster when you repeatedly call that node id. This is where NodeEntry comes in. As they store both the unregistered and the registered node id for you. So when you call a node multiple times you can use the registered node id to speed up the process. These nodes come in the flavors: - MethodNode: a node that is used to call a method on the server - ValueNode: a node that is used to read or write a value on the server

Warning A ValueNodeEntry is for one connection only. There is a reconnect register procedure build in. So when you reconnect it registers a new registered Id. So this mean that if you want to read a node on 2 different connections you need to use 2 ValueNodeEntry’s, one or each connection. (with current implementation)

To read a node using a NodeEntry you can use the following example:

var entry = new ValueNodeEntry<bool>("ns=2;s=Demo.Dynamic.Scalar.Boolean");
client.RegisterNode(node);

public async Task ReadNode()
{
    var result = await client.ReadNode(entry);
}

How can I subscribe to a node?

First you need to create a subscription. This can be done as followed:

var intervalInMilliSeconds = 1000;
var subscription = await client.CreateSubscription(intervalInMilliSeconds);

Then you can add a node to the subscription. using either a string, NodeId or NodeEntry. This can be done as followed:

await client.AddMonitoredNode(subscription, node, EventHandler);

where eventHandler is a function that is called when the value of the node changes. This function has the following signature for string and nodeIds:

public void EventHandler(MonitoredItem sender, object e);
{
    // do something with the value
}

for NodeEntry’s the signature is as followed:

public void EventHandler(MonitoredItem sender, NodeValueRecord e)
{
    // do something with the value
}

What is Opc Sharper good for?

In a lot of cases opc sharper is not needed as you have access to a UA-ModelCompiler Model.xml. However, when you don’t. For instance, when you have a PLC first development approach the tooling does not generate a model. So to prevent error due to string error. Opc Sharper is made to generate the models instead. Mainly for generating types and methods for getting the correct node addresses.

The sharper is build into the opc scout. So when you are connected to a server. you can use the sharper to generate the code for you. This code can then be used within your own project.

Why do we use Serilog?

It’s a great logging framework that is easy to use and has a lot of options. It’s also easy to extend. And since this is the logging tool of choice for the company it originally is made for, we kept it in.

How do I run Opc Scout?

There are multiple ways to run the opc scout. The easiest way is to run it via docker. This can be done with the following docker-compose file:

version: '3.3'
services:
    opcscout:
        volumes:
            - scoutdata:/app/data
        ports:
            - 8000:80
        image: autabee/opcscout:beta
volumes:
    scoutdata:

This will run the opc scout on port 8000.

However not everyone is able to run containers. So there is also a way to run it locally. This can be done by either downloading the latest release from here or by building it yourself. When you have the files you can run the following command:

dotnet run --project src/Autabee.OpcScoutWeb/AutabeeOpcScoutWeb.csproj

or (only tested on windows)

dotnet run --project src/Autabee.OpcScoutApp/AutabeeOpcScoutApp.csproj