Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send file over serial port from Python

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.

like image 876
RRWW Avatar asked Sep 26 '22 22:09

RRWW


1 Answers

import serial
s = serial.Serial("/dev/ttyAMA0")
s.write(open("target.txt","rb").read())
like image 134
Joran Beasley Avatar answered Oct 11 '22 11:10

Joran Beasley