Hydro
Topic Author
Posts: 1
Joined: 16 Oct 2023, 02:53
Answers: 0

Inquiry about delay when received from RS485 port

16 Oct 2023, 03:45

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
Answers: 2

Re: Inquiry about delay when received from RS485 port

17 Oct 2023, 07:57

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: 856
Joined: 21 Jun 2018, 10:33
Answers: 7
Location: Berlin
Contact:

Re: Inquiry about delay when received from RS485 port

17 Oct 2023, 09:09

Thanks for the Hint, Kees. In order to make this setting permanent I'd use a udev rule:
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
Answers: 2

Re: Inquiry about delay when received from RS485 port

17 Oct 2023, 09:14

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

Who is online

Users browsing this forum: No registered users and 1 guest