-
Notifications
You must be signed in to change notification settings - Fork 0
/
SRTest.py
128 lines (107 loc) · 3.68 KB
/
SRTest.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import serial
import time
from collections import deque
from decimal import Decimal
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(self.port, baudrate=self.baudrate, timeout=self.timeout)
self.read_items = deque()
def start(self):
self.box.flushInput()
self.box.flushOutput()
self.box.write(b'\x61')
time.sleep(0.1)
self.box.write(b'\x62')
time.sleep(0.1)
self.box.write(b'\x64')
time.sleep(0.1)
self.box.write(b'\x68')
time.sleep(0.1)
self.box.write(b'\x70')
time.sleep(0.1)
self.box.write(b'\xA0')
def stop(self):
self.box.flushInput()
self.box.flushOutput()
self.box.write(b'\x20')
self.box.write(b'\x70')
time.sleep(0.1)
self.box.write(b'\x68')
time.sleep(0.1)
self.box.write(b'\x64')
time.sleep(0.1)
self.box.write(b'\x62')
time.sleep(0.1)
self.box.write(b'\x61')
def read_indiv(self, ignore_blank=True):
self.start()
self.read_items = deque()
start = time.perf_counter()
last = time.perf_counter()
counter = 0
while counter <= 15000:
current = time.perf_counter() - start
inchar = self.box.read(1)
if True: #if inchar != b'':
counter += 1
if counter % 770 == 0:
print(current - last)
print(current)
last = current
print()
#if time.perf_counter() - last >= 1:
# print(counter)
# print(current)
# last = time.perf_counter()
# print()
self.read_items.append((counter, current, inchar))
self.stop()
def read_test(self):
self.read_items = deque()
self.start()
start = Decimal(time.perf_counter())
last = start
counter = 0
diffs = []
while counter <= 16000:
if counter == 0:
start = Decimal(time.perf_counter())
last = start
inchar = self.box.read(1)
if inchar != b'':
counter += 1
curr = Decimal(time.perf_counter())
diffs.append(curr - last)
last = curr
stop = Decimal(time.perf_counter())
self.stop()
print('Total time: ', Decimal(stop-start))
print('Avg B/s: ', Decimal(counter) / Decimal(stop-start))
return diffs
def __del__(self):
self.box.close()
del self.box
def read_chunk(self, ignore_blank=True):
self.start()
start = time.perf_counter()
counter = 0
checks = 0
prev_waiting = 0
while counter <= 15000:
if checks % 150000 == 0:
print(self.box.in_waiting, 'in waiting')
checks += 1
if time.perf_counter() - start >= 10:
print('Reading...')
chunk = self.box.read(5000)
for inchar in chunk:
if ignore_blank and inchar == b'':
continue
else:
counter += 1
self.read_items.append((counter, (counter*1/800), inchar))
start = time.perf_counter()
self.stop()