-
Notifications
You must be signed in to change notification settings - Fork 0
/
SRTester.py
55 lines (42 loc) · 1.47 KB
/
SRTester.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
51
52
53
54
55
import serial
import time
from collections import dequeu
class SRTester():
def __init__(self, port=None, baudrate=19200, timeout=0):
self.port = 'COM1' if port is None else port
self.baudrate = baudrate
self.timeout = timeout
self.box = serial.Serial(port, baudrate=baudrate, timeout=timeout)
self.read_items = deque()
def start(self):
self.box.flushInput()
self.box.flushOutput()
self.write(b'\xA0')
def stop(self):
self.box.flushInput()
self.box.flushOutput()
self.write(b'\x20')
def read_indiv(self, ignore_blank=True):
self.start()
self.read_items = deque()
start = time.monotonic()
counter = 0
while counter <= 15000:
inchar = self.box.read(1)
current = time.monotonic() - start
if ignore_blank and inchar == '':
continue
counter += 1
self.read_items.append((counter, current, inchar))
self.stop()
def read_chunk(self, ignore_blank=True):
self.start()
start = time.monotonic()
while counter <= 15000:
if time.monotonic() - start >= 10:
chunk = self.box.read(5000)
for inchar in chunk:
if ignore_blank and inchar == '':
continue
counter += 1
self.read_items.append((counter, (counter*1/800), inchar))