I'm trying to send a file (a .jpg image in this case) over a serial port.
Currently it works by calling an external script:
subprocess.Popen(['./sendFile.sh','myImage.jpg']).communicate()
where sendFile.sh
is:
cp /home/pi/$1 /dev/ttyAMA0
This method works but is somehow unstable. Sometimes my Python program stops after the transferring the file.
I'm wondering if there's a way to do this in Python instead of calling a script for help? I searched about XMODEM, but it seems like both ends must have it installed. I'm sending the image to a GPRS chip, which doesn't allow me to modify any code on it. So installing something to the receiving end is impossible.
import serial
s = serial.Serial("/dev/ttyAMA0")
s.write(open("target.txt","rb").read())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With