Inquiry about delay when received from RS485 port

Topics about the Software of Revolution Pi
Post Reply
Hydro
Posts: 1
Joined: 16 Oct 2023, 02:53

Inquiry about delay when received from RS485 port

Post by Hydro »

I have created a program to communicate with another device using serial communication via RS485 and run it on the RevPi.
Summary of the program
The program is written in C and uses a select function to repeatedly detect and read incoming messages from another device.

Please let me know if there is a solution to the following problem.
・It takes about 20ms for a received message from another device to be updated in the device file, which is a larger delay than expected.
  ・It takes about 20 ms before the select function detects the reception.
・When reading immediately after reception is detected, all data (100 bytes) sent from another device is in the device file, and the message written from the device driver to the device file at one time is larger than expected.
  ・Is the received data buffered in the device driver?

Environment
・RevPiConnectSE (RevPi Buster Lite (01/2023) (ID: 6568))
・Port used: RS485 (dev/ttyUSB0)
・Baud rate: 562500
kjkoster
Posts: 87
Joined: 12 Feb 2022, 10:42

Re: Inquiry about delay when received from RS485 port

Post by kjkoster »

Dear Hydro,

Not sure it is the same for you, but we have solved a similar issue reading from load cells via serial. We found we had to set /sys/bus/usb-serial/devices/ttyUSB0/latency_timer to 1 for better performance.

This gets overwritten on boot, so you need some way to make that setting survive reboots. We use docker-compose to set it for us.

This is not a Revolution Pi issue, I would think. Better look on the general Raspberry Pi forums for this type of question.

Hope this helps.

Kees Jan
User avatar
nicolaiB
KUNBUS
Posts: 931
Joined: 21 Jun 2018, 10:33
Location: Berlin
Contact:

Re: Inquiry about delay when received from RS485 port

Post by nicolaiB »

Thanks for the Hint, Kees. In order to make this setting permanent I'd use a udev rule:

Code: Select all

cat <<EOX | sudo tee /etc/udev/rules.d/90-ftdi-latency-timer.rules
ACTION=="add", SUBSYSTEM=="usb-serial", DRIVER=="ftdi_sio", ATTR{latency_timer}="1"
EOX
Make sure to reboot the Connect afterwards.

Nicolai
kjkoster
Posts: 87
Joined: 12 Feb 2022, 10:42

Re: Inquiry about delay when received from RS485 port

Post by kjkoster »

Dear Nicolai,

Great idea. You'd only need a way to make this setting survive full reset, for example if you move the code to another Revolution Pi instance.

We actually have a check in the code that throws an error on startup when latency_timer has not been set to 1. Not ideal, but at least the system does not slow down inexplicably after an RMA.

Kees Jan
Post Reply