This repository has been archived by the owner on Jan 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeasurement_repeatability.py
64 lines (51 loc) · 1.82 KB
/
measurement_repeatability.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
# -*- coding: UTF-8 -*-
from sys import exit
from time import ctime, time, localtime, sleep
from struct import unpack
from numpy import array
from serial import Serial
# ----------------------------------------------------------------------------
# Constants
BAUDRATE = 115200
TIMEOUT = 5
BUFFERSIZE = 100
READSIZE = BUFFERSIZE*2
BUFFERFORMAT = str(BUFFERSIZE) + 'H'
# ----------------------------------------------------------------------------
# Main
if __name__ == "__main__":
# Read port from keyboard:
port = input("Enter connected port (for example: COM4, COM5, ...): ")
# Start connection:
stream = Serial(port, BAUDRATE, timeout=TIMEOUT)
try:
print(stream.readline().decode())
except: # stop serial communication if something is wrong
stream.flushOutput()
stream.flushInput()
stream.close()
print("Something is wrong with the connection...")
exit()
print("System starting...\n")
timeinfo = array(localtime(0.0), dtype='int32')
timeinfo.tofile("time.info")
# Main loop:
while True:
stream.write('m'.encode())
# Receive:
Vout1 = array(unpack(BUFFERFORMAT,
stream.read(READSIZE)),
dtype='uint16')
Vout2 = array(unpack(BUFFERFORMAT,
stream.read(READSIZE)),
dtype='uint16')
# Save to file:
now = time()
Vout1.tofile("Vout1_" + str(now) + ".dat")
Vout2.tofile("Vout2_" + str(now) + ".dat")
# Display output:
print(ctime(now)
+ "... Measured V_outs:\n%d\n%d\n..."
%(Vout1.mean(), Vout2.mean()))
sleep(60.0)
stop(stream)