如何解决两个进程在linux上监听同一个串口
我已经有一个正在运行的进程P1,它监听串口并处理数据。 无法自定义该过程以侦听另一个串行端口。
我正在构建一个 python 脚本来只监听相同的数据并存储输出。 如果我直接连接到串行端口,那么 P1 将无法获取任何数据,因为我的脚本已经读取了它。
如何在不中断到 P1 的传输的情况下嗅探数据?
有人提到 o 可以使用命名管道,但我不确定如何使用。
解决方法
感谢 Marcos G. 提供的链接,我研究了 socat 命令并最终使用了用例 1 中描述的 https://github.com/danielinux/ttybus。它似乎旨在解决某些情况可以用 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.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。