Question

I want to read some data using pyserial and then send the output to a C program using subprocess.

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).

How do I get it so that I can write the result of ser.read() to the C program?

How do I interpret or use that input?

Was it helpful?

Solution

Write to stdin of Popen. It's a file object.

process.stdin.write(ser.read())
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top