def run(self): global end_var ConsoleUtil.writeInfo("Rocking curve") self.exec_cmd("ic_tune") #ConsoleUtil.writeInfo("turn led on") #pvs[0].setValue(1) self.exec_cmd("scan -o /storage/2017/May/Junior/Rocking_Curve_test_gonio -c I0 --optimum xafs2i0 MonoPitch -0.05 0.05 0.001 1") #ConsoleUtil.writeInfo("turn led off") #pvs[0].setValue(0) #self.exec_cmd("gedit") ConsoleUtil.writeInfo("end")
def doNode(node, do_node=default_node, depth=0, v=0): # \ # | result = [] # init a list for results ^ total = None # ^ # | global verbose # | verbose = v # ^ # ^ res = do_node(node, depth, 'init') # init node (can init result list if reqd) | if res != None: # if result, append to list | result.append(res) # ^ # ^ if not node in nodeLoader.NodeIndex: # check node defined, or print error and ret | ConsoleUtil.writeInfo("Error: There is no Key for \"" + node + "\" in NodeIndex[]") # | return None # | # ^ index = int(nodeLoader.NodeIndex[node] ) #find the index of the node for the lists | # | #-----------------------------------------Do subnodes---------------------------------- | if nodeLoader.SubNodeNames[index] != "": #If valid subnode list | ^ subnodes = nodeLoader.SubNodeNames[index].replace("\'", "").split( ",") #split into | ^ for s in subnodes: #go over list | | if s != "": #if valid subnode | | res = doNode(node + "_" + s, do_node, depth + 1, v) # doNode() recursivly --|--->-- if res != None: #if result, add to list | result.append(res) # | #-------------------------------------------------------------------------------------- #Elements should really be at the end of the line. ie #the subnode containing the elements should have no further subnodes defined in tree #-----------------------------------------Do elements---------------------------------- if nodeLoader.ElementNames[index] != "": #if valid element list | elements = nodeLoader.ElementNames[index].replace("\'", "").split( ",") #split | for e in elements: #go over list | if e != "": #if valid element | res = do_node(node + "_" + e, depth, 'elem') #do the element | if res != None: #if result, add to list | result.append(res) # | #-------------------------------------------------------------------------------------- total = do_node(node, depth, 'end', result) return total
def run(self): try: appDirectory = os.getenv( "APP" ) consoleScript = appDirectory + "/scripts/IOC/iocConsole.py" command = consoleScript + " " + self.widget.getParent().getMacroValue( "ioc" ) #ConsoleUtil.writeInfo( "Will execute " + "<" + command + ">" ) os.system( command ) except Exception, e: ConsoleUtil.writeInfo( "There was a problem : " + str(e) ) raise e
def run(self): try: appDirectory = os.getenv("APP") consoleScript = appDirectory + "/scripts/IOC/iocConsole.py" command = consoleScript + " " + self.widget.getParent( ).getMacroValue("ioc") #ConsoleUtil.writeInfo( "Will execute " + "<" + command + ">" ) os.system(command) except Exception, e: ConsoleUtil.writeInfo("There was a problem : " + str(e)) raise e
def check_interlock(): interlock_optical = PVUtil.getDouble(interlock_optical_pv) interlock_experimental = PVUtil.getDouble(interlock_experimental_pv) if (interlock_optical != interlock_experimental): status_pv.setValue("Necessitamos de feixe nas estacoes experimentais") #ConsoleUtil.writeInfo ("Necessitamos de feixe nas estacoes experimentais") raise ValueError("Necessitamos de feixe nas estacoes experimentais") elif (interlock_optical == 0): status_pv.setValue("Necessitamos de feixe nas estacoes experimentais") #ConsoleUtil.writeInfo ("Necessitamos de feixe nas estacoes experimentais") raise ValueError("Necessitamos de feixe nas estacoes experimentais") else: status_pv.setValue( "Feixe nas estacoes experimentais - Experimento liberado") ConsoleUtil.writeInfo( "Feixe nas estacoes experimentais - Experimento liberado")
def default_node(node,depth,mode='elem',result=None): global doElems if mode == 'init': #if start of node index=int(nodeLoader.NodeIndex[node]) #Get index from dict if verbose > 0: #if verbose erange=nodeLoader.ElementRange[index].replace("\'","").split(",") if len(erange)>1: ConsoleUtil.writeInfo( ' '*depth+"#Node:"+node+" Erange: "+erange[0]+" - "+erange[1]) #print the indented node name if verbose > 1: #if very verbose mode, print record details if any. nrnames=nodeLoader.NodeRecordNames[index].split(",") nrtypes=nodeLoader.NodeRecordTypes[index].split(",") for i in range(len(nrtypes)): if nrtypes[i] != "": ConsoleUtil.writeInfo( ' '*depth+" #NodeRecordName: "+repr(nrnames[i]).ljust(20)+ "#NodeRecordType: "+repr(nrtypes[i])) ernames=nodeLoader.ElementRecordNames[index].replace("\'","").split(",") ertypes=nodeLoader.ElementRecordTypes[index].replace("\'","").split(",") erflags=nodeLoader.ElementRecordFlags[index].replace("\'","").split(",") for i in range(len(ertypes)): if ertypes[i] != "": ConsoleUtil.writeInfo( ' '*depth+" #ElementRecordName: "+repr(ernames[i]).ljust(10)+ "#ElementRecordType: "+repr(ertypes[i])+ " #ElementRecordFlag: "+repr(erflags[i])) if len(nodeLoader.ElementNames[index]) >2: linkingContainer = WidgetUtil.createWidgetModel("org.csstudio.opibuilder.widgets.linkingContainer") linkingContainer.setPropertyValue("opi_file", opi_node_info) linkingContainer.addMacro("P", node) linkingContainer.setPropertyValue("resize_behaviour", 1) linkingContainer.setPropertyValue("border_style", 0) linkingContainer.setPropertyValue("background_color", "OPI_Background") widget.addChildToBottom(linkingContainer) #elif mode == 'elem': #if verbose>0: # ConsoleUtil.writeInfo( ' '*depth+" #Element: "+node) #print the indented elment name # #return None #esel=node.split("_")[len(node.split("_"))-1] #linkingContainer = WidgetUtil.createWidgetModel("org.csstudio.opibuilder.widgets.linkingContainer") #linkingContainer.setPropertyValue("opi_file", opi_element) #linkingContainer.addMacro("P", node) #linkingContainer.addMacro("S", esel) #linkingContainer.addMacro("C", str(eCount)) #linkingContainer.setPropertyValue("resize_behaviour", 1) #linkingContainer.setPropertyValue("border_style", 0) #widget.addChildToBottom(linkingContainer) #ConsoleUtil.writeInfo( ' '*depth+" #Element: "+node+" sel: "+esel) #print the indented elment name elif mode == 'end': if verbose: ConsoleUtil.writeInfo( ' '*depth+"#NodeEnd: "+node) else: return None
def doNode(node, do_node=default_node, depth=0, v=0): # \ # | result= []; # init a list for results ^ total = None # ^ # | global verbose # | verbose = v # ^ # ^ res = do_node(node, depth, 'init') # init node (can init result list if reqd) | if res != None: # if result, append to list | result.append(res) # ^ # ^ if not node in nodeLoader.NodeIndex: # check node defined, or print error and ret | ConsoleUtil.writeInfo( "Error: There is no Key for \""+node+"\" in NodeIndex[]") # | return None # | # ^ index=int(nodeLoader.NodeIndex[node]) #find the index of the node for the lists | # | #-----------------------------------------Do subnodes---------------------------------- | if nodeLoader.SubNodeNames[index] != "": #If valid subnode list | ^ subnodes = nodeLoader.SubNodeNames[index].replace("\'","").split(",") #split into | ^ for s in subnodes: #go over list | | if s != "": #if valid subnode | | res = doNode(node+"_"+s, do_node, depth+1,v) # doNode() recursivly --|--->-- if res != None: #if result, add to list | result.append(res) # | #-------------------------------------------------------------------------------------- #Elements should really be at the end of the line. ie #the subnode containing the elements should have no further subnodes defined in tree #-----------------------------------------Do elements---------------------------------- if nodeLoader.ElementNames[index] != "": #if valid element list | elements = nodeLoader.ElementNames[index].replace("\'","").split(",") #split | for e in elements: #go over list | if e != "": #if valid element | res = do_node(node+"_"+e, depth,'elem') #do the element | if res != None: #if result, add to list | result.append(res) # | #-------------------------------------------------------------------------------------- total=do_node(node, depth, 'end', result) return total
def check_mono_enconder(): encoder_mono = PVUtil.getDouble(enconder_mono_pv) position_monotheta = PVUtil.getDouble(position_monotheta_pv) diff = abs(encoder_mono - position_monotheta) if (diff > 0.1): status_pv.setValue( "Leitura incorreta do encoder. Faca o procedimento para a busca da posicao de referencia" ) #ConsoleUtil.writeInfo ("Leitura incorreta do encoder. Faca o procedimento para a busca da posicao de referencia") raise ValueError( "Leitura incorreta do encoder. Faca o procedimento para a busca da posicao de referencia" ) else: status_pv.setValue("Leitura correta do encoder - Experimento liberado") ConsoleUtil.writeInfo( "Leitura correta do encoder - Experimento liberado")
def run(self): try: turn_off_display() #check_mono_enconder() LED1.setValue(1) #check_interlock() LED2.setValue(1) #mono_position_height() LED3.setValue(1) #TODO: varredura_motor_pitch #TODO: SCAN_ENERGY LED4.setValue(1) except ValueError as e: ConsoleUtil.writeInfo("Error: " + str(e)) exit() except Exception as e: ConsoleUtil.writeInfo(e) exit()
from org.csstudio.opibuilder.scriptUtil import PVUtil import org.csstudio.opibuilder.scriptUtil.ConsoleUtil as ConsoleUtil energy = PVUtil.getDouble(pvs[0]) energy_target = PVUtil.getDouble(pvs[1]) ConsoleUtil.writeInfo(str(energy)) ConsoleUtil.writeInfo(str(energy_target)) if (energy == energy_target): pvs[2].setValue("OK") ConsoleUtil.writeInfo("Atingida a energia alvo. Por favor, continue.") else: pvs[2].setValue("Pressione Go") ConsoleUtil.writeInfo("Energia alvo não atingida. Por favor, aguarde.")
#This is called from HallBTree.opi; a very a generic GUI #which will display a node, parent, siblings subnodes and elements #with the asscoiated .opi files embedded for each. nodeLoader.readTree() #Get the macro(s) associated with the widget #The standard EPICS marco P=prefix is always passed. It is the name of the node or element. node = widget.getMacroValue("P") #main node for the GUI if not node in nodeLoader.NodeIndex: # check node defined, or print error and ret print "Error: There is no Key for \""+node+"\" in NodeIndex[]" exit ConsoleUtil.writeInfo("thisnode = "+node) index=int(nodeLoader.NodeIndex[node]) #find the index of the node for the lists #get the widgets of all the grouping containers to be filled with our opis widgetParent = display.getWidget("ParentContainer") widgetSiblings = display.getWidget("SiblingContainer") widgetNode = display.getWidget("NodeContainer") widgetSubnodes = display.getWidget("SubNodeContainer") widgetElements = display.getWidget("ElementContainer") widgetElementHeader = display.getWidget("ElementHeaderContainer") #get all the information for this node from the dictionaries look in clas12NodesDict to see what else is available. #Check if we're requesting the top node. If so, set node to 1st subnode down from top if node.find("_"): parent = node.split("_"+node.split("_")[len(node.split("_"))-1])[0]
import nodeLoader #from java.util import Arrays #Update the list of items in combo widget to choose an element from under a node of the CLAS EPICS tree. #Triggered by selection of a new node using the local PV loc://$(DID)_NODE #It makes the item list of all the elements under that node and sets the selected to 1st in the list nodeLoader.readTree() #make sure the node tree is made nodefull = PVUtil.getString(pvArray[0]) #Full name of the node Eg. B_SYS_HV_ECAL_SEC1 if nodeLoader.NodeIndex[nodefull]: #if its a node index = int(nodeLoader.NodeIndex[nodefull]) #get index of node widget.removeAllChildren() if ((len(nodeLoader.ElementRange[index])>2)and(len(nodeLoader.ElementNames[index])>2)): elementList = nodeLoader.ElementNames[index].strip("'").split(",") #get element names for t in range(0,len(elementList)): ConsoleUtil.writeInfo("elem: " + elementList[t]) linkingContainer = WidgetUtil.createWidgetModel("org.csstudio.opibuilder.widgets.linkingContainer") linkingContainer.setPropertyValue("opi_file", "hvChanWrapper.opi") linkingContainer.addMacro("P", nodefull+"_"+elementList[t]) # linkingContainer.addMacro("TYPE", "1527") # linkingContainer.setPropertyValue("resize_behaviour", 1) #size container to .opi linkingContainer.setPropertyValue("border_style", 0) #no border linkingContainer.setPropertyValue("background_color", "OPI_Background") widget.addChildToBottom(linkingContainer) #add to bottom of current group
def cssprint(l): ConsoleUtil.writeInfo(str(l))
if not trace_count == ntrace: # not created yet widget.setPropertyValue("trace_count",str(ntrace)) #widget.setPropertyValue("show_toolbar","true") #Set some default values and see if there are macros to override them. title = "Monitor graph" if str(widget.getMacroValue("TITLE")): title = str(widget.getMacroValue("TITLE")) for n in range(2,ntrace): # look for values for each trace macroname = "TRACE"+str(n) if widget.getMacroValue(macroname): trace_pv = widget.getMacroValue(macroname) else: ConsoleUtil.writeInfo("ERROR: Need macro " + macroname + "to be defined to set the trace PV") point_size = 4 #defailt to 4 macroname = "POINT_SIZE_"+str(n) if widget.getMacroValue(macroname): point_size = widget.getMacroValue(macroname) if trace_pv: trace_name=views[view]+":"+trace_pv+"_wf" widget.setPropertyValue("trace_"+str(n)+"_x_axis_index","0") widget.setPropertyValue("trace_"+str(n)+"_update_mode","3") widget.setPropertyValue("trace_"+str(n)+"_point_size",point_size) widget.setPropertyValue("trace_"+str(n)+"_name",trace_pv) widget.setPropertyValue("trace_"+str(n)+"_point_style","1") widget.setPropertyValue("trace_"+str(n)+"_y_pv",trace_name) widget.setPropertyValue("trace_"+str(n)+"_y_axis_index","1")
#module in the same directory is visible to this script import WidgetUtil GREEN = ColorFontUtil.getColorFromRGB(0, 180, 0) RED = ColorFontUtil.RED #Name of the flag to show if dialog has been popped up. flagName = "popped" labelName = "myLabel" if widget.getExternalObject(flagName) == None: widget.setExternalObject(flagName, 0) #Example to write text to BOY Console ConsoleUtil.writeInfo("Welcome to Best OPI, Yet (BOY)!") b = widget.getExternalObject(flagName) if PVUtil.getDouble(pvs[0]) > PVUtil.getDouble(pvs[1]): s = "Temperature is too high!" WidgetUtil.setText(display, labelName, s) WidgetUtil.setForeColor(display, labelName, RED) #If dialog has not been popped up, pop up the dialog if b == 0: #set popped flag to true widget.setExternalObject(flagName, 1) MessageDialog.openWarning(None, "Warning", "The temperature you set is too high!") else: s = "Temperature is normal"
import os.path #This is called from HallBTree.opi; a very a generic GUI #which will display a node, parent, siblings subnodes and elements #with the asscoiated .opi files embedded for each. nodeLoader.readTree() #Get the macro(s) associated with the widget #The standard EPICS marco P=prefix is always passed. It is the name of the node or element. node = widget.getMacroValue("P") #main node for the GUI if not node in nodeLoader.NodeIndex: # check node defined, or print error and ret print "Error: There is no Key for \"" + node + "\" in NodeIndex[]" exit ConsoleUtil.writeInfo("thisnode = " + node) index = int( nodeLoader.NodeIndex[node]) #find the index of the node for the lists #get the widgets of all the grouping containers to be filled with our opis widgetParent = display.getWidget("ParentContainer") widgetSiblings = display.getWidget("SiblingContainer") widgetNode = display.getWidget("NodeContainer") widgetSubnodes = display.getWidget("SubNodeContainer") widgetElements = display.getWidget("ElementContainer") widgetElementHeader = display.getWidget("ElementHeaderContainer") #get all the information for this node from the dictionaries look in clas12NodesDict to see what else is available. #Check if we're requesting the top node. If so, set node to 1st subnode down from top if node.find("_"):
layer = PVUtil.getDoubleArray(pvArray[3]) wlayer = int(widget.getMacroValue("LAYER")) #P = widget.getMacroValue("P") s=16 #ConsoleUtil.writeInfo(str(xcoords[5])) for n in range(0,232): if not size[n]==999: linkingContainer = WidgetUtil.createWidgetModel("org.csstudio.opibuilder.widgets.linkingContainer") linkingContainer.setPropertyValue("opi_file", "tile.opi") #linkingContainer.addMacro("ID",str(n)) linkingContainer.addMacro("ID", str(n).zfill(3)) linkingContainer.setPropertyValue("resize_behaviour", 2) linkingContainer.setPropertyValue("border_style", 2) l = int(layer[n]) ConsoleUtil.writeInfo(str(l) + " " + str(wlayer)) if l==wlayer: side=s*size[n] posx=(220+s*xcoords[n]) posy=(160-s*ycoords[n]) if size[n] ==1: posy=posy+s #ConsoleUtil.writeInfo(str(posx) + " " + str(posy)) linkingContainer.setPropertyValue("x", posx) linkingContainer.setPropertyValue("y", posy) linkingContainer.setPropertyValue("width", side) linkingContainer.setPropertyValue("height", side) widget.addChild(linkingContainer)
from org.csstudio.opibuilder.scriptUtil import PVUtil from org.csstudio.opibuilder.scriptUtil import ConsoleUtil container = display.getWidget("Tabs") # enable tabs tab_count = int(container.getPropertyValue("tab_count")) for i in range(tab_count): if pvArray[i + 1].isConnected(): container.setPropertyValue("tab_%s_enabled" % i, "true") else: container.setPropertyValue("tab_%s_enabled" % i, "false") # activate asked for tab try: active_tab = int(pvs[0].getValue().value) except (IndexError, AttributeError, TypeError, ValueError): active_tab = 1 ConsoleUtil.writeInfo('Could not get value from macro for active tab') if active_tab < 1 or active_tab > tab_count: ConsoleUtil.writeInfo('Active tab is out of range was ' + str(active_tab)) active_tab = 1 container.setActiveTabIndex(active_tab - 1)
from org.csstudio.opibuilder.scriptUtil import PVUtil import org.csstudio.opibuilder.scriptUtil.ConsoleUtil as ConsoleUtil encoder_mono = PVUtil.getDouble(pvs[0]); position_monotheta = PVUtil.getDouble(pvs[1]); encoder_warning = PVUtil.getDouble(pvs[2]); diff = abs(encoder_mono - position_monotheta); ConsoleUtil.writeInfo (str(diff)) if(diff > 0.1): # pvs[2].setValue("Leitura incorreta do encoder. Faca o procedimento para a busca da posicao de referencia."); pvs[2].setValue("Incorrect feedback with the encoder. Do the reference search procedure."); # ConsoleUtil.writeInfo ("Leitura incorreta do encoder. Faca o procedimento para a busca da posicao de referencia") ConsoleUtil.writeInfo ("Incorrect feedback with the encoder. Do the reference search procedure.") else: # pvs[2].setValue("Leitura correta do encoder - Experimento liberado"); pvs[2].setValue("Correct feedback with the encoder. Experiment released!"); # ConsoleUtil.writeInfo ("Leitura correta do encoder - Experimento liberado") ConsoleUtil.writeInfo ("Correct feedback with the encoder. Experiment released!")
#calcs offset = 18.0 #offset_DCM h = 6.62606896E-34 ev = 1.602176565E-19 c = 299792458 d = 3.13542 hcort_c = h / ev * c / 1E-10 initial_theta = math.asin(1.2398E4 / (2 * initial_energy * math.pi)) final_theta = math.asin(1.2398E4 / (2 * final_energy * math.pi)) initial_height = offset * math.sin(initial_theta) / math.sin(2 * initial_theta) final_height = offset * math.sin(final_theta) / math.sin(2 * final_theta) height = (initial_height + final_height) / 2 theta_calc = math.acos(offset / (2 * height)) energy = hcort_c / (2 * d * math.sin(theta_calc)) pvs[2].setValue(energy) pvs[3].setValue(height) # moving motors to calculate positions # energy_theta ConsoleUtil.writeInfo("Energia e altura médias calculadas:") ConsoleUtil.writeInfo("E = ") ConsoleUtil.writeInfo(str(energy)) ConsoleUtil.writeInfo("height = ") ConsoleUtil.writeInfo(str(height))
from org.csstudio.opibuilder.scriptUtil import PVUtil, WidgetUtil, ConsoleUtil import nodeLoader from java.util import Arrays #Update the list of items in combo widget to choose an element from under a node of the CLAS EPICS tree. #Triggered by selection of a new node using the local PV loc://$(DID)_NODE #It makes the item list of all the elements under that node and sets the selected to 1st in the list nodeLoader.readTree() #make sure the node tree is made nodefull = PVUtil.getString( pvArray[0]) #Full name of the node Eg. B_SYS_HV_ECAL_SEC1 element = PVUtil.getString(pvArray[1]) ConsoleUtil.writeInfo("NS4" + element) itemlist = ["Element"] #start off the default itemlist count = 1 #if nodeLoader.NodeIndex[nodefull]: #if its a node index = int(nodeLoader.NodeIndex[nodefull]) #get index of node #else: #else assume an element get node as parent # element = nodefull # nodefull = node.split("_"+node.split("_")[len(node.split("_"))-1])[0] # index = int(nodeLoader.NodeIndex[nodefull]) #get index of node #if there are elements, make a list if ((len(nodeLoader.ElementRange[index]) > 2) and (len(nodeLoader.ElementNames[index]) > 2)): count = 0 itemlist = []
from org.csstudio.opibuilder.scriptUtil import PVUtil from org.csstudio.opibuilder.scriptUtil import ColorFontUtil from org.csstudio.opibuilder.scriptUtil import ConsoleUtil from org.eclipse.jface.dialogs import MessageDialog ConsoleUtil.writeInfo("firstTime") MessageDialog.openWarning(None, "Warning", "firstTime ???") #Fill PV Name only once if widget.getVar("firstTime") == None: widget.setVar("firstTime", True) i = 0 for pv in pvs: ConsoleUtil.writeInfo("pv name = " + pv.getName()) table.setCellText(i, 0, pv.getName()) if not pv.isConnected(): table.setCellText(i, 1, "Disconnected") i += 1 #find index of the trigger PV i = 0 while triggerPV != pvs[i]: i += 1 table.setCellText(i, 1, PVUtil.getString(triggerPV)) table.setCellText(i, 2, PVUtil.getTimeString(triggerPV)) table.setCellText(i, 3, PVUtil.getStatus(triggerPV)) table.setCellText(i, 4, PVUtil.getSeverityString(triggerPV)) s = PVUtil.getSeverity(triggerPV)
if not trace_count == ntrace: # not created yet widget.setPropertyValue("trace_count",str(ntrace)) #widget.setPropertyValue("show_toolbar","true") #Set some default values and see if there are macros to override them. title = "Monitor graph" if str(widget.getMacroValue("TITLE")): title = str(widget.getMacroValue("TITLE")) for n in range(2,ntrace): # look for values for each trace macroname = "TRACE"+str(n) if widget.getMacroValue(macroname): trace_pv = widget.getMacroValue(macroname) else: ConsoleUtil.writeInfo("ERROR: Need macro " + macroname + "to be defined to set the trace PV") point_size = 4 #defailt to 4 macroname = "POINT_SIZE_"+str(n) if widget.getMacroValue(macroname): point_size = widget.getMacroValue(macroname) if trace_pv: trace_name=views[view]+":"+trace_pv+"_wf" widget.setPropertyValue("trace_"+str(n)+"_x_axis_index","0") widget.setPropertyValue("trace_"+str(n)+"_update_mode","3") widget.setPropertyValue("trace_"+str(n)+"_point_size",point_size) widget.setPropertyValue("trace_"+str(n)+"_name",trace_pv) widget.setPropertyValue("trace_"+str(n)+"_point_style","1") widget.setPropertyValue("trace_"+str(n)+"_y_pv",trace_name) widget.setPropertyValue("trace_"+str(n)+"_y_axis_index","1")
# Recursion ends here # ########################################################################################### #def main(): # #Read in the node tree nodeLoader.readTree() # # #Calls the doNode() (see below) that works recursively through the tree and calls do_element start_node end_node topnode=widget.getMacroValue("TOP") node = PVUtil.getString(pvArray[0]) if not node in nodeLoader.NodeIndex: # check node defined, or try parent, or force to top node if node.find("_"): parent = node.split("_"+node.split("_")[len(node.split("_"))-1])[0] ConsoleUtil.writeInfo("Update: parent="+parent) if parent in nodeLoader.NodeIndex: esel=node.split("_")[len(node.split("_"))-1] node=parent else: node=topnode else: node=topnode dir = os.environ["CSS_SHARE_DIR"] #Now do the same for ..._element.opi. This will make a widget for every element opi_element=dir+"/apps/clasTreeApp/"+topnode+"_element.opi" #Default to top opi_node=node #default to node while not opi_node == topnode: #if not at top node yet
hvstr = PVUtil.getString(pvArray[0]) hvinfo = hvstr.split(",") hv = hvinfo[3] board = hvinfo[4] half = hvinfo[5] chstr = PVUtil.getString(pvArray[1]) chlist = chstr.split(",") nchan = len(chlist) ch2 = PVUtil.getString(pvArray[2]) ConsoleUtil.writeInfo("pv0=" + hvstr) ConsoleUtil.writeInfo("pv1=" + chstr) ConsoleUtil.writeInfo("pv2=" + ch2) #ConsoleUtil.writeInfo(str(xcoords[5])) for n in range(0,nchan): ConsoleUtil.writeInfo("Chann" + str(n)); linkingContainer = WidgetUtil.createWidgetModel("org.csstudio.opibuilder.widgets.linkingContainer") linkingContainer.setPropertyValue("opi_file", "chan1.opi") linkingContainer.addMacro("ID", chlist[n]) linkingContainer.setPropertyValue("resize_behaviour", 1) linkingContainer.setPropertyValue("border_style", 0) widget.addChildToBottom(linkingContainer) linkingContainer = WidgetUtil.createWidgetModel("org.csstudio.opibuilder.widgets.linkingContainer") linkingContainer.setPropertyValue("opi_file", "grouphv.opi")
from org.csstudio.opibuilder.scriptUtil import PVUtil,WidgetUtil,ConsoleUtil import nodeLoader from java.util import Arrays #Update the list of items in combo widget to choose an element from under a node of the CLAS EPICS tree. #Triggered by selection of a new node using the local PV loc://$(DID)_NODE #It makes the item list of all the elements under that node and sets the selected to 1st in the list nodeLoader.readTree() #make sure the node tree is made nodefull = PVUtil.getString(pvArray[0]) #Full name of the node Eg. B_SYS_HV_ECAL_SEC1 element = PVUtil.getString(pvArray[1]) ConsoleUtil.writeInfo("NS4" + element) itemlist = ["Element"] #start off the default itemlist count=1 #if nodeLoader.NodeIndex[nodefull]: #if its a node index = int(nodeLoader.NodeIndex[nodefull]) #get index of node #else: #else assume an element get node as parent # element = nodefull # nodefull = node.split("_"+node.split("_")[len(node.split("_"))-1])[0] # index = int(nodeLoader.NodeIndex[nodefull]) #get index of node #if there are elements, make a list if ((len(nodeLoader.ElementRange[index])>2)and(len(nodeLoader.ElementNames[index])>2)): count=0 itemlist = [] fullrange = nodeLoader.ElementRange[index].strip("'") #strip quotes
from org.csstudio.opibuilder.scriptUtil import PVUtil, WidgetUtil, ConsoleUtil hvstr = PVUtil.getString(pvArray[0]) hvinfo = hvstr.split(",") hv = hvinfo[3] board = hvinfo[4] half = hvinfo[5] chstr = PVUtil.getString(pvArray[1]) chlist = chstr.split(",") nchan = len(chlist) ch2 = PVUtil.getString(pvArray[2]) ConsoleUtil.writeInfo("pv0=" + hvstr) ConsoleUtil.writeInfo("pv1=" + chstr) ConsoleUtil.writeInfo("pv2=" + ch2) #ConsoleUtil.writeInfo(str(xcoords[5])) for n in range(0, nchan): ConsoleUtil.writeInfo("Chann" + str(n)) linkingContainer = WidgetUtil.createWidgetModel( "org.csstudio.opibuilder.widgets.linkingContainer") linkingContainer.setPropertyValue("opi_file", "chan1.opi") linkingContainer.addMacro("ID", chlist[n]) linkingContainer.setPropertyValue("resize_behaviour", 1) linkingContainer.setPropertyValue("border_style", 0) widget.addChildToBottom(linkingContainer) linkingContainer = WidgetUtil.createWidgetModel(
from org.csstudio.opibuilder.scriptUtil import PVUtil from org.csstudio.opibuilder.scriptUtil import ColorFontUtil from org.csstudio.opibuilder.scriptUtil import ConsoleUtil from org.eclipse.jface.dialogs import MessageDialog ConsoleUtil.writeInfo("firstTime") MessageDialog.openWarning(None, "Warning", "firstTime ???") #Fill PV Name only once if widget.getVar("firstTime") == None: widget.setVar("firstTime", True) i=0 for pv in pvs: ConsoleUtil.writeInfo("pv name = " + pv.getName()) table.setCellText(i, 0, pv.getName()) if not pv.isConnected(): table.setCellText(i, 1, "Disconnected") i+=1 #find index of the trigger PV i=0 while triggerPV != pvs[i]: i+=1 table.setCellText(i, 1, PVUtil.getString(triggerPV)) table.setCellText(i, 2, PVUtil.getTimeString(triggerPV)) table.setCellText(i, 3, PVUtil.getStatus(triggerPV)) table.setCellText(i, 4, PVUtil.getSeverityString(triggerPV)) s = PVUtil.getSeverity(triggerPV)
def check_error(self, value): if(value!=0): ConsoleUtil.writeInfo("error") exit()
# only the package name differs. # # from org.csstudio.opibuilder.scriptUtil import PVUtil # # needs to change into # # from org.csstudio.display.builder.runtime.script import PVUtil # # This specific package name is actually patched by the # display builder, so this script, attached to a Label, # will simply 'run', issuing a warning that the package # name has been patched: # # from org.csstudio.opibuilder.scriptUtil import PVUtil # widget.setPropertyValue("text", "Hello") # To write a portable script, check for the display builder's widget type: display_builder = 'getVersion' in dir(widget) if display_builder: from org.csstudio.display.builder.runtime.script import PVUtil, ScriptUtil ScriptUtil.getLogger().info("Executing in display builder") else: from org.csstudio.opibuilder.scriptUtil import PVUtil, ConsoleUtil ConsoleUtil.writeInfo("Executing in BOY") # This API is now the same: val = PVUtil.getDouble(pvs[0]) widget.setPropertyValue("text", "Value is %.3f" % val)
from org.csstudio.opibuilder.scriptUtil import PVUtil import org.csstudio.opibuilder.scriptUtil.ConsoleUtil as ConsoleUtil interlock_optical = PVUtil.getDouble(pvs[0]); interlock_experimental = PVUtil.getDouble(pvs[1]); interlock_warning = PVUtil.getDouble(pvs[2]); if(interlock_optical != interlock_experimental): pvs[2].setValue("We need beam at experimental stations!"); ConsoleUtil.writeInfo ("We need beam at experimental stations!") elif (interlock_optical == 0): pvs[2].setValue("We need beam at experimental stations!"); ConsoleUtil.writeInfo ("We need beam at experimental stations!") else: pvs[2].setValue("Beam at experimental stations! - Experiment released!"); ConsoleUtil.writeInfo ("Beam at experimental stations! - Experiment released!")
from org.csstudio.opibuilder.scriptUtil import PVUtil, ConsoleUtil from jarray import array Timestamp_SP = pvs[0] EvtCode_SP = pvs[1] Mask_SP = pvs[2] Ena_SP = pvs[3] T, E, M, EN = [], [], [], [] for row in widget.getTable().getContent(): T.append(float(row[0])) ConsoleUtil.writeInfo("test 1 "+str(row[0])) E.append(float(row[1])) ConsoleUtil.writeInfo("test 2 "+str(row[1])) M.append(float(row[2])) ConsoleUtil.writeInfo("test 3 "+str(row[2])) EN.append(float(row[3])) ConsoleUtil.writeInfo("test 4 "+str(row[3])) Timestamp_SP.setValue(array(T, 'd')) EvtCode_SP.setValue(array(E, 'd')) Mask_SP.setValue(array(M, 'd')) Ena_SP.setValue(array(EN, 'd'))
def run(self): element = PVUtil.getString(pvs[1]) edge = PVUtil.getString(pvs[2]) vacuum_press = PVUtil.getString(pvs[3]) default_press = PVUtil.getString(pvs[4]) wait_purge = PVUtil.getString(pvs[5]) wait_vacuum = PVUtil.getString(pvs[6]) argon_order = int(PVUtil.getDouble(pvs[7])) helium_order = int(PVUtil.getDouble(pvs[8])) nitrogen_order = int(PVUtil.getDouble(pvs[9])) ConsoleUtil.writeInfo("Element: " + str(element)) ConsoleUtil.writeInfo("Edge: " + str(edge)) ConsoleUtil.writeInfo("Vacuum_press: " + str(vacuum_press)) ConsoleUtil.writeInfo("Default_press: " + str(default_press)) ConsoleUtil.writeInfo("Wait_purge: " + str(wait_purge)) ConsoleUtil.writeInfo("Wait_vacuum: " + str(wait_vacuum)) ConsoleUtil.writeInfo("Argon_order: " + str(argon_order)) ConsoleUtil.writeInfo("Helium_order: " + str(helium_order)) ConsoleUtil.writeInfo("Nitrogen_order: " + str(nitrogen_order)) command = [ 'gass', str(element), str(edge), "--pressureVacuum=" + str(vacuum_press), "--pressureWork=" + str(default_press), "--extraTimeManifold=" + str(wait_purge), "--extraTimeManifoldVacuum=" + str(wait_vacuum), "--argonOrder=" + str(argon_order), "--heliumOrder=" + str(helium_order), "--nitrogenOrder=" + str(nitrogen_order) ] #command = ['python3.4', '/usr/local/bin/gass', '-h'] #command = ['gass', '-h'] #command = "gass %s %s" % (str(element), str(edge)) ConsoleUtil.writeInfo("command: " + str(command)) #pvs[0].setValue(0) subprocess.call(command)
from org.csstudio.opibuilder.scriptUtil import PVUtil from java.lang import Thread import org.csstudio.opibuilder.scriptUtil.ConsoleUtil as ConsoleUtil import time import os ConsoleUtil.writeInfo(str(time.clock())) end_var = False from threading import Thread class Th(Thread): def __init__ (self): Thread.__init__(self) def check_error(self, value): if(value!=0): ConsoleUtil.writeInfo("error") exit() def exec_cmd(self, cmd): a = os.system(cmd) self.check_error(a) def run(self): global end_var
#ConsoleUtil.write("Error: There is no Key for \""+str(node)+"\" in NodeIndex[]") node="B" if not node.find("_"): if n==1: drawing=1 parent=node shortnode=node else: if n < len(node.split("_")): drawing=1 shortnode = node.split("_")[n] parent = node.split("_"+node.split("_")[n])[0] if drawing==1: ConsoleUtil.writeInfo("n="+str(n)+", parent="+parent) widget.setPropertyValue("visible","true") pindex = int(nodeLoader.NodeIndex[parent]) siblings = nodeLoader.SubNodeNames[pindex].rstrip("'").lstrip("'").split(",") siblings.sort() ConsoleUtil.writeInfo("subnodes="+nodeLoader.SubNodeNames[pindex]) subnodes = nodeLoader.SubNodeNames[pindex].rstrip("'").lstrip("'").split(",") widget.setPropertyValue("items",Arrays.asList(subnodes) ) widget.setPropertyValue("height",24*len(subnodes) ) selectedPV = pvArray[1] selectedPV.setValue(shortnode)
#module in the same directory is visible to this script import WidgetUtil GREEN = ColorFontUtil.getColorFromRGB(0, 180, 0) RED = ColorFontUtil.RED #Name of the flag to show if dialog has been popped up. flagName = "popped" labelName = "myLabel" if widget.getExternalObject(flagName) == None: widget.setExternalObject(flagName, 0) #Example to write text to BOY Console ConsoleUtil.writeInfo("Welcome to Best OPI, Yet (BOY)!") b = widget.getExternalObject(flagName); if PVUtil.getDouble(pvs[0]) > PVUtil.getDouble(pvs[1]): s = "Temperature is too high!" WidgetUtil.setText(display, labelName, s) WidgetUtil.setForeColor(display, labelName, RED) #If dialog has not been popped up, pop up the dialog if b == 0: #set popped flag to true widget.setExternalObject(flagName, 1) MessageDialog.openWarning( None, "Warning", "The temperature you set is too high!") else: s = "Temperature is normal"
from org.csstudio.opibuilder.scriptUtil import PVUtil,WidgetUtil,ConsoleUtil ch = int(PVUtil.getDouble(pvArray[0])) desc = widget.getPropertyValue("tooltip") #ConsoleUtil.writeInfo(desc) currhv = -1 if len(desc) > 2: ConsoleUtil.writeInfo(desc) currhv = int(desc[desc.find("HVChan")+7:]) ConsoleUtil.writeInfo("Currhv = " + str(currhv) ) if currhv < 0: hv="1" else: hv = PVUtil.getString(pvArray[1]) if (int(hv) != currhv): widget.removeAllChildren() #clean the area first linkingContainer = WidgetUtil.createWidgetModel("org.csstudio.opibuilder.widgets.linkingContainer") linkingContainer.setPropertyValue("opi_file", "chan8.opi") linkingContainer.addMacro("ID", str(ch).zfill(3)) #linkingContainer.addMacro("ID", ch) linkingContainer.addMacro("HV", str(hv.zfill(2))) linkingContainer.setPropertyValue("resize_behaviour", 1) linkingContainer.setPropertyValue("border_style", 0) widget.addChild(linkingContainer) widget.setPropertyValue("tooltip","ChanHV " + hv)
xcoords = PVUtil.getDoubleArray(pvArray[0]) ycoords = PVUtil.getDoubleArray(pvArray[1]) size = PVUtil.getDoubleArray(pvArray[2]) layer = PVUtil.getDoubleArray(pvArray[3]) wlayer = int(widget.getMacroValue("LAYER")) s = 16 #ConsoleUtil.writeInfo(str(xcoords[5])) for n in range(0, 231): if not size[n] == 999: linkingContainer = WidgetUtil.createWidgetModel( "org.csstudio.opibuilder.widgets.linkingContainer") linkingContainer.setPropertyValue("opi_file", "tile.opi") linkingContainer.addMacro("ID", str(n)) linkingContainer.setPropertyValue("resize_behaviour", 2) linkingContainer.setPropertyValue("border_style", 2) l = int(layer[n]) ConsoleUtil.writeInfo(str(l) + " " + str(wlayer)) if l == wlayer: side = s * size[n] posx = (180 + s * xcoords[n]) posy = (180 - s * ycoords[n]) if size[n] == 1: posy = posy + s #ConsoleUtil.writeInfo(str(posx) + " " + str(posy)) linkingContainer.setPropertyValue("x", posx) linkingContainer.setPropertyValue("y", posy) linkingContainer.setPropertyValue("width", side) linkingContainer.setPropertyValue("height", side) widget.addChild(linkingContainer)
# Recursion ends here # ########################################################################################### #def main(): # #Read in the node tree nodeLoader.readTree() # # #Calls the doNode() (see below) that works recursively through the tree and calls do_element start_node end_node topnode = widget.getMacroValue("TOP") node = PVUtil.getString(pvArray[0]) if not node in nodeLoader.NodeIndex: # check node defined, or try parent, or force to top node if node.find("_"): parent = node.split("_" + node.split("_")[len(node.split("_")) - 1])[0] ConsoleUtil.writeInfo("Update: parent=" + parent) if parent in nodeLoader.NodeIndex: esel = node.split("_")[len(node.split("_")) - 1] node = parent else: node = topnode else: node = topnode dir = os.environ["CSS_SHARE_DIR"] #Now do the same for ..._element.opi. This will make a widget for every element opi_element = dir + "/apps/clasTreeApp/" + topnode + "_element.opi" #Default to top opi_node = node #default to node while not opi_node == topnode: #if not at top node yet
from org.csstudio.opibuilder.scriptUtil import PVUtil, WidgetUtil, ConsoleUtil ch = int(PVUtil.getDouble(pvArray[0])) desc = widget.getPropertyValue("tooltip") #ConsoleUtil.writeInfo(desc) currhv = -1 if len(desc) > 2: ConsoleUtil.writeInfo(desc) currhv = int(desc[desc.find("HVChan") + 7:]) ConsoleUtil.writeInfo("Currhv = " + str(currhv)) if currhv < 0: hv = "1" else: hv = PVUtil.getString(pvArray[1]) if (int(hv) != currhv): widget.removeAllChildren() #clean the area first linkingContainer = WidgetUtil.createWidgetModel( "org.csstudio.opibuilder.widgets.linkingContainer") linkingContainer.setPropertyValue("opi_file", "chan8.opi") linkingContainer.addMacro("ID", str(ch).zfill(3)) #linkingContainer.addMacro("ID", ch) linkingContainer.addMacro("HV", str(hv.zfill(2))) linkingContainer.setPropertyValue("resize_behaviour", 1) linkingContainer.setPropertyValue("border_style", 0) widget.addChild(linkingContainer) widget.setPropertyValue("tooltip", "ChanHV " + hv)
def default_node(node, depth, mode='elem', result=None): global doElems if mode == 'init': #if start of node index = int(nodeLoader.NodeIndex[node]) #Get index from dict if verbose > 0: #if verbose erange = nodeLoader.ElementRange[index].replace("\'", "").split(",") if len(erange) > 1: ConsoleUtil.writeInfo(' ' * depth + "#Node:" + node + " Erange: " + erange[0] + " - " + erange[1]) #print the indented node name if verbose > 1: #if very verbose mode, print record details if any. nrnames = nodeLoader.NodeRecordNames[index].split(",") nrtypes = nodeLoader.NodeRecordTypes[index].split(",") for i in range(len(nrtypes)): if nrtypes[i] != "": ConsoleUtil.writeInfo(' ' * depth + " #NodeRecordName: " + repr(nrnames[i]).ljust(20) + "#NodeRecordType: " + repr(nrtypes[i])) ernames = nodeLoader.ElementRecordNames[index].replace( "\'", "").split(",") ertypes = nodeLoader.ElementRecordTypes[index].replace( "\'", "").split(",") erflags = nodeLoader.ElementRecordFlags[index].replace( "\'", "").split(",") for i in range(len(ertypes)): if ertypes[i] != "": ConsoleUtil.writeInfo(' ' * depth + " #ElementRecordName: " + repr(ernames[i]).ljust(10) + "#ElementRecordType: " + repr(ertypes[i]) + " #ElementRecordFlag: " + repr(erflags[i])) if len(nodeLoader.ElementNames[index]) > 2: linkingContainer = WidgetUtil.createWidgetModel( "org.csstudio.opibuilder.widgets.linkingContainer") linkingContainer.setPropertyValue("opi_file", opi_node_info) linkingContainer.addMacro("P", node) linkingContainer.setPropertyValue("resize_behaviour", 1) linkingContainer.setPropertyValue("border_style", 0) linkingContainer.setPropertyValue("background_color", "OPI_Background") widget.addChildToBottom(linkingContainer) #elif mode == 'elem': #if verbose>0: # ConsoleUtil.writeInfo( ' '*depth+" #Element: "+node) #print the indented elment name # #return None #esel=node.split("_")[len(node.split("_"))-1] #linkingContainer = WidgetUtil.createWidgetModel("org.csstudio.opibuilder.widgets.linkingContainer") #linkingContainer.setPropertyValue("opi_file", opi_element) #linkingContainer.addMacro("P", node) #linkingContainer.addMacro("S", esel) #linkingContainer.addMacro("C", str(eCount)) #linkingContainer.setPropertyValue("resize_behaviour", 1) #linkingContainer.setPropertyValue("border_style", 0) #widget.addChildToBottom(linkingContainer) #ConsoleUtil.writeInfo( ' '*depth+" #Element: "+node+" sel: "+esel) #print the indented elment name elif mode == 'end': if verbose: ConsoleUtil.writeInfo(' ' * depth + "#NodeEnd: " + node) else: return None