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

Python linux上侦听同一串行端口的两个进程,python,linux,serial-port,named-pipes,sniffer,Python,Linux,Serial Port,Named Pipes,Sniffer,我有一个串口/dev/ttyS0,它一直在传输数据 我已经有一个正在运行的进程P1,它侦听串行端口并处理数据。 无法自定义该进程以侦听另一个串行端口 我正在构建一个python脚本,以便只侦听相同的数据并存储输出。 如果我直接连接到串行端口,则无法获取任何数据,因为我的脚本已经读取了数据 如何在不中断到P1的传输的情况下嗅探数据 有人提到o可以使用命名管道,但我不确定如何使用。多亏了链接Marcos G。前提是我查看了socat命令并最终使用了用例1中描述的管道。这似乎是为了解决某些可以通过so

我有一个串口/dev/ttyS0,它一直在传输数据

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

我正在构建一个python脚本,以便只侦听相同的数据并存储输出。 如果我直接连接到串行端口,则无法获取任何数据,因为我的脚本已经读取了数据

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


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

多亏了链接Marcos G。前提是我查看了socat命令并最终使用了用例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.

这是一个老问题,已经有很多答案了。看看你是否觉得有用。我不认为你能用python直接或轻松地做到这一点。@markos-g我试着运行命令
sudo socat-d-d pty,link=/dev/ttyS0,raw,echo=0 pty,raw,echo=0,link=/home/panos/ttyPort1
,但即使创建了虚拟帖子,我的脚本甚至没有连接到它,因为它报告
权限被拒绝/home/panos/ttyPort1
您可能需要以su身份运行或将用户添加到拨号中group@markos-在运行相同的socat命令之前,我重新启动并停止了侦听实际串行端口的进程,然后更改了与现在所在端口相同的权限“根”组而不是拨号。现在新进程运行,但不从虚拟串行端口获取任何数据(即使主进程终止).对不起,我不知道什么是错的,也许你可以编辑你的问题,包括你对socat做了什么,什么是错的?试着复制我上面链接的答案上的步骤,我来看看。