-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathsend_userland.py
45 lines (33 loc) · 1.15 KB
/
send_userland.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import sys
import time
import serial
def send_file(serial_port, baud_rate, file_path):
try:
# Open serial port
ser = serial.Serial(serial_port, baud_rate, timeout=0)
# 65uino Rev 1 delay
time.sleep(1);
# Send Start of Header (SOH) byte (hex 0x01)
ser.write(b'\x01')
# Send binary file
with open(file_path, 'rb') as file:
file_data = file.read()
# Wait for 65uino to get ready for data
time.sleep(0.2)
ser.write(file_data)
time.sleep(0.5) #Closing too fast empties TX buffer without sending
print("File sent successfully.")
finally:
# Close the serial port
ser.close()
if __name__ == "__main__":
# Check if correct number of command line arguments is provided
if len(sys.argv) != 4:
print("Usage: python send_userland.py <serial_port> <baud_rate> <file_path>")
sys.exit(1)
# Extract command line arguments
serial_port = sys.argv[1]
baud_rate = int(sys.argv[2])
file_path = sys.argv[3]
# Call the function to send the file
send_file(serial_port, baud_rate, file_path)