Is there any port monitoring tool to watch the packets written on the port? I especially want to check if my program written in Java works so I need some kind of tool to see if my little application is writing the messages to the port. How do I do this?
socat is a tool to connect (nearly) everything to (nearly) everything, and tee can duplicate streams.
In your usecase you could connect your serial port
/dev/ttyS0 to a PTY
/tmp/ttyV0, then point your application to the PTY, and have socat
tee out Input and Output somewhere for you to observe.
Googling "socat serial port pty tee debug" will point you to several examples, one being:
socat /dev/ttyS0,raw,echo=0 \ SYSTEM:'tee in.txt |socat - "PTY,link=/tmp/ttyV0,raw,echo=0,waitslave" |tee out.txt'
out.txt will then contain the captured data.
This has been confirmed to work by commenters (@ogurets).
I don't think the serial driver has any tracing functionality that would allow you to watch packets. You can use
strace to observe all the reads and writes from your application:
strace -s9999 -o myapp.strace -eread,write,ioctl ./myapp
When I debug interaction of my application with a serial port, I use moserial.
screen /dev/tty.usbserial-blahblah 9600
works for me.
interceptty does that job:
interceptty /dev/ttyACM0 /dev/ttyDUMMY
or, with a nice output format and with configuring the backend device, and with line buffering:
interceptty -s 'ispeed 19200 ospeed 19200' -l /dev/ttyACM0 /dev/ttyDUMMY | interceptty-nicedump
and then connect with your programme to
Have a look at ttyUSBSpy. It is on alpha stage, but it works.
minicom is missing from the list of tools to monitor serial ports. Use it as for example to listen to arduino device:
minicom --device /dev/ttyACM0 --baud 9600