SlimLine Raspberry use CODESYS

CODESYS is an IEC 61131-3 development environment used by many industrial automation companies that allows programming using the 5 languages ​​required by the standard. To install the CODESYS development IDE on your PC, download it for free from manufacturer's store, look for the entry "CODESYS Development System V3".

Once the IDE installation is complete, you need to add the Raspberry target and download the installation package for free from manufacturer's store. The downloaded version allows you to run the program in demo mode for 2 hours. To use it without limits you need to purchase the license. From the menu Tools-Programma di installazione CODESYS execute package installation, it is installed in the “C:Users/Username/CODESYS Control for Raspberry PI".

CODESYS control installation screenshot for Raspberry

Run-Time installation

To install the run time CODESYS on the Raspberry device access the menu Tools-Update Raspberry Pi from which it can be installed or upgraded. You need to define the default login credentials (Username: pi Password: raspberry) and the IP address of the system to be updated as well as the folder where the run time "C:Users/Username/CODESYS Control for Raspberry PI".

Return to this article for using the library eCDSS8CoreMng which allows access to extension modules. In this article the use of WebVisu for the creation of web pages is illustrated.

CODESYS Update Raspberry screenshot

Device configuration

After the installation of the run time module hardware devices must be configured.

Serial ports configuration

RS485 serial port

If the device SlimLine has RS485 serial port, the port is connected to the port ttyAMA of the Raspberry CPU module, in order to use it from the CODESYS environment, identifying it as COM1, is needed in the file /etc/CODESYSControl_User.cfg change the item [SysCom] as shown below. Device is specified ttyAMA even if the device is ttyAMA0.

[SysCom]
;Linux.Devicefile=/dev/ttyS
Linux.Devicefile=/dev/ttyAMA

Add serial port on USB

Using forms USB / Serial additional serial ports can be connected to the USB port of the module, in the case of a port to be used as an alternative to ttyAMA identifying it as COM1, the entry needs to be changed [SysCom] as shown below. Device is specified ttyUSB even if the device is ttyUSB0.

[SysCom]
;Linux.Devicefile=/dev/ttyS
Linux.Devicefile=/dev/ttyUSB
CAN bus configuration

If the device SlimLine has a CAN bus port, in order to use it from the CODESYS environment it is necessary in the file /etc/CODESYSControl_User.cfg add the entry [CmpSocketCanDrv] as indicated:

[CmpSocketCanDrv]
ScriptPath=/opt/codesys/scripts/
ScriptName=rts_set_baud.sh 

Place the rts_set_baud.sh file with the following content in the / opt / codesys / scripts / folder:

#!/bin/sh BITRATE=`expr $2 \* 1000`
ip link set $1 down
ip link set $1 type can bitrate $BITRATE
ip link set $1 up

execution  run time CODESYS

Installed on run time it is possible to execute or stop it with the program codesyscontrol from the folder /etc/init.d.

  • To run the run time use command sudo /etc/init.d/codesyscontrol start
  • To stop the run time use command sudo /etc/init.d/codesyscontrol stop
  • To set automatic execution sudo update-rc.dcodesyscontroldefaults followed by sudo reboot
  • To eliminate automatic execution sudo update-rc.d -f codesyscontrol remove followed by sudo reboot

Creation of a new project

To create a new project to run on SlimLine choose Nuovo progettoselect Progetto standard, and set as a device CODESYS Control for Raspberry Pi.

Screenshot of the new CODESYS project

By default, a project is created that has only one POU (Program organization unit) program called "PLC_PRG”Written in ST language. The program is inserted in the MainTask and executed cyclically every 4 mS. To set the execution parameters of the task double click on the name.

Now let's write the instructions for incrementing a counter variable. Even if this is not the place to explain the programming, let's see briefly what is done. The variable is declared Cnt of type UINT (integer to 16 bits) and in the body of the program the variable is incremented at each execution loop.

Screenshot of creation of new CODESYS POU

Program execution

To run the program on SlimLine it is necessary to connect to the system and transfer it, the connection is made via Ethernet, it is necessary to make sure that the device is in the same network as the PC. Double-clicking on the device icon opens the setting window, executing the command Scan all devices found on the network will be displayed and you can connect to the one you want.

CODESYS scan network screenshot

Acting on the key Login the program will be compiled and transferred to the system by pressing the button Run you can run it. The CODESYS IDE is a very advanced environment, positioning the cursor on a program line and acting with the right mouse button it is possible to insert brakpoints in which execution stops allowing you to execute the program step-by-step. Positioning the mouse on the variable definition it is possible to force its value.

Performing the Logout it is possible to modify the program which at the next login will be transferred to the hot system, ie without stopping its execution. The ability to modify the program with hot loading is very important in automation because it allows you to make changes in programs that manage complex sequences without stopping and / or losing the state in which the system is located.

Screenshot running CODESYS program
Was this article helpful?