-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstandalone_power.py
130 lines (91 loc) · 3.24 KB
/
standalone_power.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
# ------------------------------------------------------------
# TJ-Monopix2: controlled and reproducible power-up sequence using the HMP4040 power supply
#
# The script is on one hand intended to be run side-by-side other testing-scripts
# as well as a template for scripts that include the power management
#
# The script will tell you when
#
# ------------------------------------------------------------
#
import argparse
import signal
import time
from datetime import datetime
from src.bdaq_supply import PowerManager
from src.monitor import Monitor
parser = argparse.ArgumentParser()
parser.add_argument('--bias', action='store', nargs='*', help='Bias voltage for PSUB/PWELL on CH2 of PS')
parser.add_argument('--hv', action='store', nargs='*', help='Bias voltage for HV on CH3 of PS')
parser.add_argument('-f', action='store_true', default=None, help='accept nonzero Bias and HV at the same time')
parser.add_argument('-p', default='/dev/ttyMP2', help='serial port')
parser.add_argument('-m', action='store_true', default=None, help='enable online monitoring plots of currents '
'(requires gnuplot)')
args = parser.parse_args()
# ========= begin handle ctrl-C =========
def exit_handler(signum, frame):
print("")
exit(0)
signal.signal(signal.SIGINT, exit_handler)
# ========= end handle ctrl-C =========
if args.bias is None:
bias = 0
elif len(args.bias) == 0:
bias = 3.0
else:
bias = float(args.bias[0])
if args.hv is None:
hv = 0
elif len(args.hv) == 0:
hv = 5.0
else:
hv = float(args.hv[0])
if hv == 0 and bias == 0:
print("WARNING: no bias nor HV selected")
elif hv != 0 and bias != 0:
if args.f:
print("WARNING: bias and HV used at the same time")
else:
print("ERROR: bias and HV used at the same time (use -f to ignore this)")
exit(1)
if bias != 0:
print("Bias voltage {:2.1f}V".format(bias))
if hv != 0:
print("HV voltage {:2.1f}V".format(hv))
UP = "\x1B[1A"
CLR = "\x1B[0K"
class CHWrapper:
def __init__(self, name, channel):
self.ch = channel
self.name = name
self.measure()
def measure(self):
self.u = self.ch.measVoltage()
self.i = self.ch.measCurrent()
def print(self):
print(self.name+":")
print(" {:4.2f} V".format(self.u))
print(" {:5.1f} mA".format(self.i*1e3))
print("")
with PowerManager(serial=args.p, bias=bias, hv=hv) as pm:
# ------- begin the testing-payload -------
print("ctrl-C to poweroff again and exit")
chs = []
chs.append(CHWrapper("CH1: BDAQ53 Board", pm.ch_bdaq))
chs.append(CHWrapper("CH2: PSUB/PWELL", pm.ch_bias))
chs.append(CHWrapper("CH3: HV", pm.ch_hv))
chs.append(CHWrapper("CH4: LV supply", pm.ch_chip))
gp = Monitor(args.m)
gp.init()
while True:
currtime = datetime.now().strftime("%H:%M:%S")
print(" "*30, currtime)
for l in chs:
l.print()
time.sleep(0.1)
for l in chs:
l.measure()
gp.add_values(chs[0].i, chs[1].i, chs[2].i, chs[3].i)
gp.plot()
print(UP*(len(chs)*4+2))
# ------- end testing-payload -------