简体   繁体   English

从串行端口Pyserial读取并写入C程序

[英]Pyserial read from serial port and write to C program

I want to read some data using pyserial and then send the output to a C program using subprocess. 我想使用pyserial读取一些数据,然后使用子进程将输出发送到C程序。

Here is my code (in progress): 这是我的代码(进行中):

from serial import Serial
import subprocess
process = subprocess.Popen("./print",stdin=subprocess.PIPE)
ser = Serial("/dev/ttyAMA0",9600,timeout=2)
while True:
    if ser.inWaiting!=0:
        ser.read()

where print is the C program that simply prints the output (a stepping stone to what I actually want to do). 其中print是仅打印输出的C程序(这是我实际想要做的踏脚石)。

How do I get it so that I can write the result of ser.read() to the C program? 我如何获得它以便将ser.read()的结果写入C程序?

How do I interpret or use that input? 如何解释或使用该输入?

Write to stdin of Popen . 写入Popen stdin It's a file object. 这是一个文件对象。

process.stdin.write(ser.read())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM