How to Monitor Data on a Serial Port in Linux

How can I monitor data on a serial port in Linux?

strace is very useful for this. You have a visualisation of all ioctl calls, with the corresponding structure decoded. The following options seems particularly useful in your case:

-e read=set

Perform a full hexadecimal and ASCII dump of all the data read from
file descriptors listed in the
specified set. For example, to see all
input activity on file descriptors 3
and 5 use -e read=3,5. Note that this
is independent from the normal tracing
of the read(2) system call which is
controlled by the option -e
trace=read.

-e write=set

Perform a full hexadecimal and ASCII
dump of all the data written to file
descriptors listed in the specified
set. For example, to see all output
activity on file descriptors 3 and 5
use -e write=3,5. Note that this is
independent from the normal tracing of
the write(2) system call which is
controlled by the option -e
trace=write.

Check if there's incoming data in serial port linux (cbInQue for linux)

Yes, you will need your file descriptor and then use FIONREAD to see if anything is available.

Something like the following should work:

int available;
if( ioctl( fd, FIONREAD, &available ) < 0 ) {
// Error handling here
}

Reading data from the serial port of a STM32 using the Linux terminal

Your loop says "as long as it is not possible to send a byte, repeatedly try to send it anyway, as soon as it is possible to send a byte, discard it without sending"

Change:

       while (USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET)
USART_SendData(USART2, Data);

To:

       while (USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);
USART_SendData(USART2, Data);

Reading from Linux serial port using C++ provides messy data

The issue was in wrong way opening serial ports. So I took opening code from this question and now everything works fine:

How to open, read, and write from serial port in C?

Thank you guys @JD_GRINDER and @sawdust for giving me right direction!

How to pass display output to serial port under Linux?

It's certainly feasible. The easiest way to do this is just to put a "getty" process on the serial terminal, which is sometimes done by editing /etc/inittab (there will be some examples in there) and then you will see a login prompt via the serial terminal and use all (command-line) programs normally. Historically, Unix machines did this as their primary way of working.

Another option is to use the "serial console", which involves passing some boot-time parameters to the kernel; this is only required if you want to see its startup messages on the serial port.


Edit: On newer Linux distributions, it's not so easy to put "getty" on a serial line, presumably because it's such an old-fashioned thing to do. Outside of embedded devices, pretty much nobody uses serial ports to log in to the system any more (most modern PCs don't even HAVE rs232 ports). For example, Fedora and Ubuntu do not use "init", but something else which doesn't have inherent support for running "getty". There is probably a way of doing it but I don't know what it is; consult your distributuon's documentation.

No data sent over serial port in linux c++

Turns out it was an arduino problem all along. I needed to apply some usleep to let arduino bootload



Related Topics



Leave a reply



Submit