-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvoltcraft_readout.py
95 lines (84 loc) · 2.49 KB
/
voltcraft_readout.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
#!/bin/python
import serial
import time
import matplotlib.pyplot as plt
import numpy as np
import pickle
try:
ser = serial.Serial(port='/dev/ttyUSB1',
baudrate=600,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_TWO,
bytesize=serial.SEVENBITS,
timeout=1,
rtscts=False,
dsrdtr=False,
xonxoff=False)
ser.setRTS(False)
ser.setDTR(True)
except serial.SerialException:
print("kon niet verbinden")
ser.close()
raise SystemExit
vals = []
unit = []
mode = []
t = []
t0 = time.time()
i = 0
while True:
try:
ser.write("D".encode("utf-8"))
recv = ser.read(14)
recv = recv.decode("utf-8")
recv = recv.split(" ")
for i,r in reversed(list(enumerate(recv))):
if len(r) == 0:
del recv[i]
mode.append(recv[0].strip())
try:
vals.append(float(recv[1]))
except ValueError:
vals.append(np.nan)
unit.append(recv[-1].split())
t.append(time.time())
i = i + 1
time.sleep(0.5)
except KeyboardInterrupt:
ser.close()
break
except serial.SerialException:
ser.close()
break
except IndexError:
print("Could not parse input. Is the DMM turned on?")
pass
fig, ax = plt.subplots()
ax.grid()
ax.plot([tt-t0 for tt in t],vals)
ax.set_ylabel("Measurement [" + unit[0][0] + "]")
ax.set_xlabel('Time [s]')
ax.set_title("Voltcraft ME-32 readout")
if False:
AVG_SMP = 200
vavg = []
for i in range(0,len(vals)-AVG_SMP,AVG_SMP):
temp = 0
for j in range(AVG_SMP):
temp = temp + vals[i+j]
vavg.append(temp/AVG_SMP)
fig, ax = plt.subplots()
ax.plot([(tt-t0)/60 for tt in [t[i] for i in range(0,len(vals)-AVG_SMP,AVG_SMP)]],vavg)
ax.set_xlabel('Time [min.]')
ax.set_ylabel('Voltage [V]')
ax.set_title('Lead acid battery idle voltage decay')
ax.grid()
fig, ax = plt.subplots()
ax.semilogx([(tt-t0)/60 for tt in [t[i] for i in range(0,len(vals)-AVG_SMP,AVG_SMP)]],vavg)
ax.set_xlabel('Time [min.]')
ax.set_ylabel('Voltage [V]')
ax.set_title('Lead acid battery idle voltage decay')
ax.grid()
pickling_on = open("loodaccu.pickle","wb")
pickle.dump({"vals":vals,"vavg":vavg,"t":t}, pickling_on)
pickling_on.close()