CODESYS OPC UA Client API
Product: CODESYS OPC UA Client API SL
Description
The example shows how to use the OPC Client API
library. The sample project contains an OPC UA Server configuration and an OPC UA Client configuration. Server/Client communication takes place via localhost
.
Additional information
Preparation
Connect to the controller. Use the following credentials:
Name:
user1
Password:
user1
The
user1
must be a member of the Administrator group.
Important
You need to use these credentials for the example because the OPC UA Client signs in to the OPC UA Server with this data.
Add the certificates for OPC UA Server and OPC UA Client to the trusted certificates.
The certificate for UaExpert is required only if you want to connect to the OPC UA Server from an external UaExpert instance (for example, to get more server information).
Structure of the project
Server
Server
: (GVL) Defines variables which are used for the symbol configuration of the OPC UA Server.PLC_PRG_Server
: Writes variables toGVL Server
with a cyclical counter.Symbol configuration
: Defines the symbol configuration of the OPC UA Server. It contains all variables and symbols of the GVL server.OPC UA Server in the UaExpert program.
Client
Client
: (GVL) Defines all variables which are published by the subscription. Updated when the subscription is active and the publication is released.UAVars
: (GVL) Defines constants and variables which are used by the client to establish a connection to the OPC UA Server.NamespaceArray (FB)
: Translation table for node IDs which are used on the application side. The function block is prepared only for optional use and is not used in the standard setup of the sample project.PLC_PRG
: Cyclical call of all function blocks used in the OPC UA Client API:Client
,Subscription
,Read
, andWrite
.ValueSet
: Setup of values which are used by theRead
and/orWrite
function blocks.Subscription
: Defines a subscription which publishes all variables of the GVL client.
Testing the project in online mode
Tip
Use a watch list to run the sample project.
Set
PLC_PRG.xEnable
toTRUE
.This allows the
Client
function block to establish a connection to the server.The status of
CONNECTION_STATE
changes toCONNECTED
and theUAClient.xActive
output becomesTRUE
. Now the activation of a subscription, read actions, and write actions is possible.Set
PLC_PRG.xSubscribe
toTRUE
.This allows the
Subscription
function block to create a subscription on the server and publish all values in GVL client variables.Make sure that
xPublishingEnabled=TRUE
so thatSUBSCRIPTION_STATE
becomes active.Set
PLC_PRG.xRead
toTRUE
.This enables a read action which is done by the
Read
function block.Switch
PLC_PRG.xRead
so that a new read action is triggered.Set
PLC_PRG.xWrite
toTRUE
.This enables a write action by the
Write
function block.Switch
PLC_PRG.xRead
so that a new read action is triggered.
System requirements and restrictions
Programming system | CODESYS Development System (version 3.5.18.40 or higher) |
Runtime system | CODESYS Control Win (version 3.5.18.40) |
Add-on components |
|
Note
DOWNLOAD Project