-
Notifications
You must be signed in to change notification settings - Fork 0
/
uart.py
42 lines (32 loc) · 1.19 KB
/
uart.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
# No longer in use, but at some point this was used to generate `interrupt` signals
# using a UART Tx pin. It was found too inaccurate and was replaced with the
# Digital Analog Discovery instead.
from serial import Serial
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("-o", "--outfile", type=str, required=True)
parser.add_argument("-p", "--platform", type=str,
choices=['FlexPRET', 'nrf52', 'RP2040', 'RPi'],
required=True)
args = parser.parse_args()
if args.platform == 'FlexPRET':
receive_serial = Serial('/dev/ttyUSB0', baudrate=115200, exclusive=True, timeout=0.01)
elif args.platform == 'nrf52':
receive_serial = Serial('/dev/ttyACM0', baudrate=115200, exclusive=True, timeout=0.01)
elif args.platform == 'RP2040':
receive_serial = Serial('/dev/ttyUSB0', baudrate=115200, exclusive=True, timeout=0.01)
else:
pass
done = False
file = ""
while True:
received = receive_serial.read(256).decode('utf-8')
if 'Done' in received:
done = True
if done:
if len(received) > 0:
file += received
elif done:
break
with open(args.outfile, 'w') as f:
f.write(file)