如何用 python 代码替换 socat 代码

问题描述 投票:0回答:0

现在我正在使用子进程在两个虚拟串行端口之间创建通信:

  def socat_runner(self):
      self.socat_subprocess = subprocess.Popen(['socat', '-d', '-d', 'pty,raw,echo=0', 'pty,raw,echo=0'],
                                                             stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
      print("subproc id: ", self.socat_subprocess.pid)
      line = self.socat_subprocess.stdout.readline().decode().strip('\n')
      port_location_in_string = line.find('/dev/pts')
      self.port1 = line[port_location_in_string:]
      line = self.socat_subprocess.stdout.readline().decode()
      port_location_in_string = line.find('/dev/pts')
      self.port2 = line[port_location_in_string:]

我同时使用 port1 和 port2

我会用 python 方法替换这个 cmd 方法

python linux serial-port socat
© www.soinside.com 2019 - 2024. All rights reserved.