Why is dd waiting for more data after reading 38 bytes?

0
0
Asked By CuriousCoder93 On

I'm working on sending a 38-byte string from a device to my PC over UART, and I've got stty set up correctly with 9600 8n1. I'm using the command `dd if=/dev/ttyUSB0 bs=1 count=38` to read the incoming data, but after it successfully receives the 38 bytes, it continues to wait for more data instead of terminating. As a temporary fix, I added a timeout of 1 second, which seems to solve my issue, but I'm really curious about why dd behaves this way. Shouldn't it just finish after reading those 38 bytes? Any insight would help!

4 Answers

Answered By DataDude44 On

Does the UART protocol require a string terminator? Sometimes they look for things like CR (carriage return), LF (line feed), or NULL characters to signal the end of transmission.

CuriousCoder93 -

Nope, my setup uses start (0x01) and end (0x04) delimiters, but for dd, it seems to ignore those and just goes for the bytes.

Answered By TechGuru77 On

You might want to try adding the `iflag=fullblock` option to your dd command: `dd if=/dev/ttyUSB0 bs=1 count=38 iflag=fullblock`. This usually helps it behave more reliably when reading from devices.

CuriousCoder93 -

I'll give the fullblock flag a shot! It's a new idea for me. I did run some tests, and it feels more stable, but I'm still using the timeout just in case the data isn't what I expect. I'll also hook up an oscilloscope to check if the 38 bytes are consistent or if I'm picking up some noise.

Answered By TerminalNinja On

Just a thought, but have you checked the terminal settings? It’s important to ensure that options like -icanon, -isig, and -istrip are not causing issues.

Answered By ByteBandit101 On

Have you tried pulling from `/dev/zero` instead of ttyUSB0? This will likely show whether dd works as expected without the UART complexities involved.

CuriousCoder93 -

That sounds interesting! I’ll run the `dd` command using `/dev/zero` and see if it terminates as expected after 38 bytes. I'll even use strace to check if it reads correctly: `strace -e read dd if=/dev/zero bs=1 count=38 iflag=fullblock`.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.