-
Notifications
You must be signed in to change notification settings - Fork 0
/
wisim_arduino_stream.py
50 lines (43 loc) · 1.04 KB
/
wisim_arduino_stream.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
46
47
48
49
50
# -*- coding: utf-8 -*-
import serial
import msvcrt
import time
import datetime
import sys
arg_list = sys.argv[1:]
if len(arg_list) >= 1:
filename = arg_list[0]
else:
filename = 'wisim_arduino_' + datetime.datetime.now().strftime('%Y-%m-%dT%H%M%S') + '.log'
try:
logfile_handle = False
ser = serial.Serial('COM5', 115200, timeout=0.1)
ser.write(b'r') # reset arduino to "waiting for trigger" state
#filename = input("Enter output file name base: ")
logfile_handle = open(filename + '.txt', 'w')
while(True):
try:
if msvcrt.kbhit():
ch = msvcrt.getch()
print(ch)
if ch == b'q':
break
elif ch == b'r':
print('Sending reset command')
ser.write(b'r')
if ser.in_waiting == 0:
time.sleep(0.005)
continue
s = ser.readline().decode('ascii').rstrip() # decode("ascii")
# values = s.split('\t')
if s != '':
print(s)
logfile_handle.write(s + '\n')
except Exception as e:
print(e)
except Exception as e:
print(e)
finally:
if logfile_handle:
logfile_handle.close()
ser.close()