RevPi RS485 config for use in CodeSys

PVCS
Posts: 1
Joined: 17 Apr 2024, 07:46

RevPi RS485 config for use in CodeSys

Post by PVCS »

Hello RevPi world,

My colleague and I are currently evaluating the Revolution PI Connect 4 as a controller based on CodeSys.
The system image is installed as delivered.

We plan to use the RS485 interface in CodeSys and have tested the original CodeSys sample project for the SysCom library as a template.
Unfortunately, we cannot get a valid handle for the underlying COM port.

Searching the Internet, there were various hints as to what (or what not) to enter in the two files CODESYSControl.cfg and CODESYSControl_User.cfg.....
Unfortunately, we were unsuccessful.

Hence the question:
What should be entered in the CodeSys*.cfg files so that the RS485 interface can be used as COM1, for example? The physical connection is located here under /dev/ttyRS485 sym link /dev/ttyAMA5.
User avatar
dirk
Posts: 2271
Joined: 15 Dec 2016, 12:19

Re: RevPi RS485 config for use in CodeSys

Post by dirk »

Traveller0765
Posts: 8
Joined: 15 Apr 2024, 05:34

Re: RevPi RS485 config for use in CodeSys

Post by Traveller0765 »

Hello PVCS,

I am working at the same problem trying to get Modbus RTU running on codesys with a fresh RevPi Connect 4.
Up to now it was not possible for me to establish connection to the RS485 interface. But maybe we can share our findings and get ist running together.

You wrote that you use the image as delivered. On my RevPi te image Bullseye RevPi Bullseye 64-bit was installed as delivered. But as per this article 64-bit image is not supported for CODESYS.
https://kunbus-gmbh.atlassian.net/servi ... 2687893508

To get the examples running it looks like we have to change the image to a 32-bit version. Furthermore there it is neccessary to enter following code to the /etc/CODESYSConfig_User.cfg:

For CODESYS Control for Raspberry Pi MC SL - 4.10.0.0 or higher
[SysFile]
PlaceholderFilePath.2=/etc/revpi, $configrsc$

On the other hand Kunbus offers a new Codesys library that supports 64-bit which is still in BETA. I think the Release will be soon, maybe end of this month.
viewtopic.php?t=4293

But to use this library it can run only with CODESYS Control for Linux ARM SL. In this case the 64-bit image can stay on the RevPI.
When using this library the entry into /etc/CODESYSConfig_User.cfg should be:

[SysFile]
PlaceholderFilePath.1=/etc/revpi, $configrsc$

For the entry into the CODESYS*.cfg for accessing the RS485 I am also confused by different posts.
Accoding to the tutorial it should be
Linux.Devicefile=/dev/ttyUSB
But im my opinion USB are the On-Board USB ports.

According to this post viewtopic.php?t=3484 (German) Kunbus mentioned, that the entry should be /dev/ttyRS485. And user Inoak wrote it must be Linux.Devicefile.1=/dev/ttyRS485 (Why .1?)

In another post I found the entry
[SysCom]
/dev/ttyAMA
Also this entry sounds for me plausible, because /dev/RS485 is sym linked to /dev/ttyAMA5.

Looking into the CODESYSControl_User.cfg there is already an entry
[SysCom]
Linux.Devicefile=/dev/ttyS
but I don't know what this entry means.

Maybe someone from Kunbus support can leave some comments on this findings and can tell us the exact entry into the CODESYS*.cfg.
I guess the entry must be done in the CODESYSControl_User.config and not in the CODESYSControl.cfg like said in the tutorial.

I hope I could give you some information more on our common problem. Next week I will do further tests to get it running. Maybe we can share our results.

Best regards
Wolfgang
User avatar
nicolaiB
KUNBUS
Posts: 1135
Joined: 21 Jun 2018, 08:33
Location: Berlin

Re: RevPi RS485 config for use in CodeSys

Post by nicolaiB »

Not much a CODESYS expert, but the correct device is /dev/RS485 which is a symlink to the effective serial device. The effective serial devices differ between different RevPi types, so make sure to use the symlink.

There is also the beta of our CODESYS library, which finally supports 64-bit systems. The new library version also works with the native CODESYS arm runtime which works with the new license model. Maybe you can give it a shot? Customer feedback looks good so far and we will probably release it in May (among support for latest CODESYS V3.5 SP20).

See viewtopic.php?t=4293

Nicolai
Nicolai
User avatar
Amar
KUNBUS
Posts: 200
Joined: 15 Jul 2019, 10:58

Re: RevPi RS485 config for use in CodeSys

Post by Amar »

Hello PVCS,

Under General->Serial Port Configuration tab of MODBUS_COM device in codesys tree
COM Port selected will be as follows

/dev/ttyUSB0 -> COM Port 1
/dev/ttyUSB1 -> COM Port 2 ...
/dev/ttyUSBn -> COM Port n

In /etc/CODESYSControl_User.cfg you can try configuring following:

Code: Select all

[SysCom]
Linux.Devicefile=/dev/ttyAMA
Try using port 6. If it does not work, try port 5 also.
codesys modbus.png
You can check out example ModbusTCP-RTU-Master which is however for Connect 3/S

Lastly it may be perhaps CODESYS needing COM description in /dev/ttyUSB* format in /etc/CODESYSControl_User.cfg

For this you can try creating following symlink:
/dev/ttyUSB5 -> ttyAMA5

In /etc/CODESYSControl_User.cfg you can configure:

Code: Select all

[SysCom]
Linux.Devicefile=/dev/ttyUSB
And then try with port 6 or 5 if it works.

Please let us know your findings accordingly.

Regards, Amar
You do not have the required permissions to view the files attached to this post.
KUNBUS
Traveller0765
Posts: 8
Joined: 15 Apr 2024, 05:34

Re: RevPi RS485 config for use in CodeSys

Post by Traveller0765 »

After several trials I was not able to get Modbus communication running on CODESYS (V3.5.20.0) with RevPi Connect 4 and the delivered 64bit image. So, I changed my setup like described in the CODESYS Checklist.
https://kunbus-gmbh.atlassian.net/servi ... 2687893508

Finally I got it working.

My new setup:
- RevPi Bullseye 32-bit (02/2024) (ID: 7792)
- CODESYS Development System V3.5.19.0
- Revolution Pi Library for CODESYS V1.4.1.0 (ID: 7530)
- CODESYS Control for Raspberry Pi 4.10.0.0 (ID: 7533)

CODESYSControl.cfg:
[SysCom]
Linux.Devicefile.1=/dev/ttyRS485

CODESYSControl_User.cfg:
[SysFile]
PlaceholderFilePath.2=/etc/revpi, $configrsc$

In CODESYS the Com-Port will be COM1.
Screenshot 2024-04-24 100812.png
Regards
Wolfgang
You do not have the required permissions to view the files attached to this post.
User avatar
Amar
KUNBUS
Posts: 200
Joined: 15 Jul 2019, 10:58

Re: RevPi RS485 config for use in CodeSys

Post by Amar »

Hello Wolfgang and PVCS,
Modbus RTU with Connect 4 on 64 bit image shall work with following settings:

Configure COM port default interface for Connect4 in /etc/CODESYSControl_User.cfg
running CODESYS Control for Linux ARM64 SL

Code: Select all

[SysFile]
PlaceholderFilePath.1=/etc/revpi, $configrsc$

[SysCom]
Linux.Devicefile=/dev/ttyAMA
In CODESYS project, the COM port 6 will have to be used
2024-04-25 13_37_03-ModbusRTU_Connect4.project - CODESYS.png
You can check out a sample Modbus RTU application for Connect 4 on 64bit image running CODESYS Control for Linux ARM64 SL
2024-04-25 13_25_46-ModbusRTU_Connect4.project_ - CODESYS.png
Example:
ModbusRTU_Connect4.zip
Additional comment:
In Connect 4, the RS-485 port is linked to ttyAMA5 using symlink
/dev/ttyRS485 -> ttyAMA5

In Connect 3, the RS-485 port is linked to ttyUSB0 using smbolic link
/dev/ttyRS485 -> ttyUSB0

Regards, Amar
You do not have the required permissions to view the files attached to this post.
KUNBUS
compera24
Posts: 8
Joined: 03 Nov 2025, 09:17

Re: RevPi RS485 config for use in CodeSys

Post by compera24 »

I have a similar Problem but with a revpi Connect 5. The solutions here didn`t work for me. In the lost Comment Amar mentioned the symlinks differ by revpi 3 and 4 i wonder if they differ again by 5. And it seems like Codesys switched also the Naming from Master/slave to Client/Server in the meantime. So i wonder if they change something else to, what causes the Problems. (The Dokumentation for the example Projekts seems generally outdatet and unaccurate alittle to vague)
User avatar
Amar
KUNBUS
Posts: 200
Joined: 15 Jul 2019, 10:58

Re: RevPi RS485 config for use in CodeSys

Post by Amar »

Hello,
Thank you for pointing out the status of documentation for RS-485 configuration in CODESYS.

When using Bookworm image or later
Add following lines in /etc/codesyscontrol/CODESYSControl_User.cfg

Code: Select all

[SysCom]
Linux.Devicefile =/dev/ttyRS485-
Under General/Serial Port Configuration tab of the MODBUS_COM device in the CODESYS tree the COM Port will be selected as follows:
/dev/ttyRS485-0 -> COM Port 1 (Connect S/SE, Connect 4, Connect 5, Falt S (first RS-485 port)
/dev/ttyRS485-1 -> COM Port 2 (2nd RS-485 port of Flat S )

Regards, Amar
KUNBUS
compera24
Posts: 8
Joined: 03 Nov 2025, 09:17

Re: RevPi RS485 config for use in CodeSys

Post by compera24 »

So With my RevPi 5 i wrote: Linux.Devicefile=/dev/ttyRS485-0 under the [SysCom] but it didnt Work. (Modbus shows red triangle and says that is not working ( with Com-Port 1 and also with 5)
With Linux.Devicefile=/dev/ttyAMA it seems to work better. The Triangle switches between Yellow and Red (For Com.Port 5) instead of beeing permanently red (all other comports and versions i tryt)
The error messages are as following: Die Lizenz fehlt oder ist ungültig. Die SPS läuft im Demo-Modus. (engl.: Lizenz is missing, run in Demo mode), Läuft nicht | Der Fehler wurde bereinigt (engl.: Not running. The error has been fixed).

So at the moment im a little confused. But sadly i see now way to avoid Modbus for the use case i need it for at the time (like i did at another point). So i continue to search for the cause or atleast narrow it down more.
I find the codesys lizenz modell a little bit confusing but i thing this is no problem at this point because there should be the 30 min demo for Modbus. And the warning is referenzing to it. And i don't want to buy lizenzes if im not sure if it is working than.