I am trying to transmit a constantly changing 5 digit value over serial, to fake this I have a program called jsfake
int main() {
while (1) {
printf("02000\n");
fflush(stdout);
sleep(1);
}
return 0;
}
Then i have my actual python script which is designed to transmit the stdout from the C program over serial. I have then added a section on the bottom to receive the serial as well as I am testing it from one raspberry pi to the same one, so I can be sure it is working before trying to receive it from another computer.
from serial import Serial
import subprocess
subp = subprocess.Popen("./jsfake",stdout=subprocess.PIPE)
port = Serial("/dev/ttyAMA0",115200,timeout=3)
while True:
for line in iter(subp.stdout.readline, ''):
port.write(line)
if port.inWaiting!=0:
rcv = port.read(6)
print rcv
However my code waits at the line for line in iter(subp.stdout.readline, ''):
as this is the point it is always at when I interrupt it with ctrl-c. However it prints no values.
EDIT:
I have tried replacing the last 4 lines with print line
and print line.rstrip()
but neither generate any values either.