[英]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.