RevPi RS485 config for use in CodeSys

Post Reply
PVCS
Posts: 1
Joined: 17 Apr 2024, 09: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
KUNBUS
Posts: 2174
Joined: 15 Dec 2016, 13:19

Re: RevPi RS485 config for use in CodeSys

Post by dirk »

Traveller0765
Posts: 8
Joined: 15 Apr 2024, 07: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: 931
Joined: 21 Jun 2018, 10:33
Location: Berlin
Contact:

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
User avatar
Amar
KUNBUS
Posts: 160
Joined: 15 Jul 2019, 12: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
KUNBUS
Traveller0765
Posts: 8
Joined: 15 Apr 2024, 07: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
User avatar
Amar
KUNBUS
Posts: 160
Joined: 15 Jul 2019, 12: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
(284.68 KiB) Downloaded 1474 times
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
KUNBUS
Post Reply