7

I'm able to convert my serial device output to hex format doing these two commands:

cat /dev/ttyUSB0 > data.dump #send some data to serial device, and interrupt cat using Ctrl+C after some time
xxd data.dump

It gives me output like:

00000000: 80ff ffff ffff ffff ffff ffff ffff       ..............

But I want to do that in one command, to see live data stream, but neither of these commands works for me:

cat /dev/ttyUSB0 | xxd
xxd /dev/ttyUSB0
hexdump /dev/ttyUSB0

These commands gives me no output at all, what is the problem here? I'm using zsh shell, and working on fedora OS.

bladekp
  • 279
  • 1
  • 3
  • 7

1 Answers1

1

Reading from /dev/ttyUSB0 is unfortunately not so simple. This solution on the Unix & Linux SE site worked best for me.

stty -F /dev/ttyUSB0 115200 raw -echo   #CONFIGURE SERIAL PORT
exec 3</dev/ttyUSB0                     #REDIRECT SERIAL OUTPUT TO FD 3
  cat <&3 > /tmp/ttyDump.dat &          #REDIRECT SERIAL OUTPUT TO FILE
  PID=$!                                #SAVE PID TO KILL CAT
    echo "R" > /dev/ttyUSB0             #SEND COMMAND STRING TO SERIAL PORT
    sleep 0.2s                          #WAIT FOR RESPONSE
  kill $PID                             #KILL CAT PROCESS
  wait $PID 2>/dev/null                 #SUPRESS "Terminated" output

exec 3<&- #FREE FD 3 cat /tmp/ttyDump.dat #DUMP CAPTURED DATA

Jim Fell
  • 6,099