Good. There is a program that configures / dev / ttyS0. It sends messages on this port. Tell me how to listen to incoming and outgoing messages on this port.

cat / dev / ttyS0 only works when I connect the device I want to control and it sends its messages to the port, I see them.

But what my program is trying to send to the port I can not track.

I create a FHandel pointer to the / dev / ttyS0 port, with the necessary settings.

int FHandle; void Uart::Open() { int flags |= O_RDWR | O_NOCTTY; FHandle = open("/dev/ttyS0", flags); if(FHandle == InvalidHandleValue) throw UartExcept; termios newSettings; bzero(&newSettings, sizeof(termios)); cfsetospeed(&newSettings, B9600); cfsetispeed(&newSettings, B9600); newSettings.c_cflag |= CS8; newSettings.c_cflag |= (CLOCAL|CS8|CREAD); newSettings.c_cflag &= ~(CRTSCTS|CSIZE|PARENB); newSettings.c_cc[VMIN] = 0; newSettings.c_cc[VTIME] = 3; newSettings.c_iflag = INPCK | IGNPAR; if(tcsetattr(FHandle, TCSANOW, &newSettings) == -1) throw UartException; } 

In a certain place send buffer

  UInt32 Uart::Write(const Byte *_inputBuffer, UInt32 _bufferOffset, UInt32 _numberOfBytesToWrite) { ssize_t result; if (FWOverlapped == nullptr) result = write(FHandle, _inputBuffer + _bufferOffset, _numberOfBytesToWrite); return (UInt32)result; } 

How to intercept these messages that I send using the program?

Thank you for your time.

  • Do you send yourself and do not know what you are sending? - Sergey
  • one
    You can do a loopback. In the simplest case, when the signal lines are not used, it is enough to close the two contacts TX and RX with each other. In general, the Internet is full of instructions on how to do this. Then all that you write to the port, you'll immediately get back at the entrance of the port. - Sergey

2 answers 2

You can test the program using pseudo-terminals. For example, /dev/pts/* . Details described in Wikipedia .

  • For some reason I do not have these pseudo terminals. - NewSheriff
  • Try searching for / dev / pty * or / dev / pts *. - Vanyamba Electronics

Use the strace utility to view system calls for the program. Filtering by function is possible. For your purpose, it may be enough:

 strace -e write -s макс_длина_буфера программа