-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlog-discharge.py
50 lines (35 loc) · 900 Bytes
/
log-discharge.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
import serial
import time
import DL24
load = DL24.DL24(serial.Serial('/dev/ttyUSB0', 9600))
load.resetStats()
load.setCutoffVoltage(2.8)
load.setTargetCurrent(0.3)
load.setTimer(None)
log = open("log.csv", "a")
log.write("time,seconds,voltage,current,capacity")
log.write("\n")
start = time.time()
load.enable()
while True:
try:
values = [
load.getTime(),
int(time.time() - start), # Can be calculated from time but just more convenient to use
load.getVoltage(),
load.getCurrent(),
load.getCapacity()
]
def text(v):
if v is None:
return ''
else:
return str(v)
row = ",".join(map(text, values))
log.write(row)
log.write("\n")
print(row)
except:
print("Error reading sample")
time.sleep(10)
log.disable()