Attention

You are viewing an older version of the documentation. The latest version is v3.3.

Application #2: CODESYS OPC UA Publish/Subscribe

The following section is applicable to:

../../_images/target1.png

The OPC UA Publish/Subscribe Example makes use of the CODESYS Software PLC and the ECI Edge Control Protocol Bridge to showcase bridging OPC UA Client/Server Model to OPC UA Publish/Subscribe Model. In this example topology, the EC Protocol Bridge establishes a connection as an OPC UA client to the CODESYS Linux Runtime OPC UA server. Data on this OPC UA client/server protocol is bridged to an OPC UA publish/subscribe protocol, which the EC Protocol Bridge makes available.

Prerequisites
  • EC Protocol Bridge - Make sure that the EC Protocol Bridge is installed. For more information, refer to Install Edge Control Protocol Bridge.

  • A Windows system (x64 bit) to host the CODESYS IDE

  • A target system with the CODESYS Linux Runtime installed (See Install CODESYS Linux Runtime)

  • Ability to modify IP address of both the Windows PC and target system

  • Ability to connect both the Windows PC and target system via Ethernet network

Note: If the CODESYS IDE has not yet been installed on a Windows system, follow the section Install CODESYS IDE to install the CODESYS IDE. For more information on CODESYS, refer to CODESYS Software PLC

Attention

This CODESYS example project was created and validated using CODESYS V3.5 SP17 Patch 2 + (64-bit). Project compatibility differences may occur when changing CODESYS version.

../../_images/codesys_version.png

Deploying CODESYS Application

The following section is applicable to:

