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

前端 未结 5 1350
忘掉有多难
忘掉有多难 2021-01-30 14:07

I\'m debugging communications with a serial device, and I need to see all the data flowing both directions.

It seems like this should be easy on Linux, where the serial

5条回答
  •  后悔当初
    2021-01-30 15:04

    A simple method would be to write an application which opened the master side of a pty and the tty under test. You would then pass your tty application the slave side of the pty as the 'tty device'.

    You would have to monitor the pty attributes with tcgetattr() on the pty master and call tcsetattr() on the real tty, if the attributes changed.

    The rest would be a simple select() on both fd's copying data bi-directionally and copying it to a log.

提交回复
热议问题