Pan*_*kis 2 python linux serial-port named-pipes sniffer
我有一个串口/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.
Run Code Online (Sandbox Code Playgroud)