-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.py
executable file
·38 lines (33 loc) · 1.14 KB
/
log.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
#!/usr/bin/env python3
"""
Log data from the mcpc to the given save file. This program does not use
environment variables - instead, just pass the values for the MCPC port,
the expected baudrate (if not default), and the savefile. This will
continuously write the raw MCPC data to the file, so it will remain loosely
formatted raw input.
"""
import argparse
import sys
from time import sleep
from serialdevices import MCPC
def main():
"""
Log MCPC data to the save file.
"""
parser = argparse.ArgumentParser()
parser.add_argument('mcpc_port')
parser.add_argument('--mcpc-baud', type=int, required=False, default=115200)
parser.add_argument('save_file', type=argparse.FileType('w'), default=sys.stdout, nargs='?')
parser.add_argument('--period', type=int, required=False, default='1')
args = parser.parse_args()
# Create and configure the mcpc instance.
m = MCPC()
m.connect(port=args.mcpc_port, baudrate=args.mcpc_baud)
f = args.savefile
# Log the raw data indefinitely.
while True:
data = m.get_reading()
f.write(data)
sleep(args.period)
if __name__ == '__main__':
main()