Integrate RevPiLib into CODESYS

CODESYS is a development environment for programmable logic controllers (PLC).  We have created a library for CODESYS so that you can also use it in your RevPi projects.

In this tutorial we have prepared a sample project in which you will learn the first steps and how to integrate RevPiLib into CODESYS.

With the download you confirm these conditions:

The RevPiLib Codesys Library is experimental and for testing purposes only,
because this is not a finished product.
Therefore please note that we cannot offer you support for the RevPiLib Codesys Library.
Using the RevPiLib Codesys library is at your own risk.

http://media.kunbus.de/media/support/RevPi.Codesys.Lib.zip

The “CODESYS Development System” is free of charge. You can use it to set up your project.

“CODESYS Control for Rapberry Pi SL” is a runtime system. The use of this system is subject to a fee. More detailed information can be found on the CODESYS website.

Prerequisites::

  • Windows-PC
    • The PC is on your network
    • You have installed CODESYS Development System V3 on it.
    • You have downloaded “CODESYS Control for Raspberry Pi SL”.
  • RevPi Core/Connect
    • Is located in your network
    • You know the IP address of your RevPi

Create a new project

Open CODESYS Development System.

  • Click on “File”.
  • Click on “New Project”.

 

The following window opens:

  • Select an “empty project” from the templates.
  • Enter a file name.
  • Select a storage location.

Install CODESYS Control runtime system on the RevPi

  • Click on “Tools”.
  • Click on “Package Manager”.

  • Click on “Install”.

  • Select “CODESYS Control for Raspberry Pi SL”. You already downloaded this package during the preparations.
  • Click on “Open”.
  • An installation dialog opens.
  • Follow the installation steps.

If the package was successfully installed, it appears in the Package Manager under “Already installed packages”:

 

  • Now you can transfer the runtime system to the RevPi.
  • Click on “Tools”.
  • Click on “Update Raspberry Pi”.

The following window opens:

  • Enter your credentials and the IP address of your RevPi module.
  • Select the desired package version.

  • Click Install.

Select control type

  • Right-click on your project. You will find it in the “Devices” window.
  • Click on “Attach device”.

  • Select “CODESYS Control for Raspberry Pi” with a double click.

  • Various components have now been imported into your project:

Install RevPiLib

    • Click on “Tools”.
    • Click on “Package Manager”.

      • Click on “Install”.

  • Select „RevPiLib.package“ .
  • When the installation is complete, the library is available under “Target -> RevPi”. To be able to use it, you have to add it to the project.

  • Open the library manager with a double click.
  • Click on the “Add library” tab.

  • Click on “Extended”.
  • Click on “Target”.
  • Click on “Other”.
  • Click on “RevPi”.
  • Select “Revolution Pi IO Module Interface”.
  • Click on “Ok”.

The library is now in your project. You can use it now. In the following section we will explain you how to do this with an example.

Using RevPiLib in your project

  • Right-click on “Application”.
  • Click on “Add Object”.
  • Click POU (Program Organizational Unit).
  • The following window opens:

For this example we use the implementation language “Continuous Function Chart” (CFC).

  • Click on the “Add” button.

You have now created a program organizational unit. It contains the source code of your program.

  • Click with the right mouse button on “Application”.
  • Click on “Add object”.
  • Click on GVL (Global Variable List).
  • Enter an object name.
  • Click on “Add”.

We generate the required contents for the variable list from PiCtory.

  • Open PiCtory.

Assemble the following devices on the Configuration Board:

      • RevPi Core or Connect
      • RevPi DIO

  • Click on “File”.
  • Click on “Export”.

The following window opens:

Select the export type e04.json . This export contains ST compliant definition of global variables with initial values.

  • Click on “Show Only”.
  • Click on “Ok”.

  • The following window opens:

  • Copy the variables.
  • From now on it’s back to CODESYS:
  • Switch the view of the GVL to the “Textual view”.

  • Paste the variables from PiCtory here.

Note!

As soon as the configuration is changed in PiCtory the configuration has to be exported again and copied to the Global Variable List.

Now that we have all the data we need to work, we can fill the POU object with function blocks.

  • Open the POU.
  • The work area is divided into the following windows:

      1. Tools
      2. Variable declaration
      3. Routing
  • Drag the function block “Block” from the “Tools” window to the “Routing” window.
  • Click on the question marks above the block.

  • Select the block REVPI_CPI_IN FB from the RevPiLib.

  • Enter a name for the function module.

  • In this way, you also create these function modules
      • REVPI_PIDI
      • REVPI_PIDO
      • RPI.REVPI_CPI_OUT
  • Set the correct execution sequence. You can see the current order in the upper right corner of the function module. You can change the order by right-clicking on the function module.

The function modules REVPI_PIDI and REVPI_PIDO need an offset. We created this offset by exporting it to PiCtory and copying it to the Global Variable List.

  • Drag the function block “Input” from the “Tools” window into the “Routing” window.
  • Select the global variable for this block.

  • Use the mouse to connect the input blocks to the offset pins.
  • Use the mouse to connect input In_01 of function module DI to output Out_01 of function module DO.

This is how your result should look like:

Creating a Task

In order to run the POU program we need the “Task” object. In this object you can set conditions for starting the task and calling the task.

  • Click with the right mouse button on “Application”.
  • Click on “Add object”.
  • Click on “Task configuration”.
  • Double click on the Task.
  • Click on “Add call”.

  • Select the created POU.

The program is now called up cyclically.

Installing the project on the RevPi

  • Click on “Create”.
  • Click on “Translate”.

  • Select “CODESYS_Control_forRaspberry_Pi” in the project tree with a double click. This selects the RevPi device on which we want to load the project.

  • Click on “Browse Network”.

Your RevPi will now be displayed.

  • Select the RevPi and click “OK”.

  • Click on”Online”.
  • Click on “Login”.

  • The project is now loaded to the RevPi.

It is possible that not all translation information is available. In this case you will get the following error message:

  • Confirm with “Yes”.

If your control is in “Stop” mode, you can set it to “Run” mode with the “Start” button or the F5 key.

Our small example program now runs on the RevPi module. If you now apply 24 V to input 1 of the DIO, the state of the input is copied to the output and output 1 is switched to “High”.