Gerasim_V_Gerasimov
Posts: 2
Joined: Wed Aug 04, 2021 2:37 pm

UART /dev/ttyAMA0/ is tearing the respond out of chunks

Wed Aug 04, 2021 3:47 pm

i'm reading responds from some modbus rtu devices.
Environment:
Raspberry: CM3+, Pi 4 Model B, Pi 3 Model B
Node.js (version from 10 to 14)
node-serialport lib (version from 8 to latest)

I'm watching repeated distinction of behavior in virtual vs hardware UARTs.

Normar behavior (as i need): one request - one respond
Image

Strange behavior: one request - several chunks of one respond
Image

In my case, i need, the reaction of hardware ttyAMA0 should be like as virtual ttyUART1.
Where can i tuning up the ttyAMA0 behavior?

cleverca22
Posts: 4345
Joined: Sat Aug 18, 2012 2:33 pm

Re: UART /dev/ttyAMA0/ is tearing the respond out of chunks

Wed Aug 04, 2021 4:30 pm

you just need to add more buffering

the usb device has a high latency, and by the time the host issues a read, the buffer has built up an entire packet
depending on random chance, you may read when partial data is in the buffer, and youll get the same effect as on ttyAMA0

your best solution is to just wait for more data, assemble the chunks, and then parse the whole thing

Gerasim_V_Gerasimov
Posts: 2
Joined: Wed Aug 04, 2021 2:37 pm

Re: UART /dev/ttyAMA0/ is tearing the respond out of chunks

Wed Aug 04, 2021 5:25 pm

cleverca22 wrote:
Wed Aug 04, 2021 4:30 pm
you just need to add more buffering
Do you think, the CP2103 ASIC is buffering the device respond?
Is hardware UART FIFO's size not customizable?

Return to “Interfacing (DSI, CSI, I2C, etc.)”