../../_images/windows2.png
  1. Use the Intel edgesoftware utility to download the ECI release archive, if not done already.

  2. Copy the CODESYS_Example_Applications.zip archive from the ECI release archive (release-eci_#.#.zip) to the Windows system. This archive is located in the ECI release archive within the Edge-Controls-for-Industrial directory as follows:

    └── Edge-Controls-for-Industrial
        ├── Codesys_Example_Applications.zip
        ├── Dockerfiles.tar.gz
        └── eci-release.tar.gz
    
  3. Extract the CODESYS_Example_Applications.zip archive. Navigate to the OPCUA directory. Double-click ec-protocol-bridge_Linux_3.5.x.x.project to open the project with CODESYS.

  4. When the project is first loaded, a message on failing to load library references might be displayed. Click OK. You will install these dependencies later.

    ../../_images/011.jpg
  5. A dialog listing newer library versions will be displayed. If you prefer, you may update to the suggested versions. Performing the update will not break the project.

    ../../_images/021.jpg
  6. When prompted to upgrade the storage format, click Yes. It is recommended to use the format suggested by CODESYS.

    ../../_images/031.jpg
  7. When the project opens, you may see a (?) mark next to Device (CODESYS Control for Linus SL) in the Devices pane. If this occurs, right-click Device (CODESYS Control for Linus SL) and select Download missing device description from the pop-up menu.

    ../../_images/041.jpg

    Follow the prompts to install the missing device.

    ../../_images/051.jpg
  8. At this point, compile to assess the missing libraries. Follow the menu path Build > Build.

    ../../_images/061.jpg
  9. After a build, the Messages tab (typically located at the bottom of the IDE) will display an error count. If there are any errors, it might be because of missing libraries. Double-click Library Manager from the Devices pane. A Library Manager tab will open in the right pane. You might need to expand the IDE window to see the buttons available in this tab. Click Download Missing Libraries.

    ../../_images/071.jpg
  10. A dialog will list the missing libraries. Make sure that all missing libraries are checked and click Download.

    ../../_images/081.jpg
  11. At this point, there might still be missing libraries (due to installation order dependency). Click Download Missing Libraries, if the button is still available.

    ../../_images/091.jpg
  12. A dialog will list the missing libraries. Make sure that all missing libraries are checked and click Download.

    ../../_images/101.jpg
  13. If Download Missing Libraries disappears, you are ready to rebuild the project. Follow the menu path Build > Build.

    ../../_images/111.jpg
  14. If all dependencies are installed, the build should complete without errors. Make sure that Messages tab shows zero errors. Close the Library Manager tab.

    ../../_images/12.jpg
  15. Double-click Ethernet from the Devices pane. You should see “eno1” listed as Interface, 192.168.255.12 listed as the IP address, and 255.255.255.0 listed as Subnet mask. The CODESYS Linux runtime residing on the target system (with ECI installed) will use this IP address.

    Attention

    If your system uses an Interface other than eno1, make sure to update the Interface used by the Ethernet device in the CODESYS project.

    ../../_images/13.jpg
  16. Connect the Windows PC and the target system together via an Ethernet network. Use the Ethernet port that corresponds to the Interface used in the previous step.

  17. Modify the IP address assigned by Windows for the relevant Ethernet interface. Use the IP address “192.168.255.10” and subnet mask “255.255.255.0”.

    ../../_images/14.jpg
    ../../_images/15.jpg
  18. You might also need to modify the Windows firewall to allow traffic to CODESYS from private networks. Open the Allowed apps and features firewall dialog and make sure that CODESYS and CODESYScontrol Service are selected. If the Windows PC and target system are connected correctly, you should be able to ping each system from the other.

    ../../_images/16.jpg

    The following steps are applicable to:

    ../../_images/target2.png
  19. On the target system, restart the CODESYS Linux runtime:

    $ sudo systemctl restart codesyscontrol
    

    Verify that the CODESYS Linux runtime is active (running):

    $ sudo systemctl status codesyscontrol
    

    The output should report active (running):

    ● codesyscontrol.service - LSB: Prepares and starts codesyscontrol
         Loaded: loaded (/etc/init.d/codesyscontrol; generated)
        Drop-In: /usr/lib/systemd/system/service.d
                 └─10-override-protect-proc.conf
         Active: active (running) since Thu 2022-09-01 01:50:45 UTC; 2s ago
    

    If the output does not report active (running), then repeat the process of restarting and checking the runtime.

    Tip

    Isolated incidences of compatibility issues with +12th Generation Intel CPUs and CODESYS have been observed. See Limitation #6 - Cannot start CODESYS Linux runtime for potential mitigation actions.

    The following steps are applicable to:

    ../../_images/windows2.png
  20. In the CODESYS IDE, double-click Device (CODESYS Control for Linux SL) from the Devices pane. Click Scan Network… to probe for active CODESYS servers.

    ../../_images/17.jpg
  21. The Select Device dialog should list the a device named intel-rt-corei7-64…. Select this device and click OK.

    ../../_images/18.jpg
  22. When connecting to a device for the first time, you might be prompted to activate user management on the device. Click Yes to continue.

    ../../_images/19.png
  23. Add a device user which will be used to access the device. Remember the name and password, as this will be used again in later steps.

    ../../_images/20.png
  24. CODESYS will attempt to authenticate with the new device. At this time, do not try to authenticate. Click Cancel when prompted.

    ../../_images/21.png
  25. If a connection was established to the device, a green circle will appear next to it. At this point, click the Device drop-down menu and click Change Communication Policy….

    ../../_images/22.png
  26. In the Device User Logon dialog, enter the user name and password registered earlier.

    ../../_images/23.png
  27. By default, CODESYS does not allow anonymous OPC UA clients to connect to the OPC UA server. Modify the setting to allow anonymous login, so that the EC-Protocol Bridge can connect to the CODESYS OPC UA server. Select Allow anonymous login, then click OK.

    ../../_images/24.png
  28. Follow the menu path Online > Login.

    ../../_images/25.jpg
  29. If there is a warning related to version mismatch, ignore the warning and click OK.

    ../../_images/26.jpg
  30. When you are logging into the CODESYS Linux runtime for the first time, a message will appear indicating that no application exists on the target device. Click Yes to download the application.

    ../../_images/27.jpg
  31. After the application has completed uploading to the CODESYS Linux runtime, follow the menu path Debug > Start.

    ../../_images/28.jpg

    If everything is correct, green indicators will appear next to various components as shown in the following figure.

    ../../_images/291.jpg

    The following steps are applicable to:

    ../../_images/target2.png
  32. On the target system, run the Edge Control Protocol Bridge to bridge OPC UA client/server protocol to OPC UA publish/subscribe protocol.

    $ /opt/ec-protocol-bridge/plg-opcua-rt/examples/codesys/startDemo.sh
    
    1. The script will ask you to connect the PC to a network. This was done in an earlier step, so press Enter.

    2. The script will then prompt you to select an interface. Enter the number that corresponds to the Interface configured in the earlier steps (this example uses Interface “eno1”).

    3. The script will ask if you would like to use the default IP address “192.168.255.12”, enter y. If you are using a different IP address, enter n and input your address when prompted.

    The following steps are applicable to:

    ../../_images/windows2.png
  33. Open a web browser on the Windows PC and navigate to: http://192.168.255.12:8080. You should see the Visualization hosted by the CODESYS Linux runtime. You may rotate the dial to vary the value sent to the OPC UA client.

    ../../_images/codesys-example.gif

    Note: The CODESYS Linux runtime is free to use without a license, however it will automatically stop execution after two hours. Additionally, OPC UA client functionality is limited to only thirty minutes, after which the OPC UA client will not function. If you want to use CODESYS Linux runtime beyond these time limit, you will need to purchase a license. For information on licensing CODESYS, refer to License CODESYS Linux Runtime.

  34. If the CODESYS Linux runtime stops running due to the two-hour time limit, restart the runtime:

    $ systemctl restart codesyscontrol
    

    To run the CODESYS Linux runtime beyond two hours, you must purchase a license from the CODESYS Webstore. Refer to CODESYS Linux Runtime for various licensing options for CODESYS.