How to setup simple OPC UA Server in B&R AS

How to setup simple B&R OPC UA Server from the scratch.

In this exercise I’ll use latest available AS v.4.12.5.95:

image-20240417160358490

Start with new Project

image-20240417160539302

Step by step:

image-20240417161325716

Everything by default

image-20240417160908709

Select Standard PC here:

image-20240417161014197

If you’re lucky, then the project is created and online in Run State:

image-20240417161641067

Add Global variable (later this Variable will be mapped to OPC UA Node):

image-20240417161927994

Who said that the Globals are bad?!

I’ll change name to “Counter” and keep default type, which is USINT (which is uint8).

image-20240417162303901

Don’t confuse with BYTE Type, this is something different in B&R Interprepation!

Now I’ll add C Program. Just drag and drop to MyOPC_UA:

image-20240417162637108

I prefer “All in One” Template. The changes I’ll made very simple:

image-20240417162849317

Whole program:


#include <bur/plctypes.h>

#ifdef _DEFAULT_INCLUDES
	#include <AsDefault.h>
#endif

void _INIT ProgramInit(void)
{
	Counter = 0;
}

void _CYCLIC ProgramCyclic(void)
{
	if (255 == Counter) Counter = 0;
	else Counter++;
}

void _EXIT ProgramExit(void)
{

}

Now time for first build:

image-20240417163119690

and transfer to the target:

image-20240417163201324

and transfer

image-20240417163244915

If you’re still lucky, you will see running counter:

image-20240417163402184

The counter incremented once per second, because by default your Program automatically inserted into 1000ms cycle:

image-20240417163932374

Now time to turn ON OPC Server, this can be done here:

image-20240417164047034

It is OFF by default, needs to be switched to ON:

image-20240417164154890

By default Security Policies will prohibit Authentication without security, I’ll allow for my exercises

image-20240417164328297

Keep rest by defaults:

image-20240417164457876

Now we must add mapping:

image-20240417164633151

The variable is available, but disabled:

image-20240417164740532

You have to enable it:

image-20240417164817329

and rebuild:

image-20240417164905872

Now this Node is appeared in UA Expert:

In the Tree located here:

image-20240417165733887

That is. Now you can connect to this server with NI OPC UA Toolkit as shown below:

(The NodeID can be obtained from UA Expert):