Why is dd waiting for more data after reading 38 bytes?
Asked by
ink on fingertips
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!
Answers
Have you tried pulling from `/dev/zero` instead of ttyUSB0? This will likely show whether dd works as expected without the UART complexities involved.
Reply to this answer
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.
Reply to this answer
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.
ink on fingertips: 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.
Reply to this answer
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.
ink on fingertips: Nope, my setup uses start (0x01) and end (0x04) delimiters, but for dd, it seems to ignore those and just goes for the bytes.
Reply to this answer
Add your answer
Answers are reviewed before publication.
ink on fingertips: 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`.