两个进程在linux上侦听同一个串行端口



我有一个串行端口/dev/ttyS0,它可以持续传输数据。

我已经有一个正在运行的进程P1,它监听串行端口并处理数据。该进程无法自定义为侦听另一个串行端口。

我正在构建一个python脚本,只监听相同的数据并存储输出。如果我直接连接到串行端口,那么P1将不会得到任何数据,因为我的脚本已经读取了它

如何在不中断到P1的传输的情况下嗅探数据?

有人提到o可以使用命名管道,但我不知道如何使用。

感谢Marcos G.提供的链接,我研究了socat命令,最终使用https://github.com/danielinux/ttybus如用例1中所述。它似乎旨在解决某些场景,这些场景可以通过socat解决,但方式更简单。

Use case 1
Multiplexing serial input only or output only device attached to /dev/ttyS0, for use with multiple applications.
1. Create a new tty_bus called /tmp/ttyS0mux:
tty_bus -d -s /tmp/ttyS0mux
2. Connect the real device to the bus using tty_attach:
tty_attach -d -s /tmp/ttyS0mux /dev/ttyS0
3. Create two fake /dev/ttyS0 devices, attached to the bus:
tty_fake -d -s /tmp/ttyS0mux /dev/ttyS0fake0
tty_fake -d -s /tmp/ttyS0mux /dev/ttyS0fake1
4. Start your application and force it to use the new serial device for input or output
/bin/foo /dev/ttyS0fake0 &
/bin/bar /dev/ttyS0fake1 &
Both application will read (or write) from the same serial device.
CAUTION: All data written on each of the two fake devices will be echoed on the other one too.

最新更新