-
Notifications
You must be signed in to change notification settings - Fork 0
/
voltages.py
105 lines (96 loc) · 5.73 KB
/
voltages.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
#!/usr/bin/env python
#
# voltages.py - script to read the frontend electronics bias voltages
# for all of the SiPM readout boards and report the results
# in tabular form, optionally saving them to EPICS.
#
# author: richard.t.jones at uconn.edu
# version: august 17, 2018
import os
import re
import sys
import subprocess
frendaddress = "gluon28.jlab.org:5692::"
readVbias = re.sub(r"voltages.py", r"bin/readVbias", sys.argv[0])
def usage():
print "Usage: python voltages.py [options]"
print " where options may include the following,"
print " -s : save the readback values to EPICS"
sys.exit(1)
fiber_row = {
0x8e: [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5],
0x8f: [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5],
0x90: [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5],
0x91: [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5],
0x92: [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5],
0x93: [1, 2, 3, 4, 5, 1, 2, 3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9e: [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5]
}
fiber_column = {
0x8e: [3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4],
0x8f: [9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 12, 12, 12, 12, 12, 11, 11, 11, 11, 11, 10, 10, 10, 10, 10],
0x90: [15, 15, 15, 15, 15, 14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 18, 18, 18, 18, 18, 17, 17, 17, 17, 17, 16, 16, 16, 16, 16],
0x91: [21, 21, 21, 21, 21, 20, 20, 20, 20, 20, 19, 19, 19, 19, 19, 24, 24, 24, 24, 24, 23, 23, 23, 23, 23, 22, 22, 22, 22, 22],
0x92: [27, 27, 27, 27, 27, 26, 26, 26, 26, 26, 25, 25, 25, 25, 25, 30, 30, 30, 30, 30, 29, 29, 29, 29, 29, 28, 28, 28, 28, 28],
0x93: [33, 33, 33, 33, 33, 32, 32, 32, 32, 32, 31, 31, 31, 31, 31, 36, 36, 36, 36, 36, 35, 35, 35, 35, 35, 34, 34, 34, 34, 34],
0x94: [39, 39, 39, 39, 39, 38, 38, 38, 38, 38, 37, 37, 37, 37, 37, 42, 42, 42, 42, 42, 41, 41, 41, 41, 41, 40, 40, 40, 40, 40],
0x95: [45, 45, 45, 45, 45, 44, 44, 44, 44, 44, 43, 43, 43, 43, 43, 48, 48, 48, 48, 48, 47, 47, 47, 47, 47, 46, 46, 46, 46, 46],
0x96: [51, 51, 51, 51, 51, 50, 50, 50, 50, 50, 49, 49, 49, 49, 49, 54, 54, 54, 54, 54, 53, 53, 53, 53, 53, 52, 52, 52, 52, 52],
0x97: [57, 57, 57, 57, 57, 56, 56, 56, 56, 56, 55, 55, 55, 55, 55, 60, 60, 60, 60, 60, 59, 59, 59, 59, 59, 58, 58, 58, 58, 58],
0x98: [63, 63, 63, 63, 63, 62, 62, 62, 62, 62, 61, 61, 61, 61, 61, 66, 66, 66, 66, 66, 65, 65, 65, 65, 65, 64, 64, 64, 64, 64],
0x99: [69, 69, 69, 69, 69, 68, 68, 68, 68, 68, 67, 67, 67, 67, 67, 72, 72, 72, 72, 72, 71, 71, 71, 71, 71, 70, 70, 70, 70, 70],
0x9a: [75, 75, 75, 75, 75, 74, 74, 74, 74, 74, 73, 73, 73, 73, 73, 78, 78, 78, 78, 78, 77, 77, 77, 77, 77, 76, 76, 76, 76, 76],
0x9b: [81, 81, 81, 81, 81, 80, 80, 80, 80, 80, 79, 79, 79, 79, 79, 84, 84, 84, 84, 84, 83, 83, 83, 83, 83, 82, 82, 82, 82, 82],
0x9c: [87, 87, 87, 87, 87, 86, 86, 86, 86, 86, 85, 85, 85, 85, 85, 90, 90, 90, 90, 90, 89, 89, 89, 89, 89, 88, 88, 88, 88, 88],
0x9d: [93, 93, 93, 93, 93, 92, 92, 92, 92, 92, 91, 91, 91, 91, 91, 96, 96, 96, 96, 96, 95, 95, 95, 95, 95, 94, 94, 94, 94, 94],
0x9e: [99, 99, 99, 99, 99, 98, 98, 98, 98, 98, 97, 97, 97, 97, 97, 102, 102, 102, 102, 102, 101, 101, 101, 101, 101, 100, 100, 100, 100, 100]
}
epics = False
for i in range(1,len(sys.argv)):
if sys.argv[i] == '-s':
import epics
else:
usage()
def read_frontend():
Vbias = {}
for gid in range(0x8e, 0x9f):
Vbias[gid] = [0 for i in range(0, 30)]
proc = subprocess.Popen([readVbias, hex(gid) + "@" + frendaddress], stdout=subprocess.PIPE)
resp = proc.communicate()[0]
for line in resp.split("\n"):
m0 = re.match(r" *([0-9]+): *([0-9.]+)" * 5, line)
if m0:
for i in range(1,11,2):
try:
Vbias[gid][int(m0.group(i))] = float(m0.group(i+1))
except:
print "bad index", i, m0.group(i)
sys.exit(1)
return Vbias
def print_table1():
for gid in range(0x8e, 0x9f):
for col in range(0,6):
if col == 0:
print " {0} ".format(hex(gid)),
else:
print " ",
for row in range(0,5):
print " {0:6.3f}".format(Vbias[gid][col * 5 + row]),
if epics:
r = fiber_row[gid][col * 5 + row]
c = fiber_column[gid][col * 5 + row]
evar = "TAGM:bias:{0}:{1}:v_set:rb".format(r,c)
epics.caput(evar, Vbias[gid][col * 5 + row])
print
Vbias = read_frontend()
print_table1()