×

CODESYS OPC-UA

Generate a text file using the 'File->Export->Codesys DUT' feature that contains Data Unit Types (DUTs) that are suitable for import into CODESYS. One DUT per application will be created. Each application will have its own DUT, but all DUTs will be exported in the same file.
 
Text File with DUTs
 
To use the exported file, in CODESYS, create a DUT of type STRUCT for each application. Right click the 'Application' item in the tree view and choose 'Add Object-> DUT'.
 
Create DUT
 
 Name the DUT the same value as in the TYPE declaration for the application. In the example above, the DUT would be named 'GF01_GasFlow_v1_4'.
The DUT must have the same name as the TYPE to avoid an error.
 
Copy and paste a TYPE from the generated text file into the new DUT and save the DUT object. This will create a single DUT for each app.
 
DUT from Copied Text
 
Next, create a globally scoped tag from the DUT. Right click on the 'Application' object in the tree view and select 'Add Object->Global Variable List'. Name the new item 'GVL'
The name of the Global Variable List (GVL) must match the name of the GVL in the application's 'OPC UA Global Variable List'  parameter in its 'Overall Settings' group.
 
Create Global Variable List
 
In the GVL, create an instance of the DUT. The name of the tag can be whatever you want, but must match the tag name in the application's 'PLC Tag Name' parameter in its 'Overall Settings' group. In the example below, we have name the instance 'GF01'.
Set the value of the 'PLC Tag Name' parameter in PLC Shift to the same value as the name of the tag in the global variable list.
 
GVL - Create Tag from DUT
 
Next, use the newly created tag in code somewhere. If you don't do this, then the tag will be trimmed from the project and will not appear in the 'Symbol Configuration' object. In the screen grab below, we have assigned values to the dp, sp and temp values in the GF01 tag. In an actual system, these values would be likely be assigned to analog inputs.
 
Use Tag in Program
The DUT tag must be used somewhere in the project or it will not appear in the 'Symbol Configuration' object in CODESYS.
 
Open the 'Symbol Configuration' object and open the symbol details using the button in the 'Members' column with the ellipses. Select all the members of the DUT as shown below. This makes the tag available via OPC-UA. PLC Shift can read and write tag members at runtime.
 
Symbol Configuration
 
Ensure that the runtime security policy allows for anonymous login. Start by opening the Change Runtime Security Policy window from the device communications settings. Then check the 'Allow anonymous login' option at the bottom of the new window.
 
Change Runtime Security Policy Menu
 
Change Runtime Security Policy Window
 
Verify that the 'Anonymous_OPCUAServer' user has permissions in the 'Remote Connections' section under the 'Runtime Objects' folder.
 
Remote Connections User Permissions
 
If Symbol Sets are enabled, as shown in the screen grab below, then the  'Anonymous_OPCUAServer' user needs to have permissions enabled on specific symbol sets. If Symbol Sets are not enabled, then nothing needs to be done.
 
Enable Symbol Sets
 
Set Symbol Rights
 
Write the updated configuration with new tags to the PLC.
 
When configuration OPC-UA security, sometimes a complete download or a restart of the Codesys runtime is required to get the settings to take effect.
 
In PLC Shift, set the value of the 'OPC UA Node ID' parameter in the 'Device Settings' group to the name of the application. For Opto 22 Devices, the default value of '|var|Opto22-Cortex-Linux.Application' is usually okay. For generic Codesys systems, the node ID is usually the type of hardware that you are using. For example, in the tree view from Codesys below, the device is named 'CODESYS Control for Raspberry Pi MC SL' which would make the OPC UA node ID '|var|CODESYS Control for Raspberry Pi MC SL.Application'.
 
Codesys Node ID for OPC UA
 
As of December 2023, it does not seem that the Node  ID can be changed via the development environment. The node ID must be changed by editing a text file on the remote device as described in this Codesys forum post: https://forge.codesys.com/forge/talk/Engineering/thread/cb5a492aa0/
 
Change Node ID for Codesys Runtime