Skip to content

Commit 9e2e7dc

Browse files
John-Holt-TessellaTom-Willemsen
authored andcommitted
Update import
1 parent fb3618d commit 9e2e7dc

File tree

1 file changed

+145
-1
lines changed

1 file changed

+145
-1
lines changed

base/uk.ac.stfc.isis.ibex.opis/resources/HV/Scripts/UpdateChannels.py

Lines changed: 145 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,150 @@
1-
from ChannelUtilities import get_available_channels, get_max_crates, get_channel_pv_name
1+
# These should be imported but imports have stopped working, removed until this is fixed see ticket 4350
2+
# This import seems to work but the other definitely don't something is funny.
3+
#from ChannelUtilities import get_available_channels, get_max_crates, get_channel_pv_name
4+
#### ChannelUtilities.py start #################################
5+
6+
from org.csstudio.opibuilder.scriptUtil import PVUtil
7+
from org.csstudio.opibuilder.scriptUtil import ConsoleUtil
8+
9+
def get_available_channels(crate_name_pvs, this_display,
10+
get_string_from_pv=PVUtil.getString, log=ConsoleUtil.writeError):
11+
"""
12+
Generator for the available Caen channels
13+
14+
Args:
15+
crate_name_pvs: The PVs containing the names of the crates
16+
this_display: The display that contains the macros for the maximum number of crates, slots and channels
17+
get_string_from_pv: Method used to get strings from PVs
18+
log: Method to send strings to the logs
19+
20+
Yields:
21+
A tuple of crate (string), slot (int), channel (int)
22+
"""
23+
for crate_name_pv in crate_name_pvs:
24+
try:
25+
crate = get_string_from_pv(crate_name_pv)
26+
except Exception, e:
27+
log("Unable to get crate name for PV: " + crate_name_pv + " , error: " + str(e))
28+
continue
29+
30+
if len(crate) == 0:
31+
continue
32+
33+
for slot in range(get_max_slots(this_display)):
34+
for channel in range(get_max_channels(this_display)):
35+
yield crate, slot, channel
36+
37+
38+
def get_summary_channels(channel_list_pv, get_string_from_pv=PVUtil.getString, log=ConsoleUtil.writeError):
39+
"""
40+
Gets the list of channels from the HVCaen.
41+
42+
Args:
43+
channel_list_pv: The PV containing the list of channels.
44+
get_string_from_pv: Function for extracting a string from a named PV
45+
log: Function accepting a string that is written to a log
46+
47+
Returns:
48+
A list of available channels, or an empty list if getting the channels fails.
49+
"""
50+
51+
def channel_formatter(channel):
52+
formatted_channel = channel.replace(" ", "")
53+
if formatted_channel.endswith(','):
54+
formatted_channel = formatted_channel[:-1]
55+
return formatted_channel
56+
57+
channels = list()
58+
try:
59+
if channel_list_pv.getValue().getData().size() > 0: # default method throws uncaught java exception if empty
60+
channels = [channel_formatter(chan) for chan in get_string_from_pv(channel_list_pv).split(' ')]
61+
except Exception, e: # Jython slightly different to standard Python
62+
log("Unable to get channel list for HVCaen: " + str(e)) # Jython str has no 'format'
63+
return channels
64+
65+
def _get_max(this_display, macro, default_value, upper_limit=None):
66+
"""
67+
68+
Args:
69+
this_display: The display. The returned value should be available via a macro.
70+
macro: The macro containing the value
71+
default_value: The value to use if the macro isn't specified
72+
upper_limit: The absolute maximum value the property can take
73+
log: Where to send messages
74+
75+
Returns:
76+
The value of the macro
77+
"""
78+
max_value = this_display.getPropertyValue("macros").getMacrosMap().get(macro)
79+
80+
try:
81+
max_value = int(max_value)
82+
except (TypeError, ValueError):
83+
max_value = default_value
84+
85+
if max_value is None:
86+
max_value = default_value
87+
88+
if upper_limit is not None:
89+
max_value = min(max_value, upper_limit)
90+
91+
return max_value
92+
93+
94+
def get_max_crates(this_display):
95+
"""
96+
The absolute maximum value is 15, determined by the limitations of EPICS MMBO records.
97+
98+
Args:
99+
this_display: The display. The returned value should be available via a macro.
100+
101+
Returns:
102+
The maximum number of crates supported by the OPI
103+
"""
104+
return _get_max(this_display, "MAX_CRATES", 2, 15)
105+
106+
107+
def get_max_slots(this_display):
108+
"""
109+
Args:
110+
this_display: The display. The returned value should be available via a macro.
111+
112+
Returns:
113+
The maximum number of slots supported by the OPI
114+
"""
115+
return _get_max(this_display, "MAX_SLOTS", 5)
116+
117+
118+
def get_max_channels(this_display):
119+
"""
120+
Args:
121+
this_display: The display. The returned value should be available via a macro.
122+
123+
Returns:
124+
The maximum number of channels supported by the OPI
125+
"""
126+
return _get_max(this_display, "MAX_CHANNELS", 25)
127+
128+
129+
def get_channel_pv_name(crate, slot, channel):
130+
"""
131+
Gets the PV name for a given channel
132+
133+
Args:
134+
crate: The name of the crate
135+
slot: The slot number
136+
channel: The channel number
137+
138+
Returns:
139+
The PV name for accessing the given channel
140+
"""
141+
return crate + ":" + str(slot) + ":" + str(channel)
142+
#### ChannelUtilities.py end #################################
143+
144+
2145
from org.csstudio.opibuilder.scriptUtil import PVUtil
3146

147+
4148
def update_channels(this_display, this_pvs):
5149
"""
6150
Updates the channels available on the summary maintenance page

0 commit comments

Comments
 (0)