-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrecord.py
44 lines (31 loc) · 920 Bytes
/
record.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
import serial
import sys
import time
def main(argv):
"""
After charging, then record sensor data sequentially.
:param argv:
argv[0]: output_file_name
argv[1]: connect_port_name
:return:
"""
_FILENAME = argv[0]
_PORT_NAME = argv[1]
# write data into this file.
fp_out = open(_FILENAME + ".csv", 'w')
# open the port which we entered.
ser = serial.Serial(_PORT_NAME, 9600)
# first some raw data may got some problem, drop it.
for _ in range(20):
ser.readline()
while True:
line = ser.readline().decode()
# retrieve now time
timer = time.strftime("%H:%M:%S", time.localtime())
# "line" has contents.
if line:
fp_out.write(timer + "," + line)
# print at the terminal to debug
sys.stdout.write(timer + "," + line)
if __name__ == '__main__':
main(sys.argv[1:])