def run(self): simuData = array.array('d', range(65536)) value = PVUtil.getDouble(pvs[0]) dataSrc = PVUtil.getString(pvs[1]) if dataSrc == "Linear Sine Wave": for i in range(256): for j in range(256): simuData[i * 256 + j] = math.sin(j * 6 * math.pi / 256 + i * 6 * math.pi / 256 + value) else: for i in range(256): for j in range(256): x = j - 128 y = i - 128 p = math.sqrt(x * x + y * y) simuData[i * 256 + j] = math.sin(p * 2 * math.pi / 256 + value) class UITask(Runnable): def run(self): widget.setValue(simuData) UIBundlingThread.getInstance().addRunnable(currentDisplay, UITask())
def prepare_tabledata(self): if self.s == None: self.tableData = [['', '', '', '', False]] else: self.tableData = [] for l in self.s: idstr = l[0] pvname = l[1] # read PV value curval = "---" restore_flag = l[2] try: ipv = PVUtil.createPV(pvname, self.widget) curval = PVUtil.getString(ipv) except: restore_flag = False if self.savemode: self.tableData.append( [pvname, idstr, curval, restore_flag]) else: self.tableData.append( [pvname, idstr, curval, '---', restore_flag]) if self.savemode: self.colNames = TABLE_HEADER_SAVEMODE else: self.colNames = TABLE_HEADER_LOADMODE self.dataModel = MyTableModel(self.tableData, self.colNames, savemode=self.savemode)
def run(self): while display.isActive(): scan_id = long(display.getVar("LatestPointScanID")) if scan_id > 0: scanInfo = client.getScanInfo(scan_id) statusLabel.setPropertyValue("text", scanInfo.getState().toString()) if scanInfo.getState().isActive(): scanNameLabel.setPropertyValue("text", scanInfo.getName()) commandLabel.setPropertyValue("text", scanInfo.getCurrentCommand()) progressBar.setPropertyValue( "pv_value", scanInfo.getPercentage() / 100.0) # Mark scanned points as green for i in range(table.getRowCount()): xpos = float(table.getCellText(i, 1)) ypos = float(table.getCellText(i, 2)) if ( xpos == PVUtil.getDouble(pvs[1]) and ypos == PVUtil.getDouble(pvs[2]) and scanInfo.getPercentage() >= i * 100.0 / table.getRowCount() ): #To make sure the matched position is set from this scan Display.getDefault().asyncExec( SetRowColor(i, ColorFontUtil.GREEN)) elif scanInfo.getState().isDone(): display.setVar("LatestPointScanID", -1) else: scanNameLabel.setPropertyValue("text", "None") commandLabel.setPropertyValue("text", "") progressBar.setPropertyValue("pv_value", 0) Thread.sleep(1000)
def main(): if spectrumPv.isConnected(): spectrum = PVUtil.getLong(spectrumPv) if spectrum is None: spectrum = 1 else: spectrum = 1 if periodPv.isConnected(): period = PVUtil.getLong(periodPv) if period is None: period = 1 else: period = 1 if modePv.isConnected() and PVUtil.getString(modePv).lower() == "counts": mode = "YC" axis_title = "Counts" else: mode = "Y" axis_title = "Counts/us" widget.setPropertyValue("trace_0_x_pv","$(P)DAE:SPEC:" + str(period) + ":" + str(spectrum) + ":X") widget.setPropertyValue("trace_0_y_pv","$(P)DAE:SPEC:" + str(period) + ":" + str(spectrum) + ":" + mode) widget.setPropertyValue("axis_1_axis_title", axis_title)
def run(self): while display.isActive(): scanInfos = client.server.getScanInfos() findActive = False markedDone = False for scanInfo in scanInfos: if scanInfo.getId() == long( display.getVar("LatestPointScanID")): statusLabel.setPropertyValue( "text", scanInfo.getState().toString()) if scanInfo.getState().isDone(): #mark table to dark gray if it is done. if scanInfo.getId() == long( display.getVar( "LatestPointScanID")) and not markedDone: for i in range(table.getRowCount()): Display.getDefault().asyncExec( SetRowColor(i, ColorFontUtil.DARK_GRAY)) markedDone = True continue if scanInfo.getState().isActive(): scanNameLabel.setPropertyValue("text", scanInfo.getName()) commandLabel.setPropertyValue("text", scanInfo.getCurrentCommand()) progressBar.setPropertyValue( "pv_value", scanInfo.getPercentage() / 100.0) #Mark scanned points as green if scanInfo.getId() == long( display.getVar("LatestPointScanID")): markedDone = False for i in range(table.getRowCount()): xpos = float(table.getCellText(i, 1)) ypos = float(table.getCellText(i, 2)) if ( xpos == PVUtil.getDouble(pvs[1]) and ypos == PVUtil.getDouble(pvs[2]) and scanInfo.getPercentage() >= i * 100.0 / table.getRowCount() ): #To make sure the matched position is set from this scan Display.getDefault().asyncExec( SetRowColor(i, ColorFontUtil.GREEN)) findActive = True if not findActive: scanNameLabel.setPropertyValue("text", "None") commandLabel.setPropertyValue("text", "") progressBar.setPropertyValue("pv_value", 0) Thread.sleep(200)
def get_motor_pvs(): """ Get the PVs containing the names of the motors associated with the specified soft motors """ motor_pvs = [] for name in [PVUtil.getString(pv) for pv in pvs[1:]]: # pvs[0] is for the number of motors if is_unexpanded_macro(name) or len(name) == 0: motor_pvs.append(None) else: # Associate all PVs with the top-level display for ease. Shouldn't be any conflict motor_pvs.append(PVUtil.createPV(display.getMacroValue("P") + name + ":MOTOR", display)) return motor_pvs
def update_channels(this_display, this_pvs): """ Updates the channels available on the summary maintenance page Args: this_display: The display that has called this script. Used to control modification of global CSS variables this_pvs: PVs passed to the script by CSS. Used to control modification of global CSS variables Returns: None """ # Loop through the channels, and if selected add them to the list actioned = PVUtil.getDouble(this_pvs[0]) == 1 if actioned: # Generate the list of included channel names channel_names = list() for crate, slot, channel in get_available_channels(this_pvs[1:1 + get_max_crates(this_display)], this_display): channel_name = get_channel_pv_name(crate, slot, channel) if this_display.getWidget(channel_name).getChild('Include').getValue() == 1: channel_names.append(channel_name) # Create a PV value based on the channel names new_pv_value = " ".join(channel_names) this_display.getWidget('update').getPV().setValue(new_pv_value)
def getWidgetPVString(display, widget): """Fetch value of a widget's PV @param display BOY Display @param widget Widget name @return Value of that PV as string """ pv = display.getWidget(widget).getPV() return str(PVUtil.getString(pv))
def getWidgetPVDouble(display, widget): """Fetch value of a widget's PV @param display BOY Display @param widget Widget name @return Value of that PV as double """ pv = display.getWidget(widget).getPV() return PVUtil.getDouble(pv)
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 getWidgetPVLong(display, widget): """Fetch value of a widget's PV @param display BOY Display @param widget Widget name @return Value of that PV as long """ pv = display.getWidget(widget).getPV() return PVUtil.getLong(pv);
def getWidgetPVDouble(display, widget): """Fetch value of a widget's PV @param display BOY Display @param widget Widget name @return Value of that PV as double """ pv = display.getWidget(widget).getPV() return PVUtil.getDouble(pv);
def run(self): startButton.setEnabled(False) stopButton.setEnabled(True) resetButton.setEnabled(False) bar.setVisible(True) hourText.setEnabled(False) minText.setEnabled(False) secText.setEnabled(False) hour = PVUtil.getLong(hourPV) min = PVUtil.getLong(minPV) sec = PVUtil.getLong(secPV) #remember the values to be reset resetButton.setVar("hour", hour) resetButton.setVar("min",min) resetButton.setVar("sec",sec) timerLabel.setPropertyValue("foreground_color", ColorFontUtil.BLACK) timerLabel.setPropertyValue("text", "Time Left:") stopped=False total = hour*3600+min*60+sec for i in range(total,-1,-1): if not display.isActive(): return if PVUtil.getLong(pvs[0])==0: stopped = True break pvs[1].setValue(100-100*i/total) hourPV.setValue(int(i/3600)) minPV.setValue(int(i%3600/60)) secPV.setValue(int(i%60)) Thread.sleep(1000) timerLabel.setPropertyValue("foreground_color", ColorFontUtil.RED) if stopped: timerLabel.setPropertyValue("text", "Interrupted!") else: timerLabel.setPropertyValue("text", "Time's Up!!!") widget.executeAction(0) pvs[2].setValue(1) Thread(Blink()).start() startButton.setEnabled(True) stopButton.setEnabled(False) resetButton.setEnabled(True) bar.setVisible(False) hourText.setEnabled(True) minText.setEnabled(True) secText.setEnabled(True)
def run(self): i=0 while PVUtil.getLong(pvs[2]) ==1: Thread.sleep(500) timerLabel.setPropertyValue("foreground_color", ColorFontUtil.YELLOW if i%2==0 else ColorFontUtil.RED) i=i+1 timerLabel.setPropertyValue("foreground_color", ColorFontUtil.BLACK)
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 get_pv_value(pv, max_wait=1.0): """ Gets the value of a PV as a string. Returns None if no value available """ steps = 100 for i in range(steps): try: return PVUtil.getString(pv) except: sleep(max_wait/steps) return None
def main(): # Get current PV value curr = PVUtil.getLong(get_pv) # If currently 0, then set to 1 if curr == 0: print "Setting to 1" set_pv.setValue(1) # If currently 1, then set to 0 if curr == 1: print "Setting to 0" set_pv.setValue(0)
def mono_position_height(): initial_energy = PVUtil.getDouble(initial_energy_pv) final_energy = PVUtil.getDouble(final_energy_pv) actual_height = PVUtil.getDouble(actual_height_pv) velo_height = PVUtil.getDouble(velo_height_pv) #calculations 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)) # moving motors to calculated positions # energy_theta #ConsoleUtil.writeInfo ("Movendo os motores para as posicoes calculadas..."); #ConsoleUtil.writeInfo ("E = "); #ConsoleUtil.writeInfo (str(energy)); move_motor(energy_pv, energy) #height second crystal height_before = height + 0.1 move_motor(actual_height_pv, height_before, height_motor_dmov_pv, True) #ConsoleUtil.writeInfo ("height_before = "); #ConsoleUtil.writeInfo (str(height_before)); move_motor(actual_height_pv, height, height_motor_dmov_pv, True)
def get_pvs(self): self.north = PVUtil.getDouble(pvs[0]) self.south = PVUtil.getDouble(pvs[1]) self.east = PVUtil.getDouble(pvs[2]) self.west = PVUtil.getDouble(pvs[3]) self.max_y = PVUtil.getDouble(pvs[4]) self.max_x = PVUtil.getDouble(pvs[5])
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)
def run(self): while display.isActive(): scanInfos = client.server.getScanInfos() findActive = False markedDone = False for scanInfo in scanInfos: if scanInfo.getId() == long(display.getVar("LatestPointScanID")): statusLabel.setPropertyValue("text", scanInfo.getState().toString()) if scanInfo.getState().isDone(): #mark table to dark gray if it is done. if scanInfo.getId() == long(display.getVar("LatestPointScanID")) and not markedDone : for i in range(table.getRowCount()): Display.getDefault().asyncExec(SetRowColor(i, ColorFontUtil.DARK_GRAY)) markedDone=True continue if scanInfo.getState().isActive(): scanNameLabel.setPropertyValue("text", scanInfo.getName()) commandLabel.setPropertyValue("text", scanInfo.getCurrentCommand()) progressBar.setPropertyValue("pv_value", scanInfo.getPercentage()/100.0) #Mark scanned points as green if scanInfo.getId() == long(display.getVar("LatestPointScanID")): markedDone=False for i in range(table.getRowCount()): xpos=float(table.getCellText(i, 1)) ypos=float(table.getCellText(i, 2)) if (xpos == PVUtil.getDouble(pvs[1]) and ypos==PVUtil.getDouble(pvs[2]) and scanInfo.getPercentage() >= i*100.0/table.getRowCount()): #To make sure the matched position is set from this scan Display.getDefault().asyncExec(SetRowColor(i, ColorFontUtil.GREEN)) findActive=True if not findActive: scanNameLabel.setPropertyValue("text", "None") commandLabel.setPropertyValue("text", "") progressBar.setPropertyValue("pv_value", 0) Thread.sleep(200)
def run(self): while display.isActive(): scan_id = long(display.getVar("LatestPointScanID")) if scan_id > 0: scanInfo = client.getScanInfo(scan_id) statusLabel.setPropertyValue("text", scanInfo.getState().toString()) if scanInfo.getState().isActive(): scanNameLabel.setPropertyValue("text", scanInfo.getName()) commandLabel.setPropertyValue("text", scanInfo.getCurrentCommand()) progressBar.setPropertyValue("pv_value", scanInfo.getPercentage()/100.0) # Mark scanned points as green for i in range(table.getRowCount()): xpos=float(table.getCellText(i, 1)) ypos=float(table.getCellText(i, 2)) if (xpos == PVUtil.getDouble(pvs[1]) and ypos==PVUtil.getDouble(pvs[2]) and scanInfo.getPercentage() >= i*100.0/table.getRowCount()): #To make sure the matched position is set from this scan Display.getDefault().asyncExec(SetRowColor(i, ColorFontUtil.GREEN)) elif scanInfo.getState().isDone(): display.setVar("LatestPointScanID", -1) else: scanNameLabel.setPropertyValue("text", "None") commandLabel.setPropertyValue("text", "") progressBar.setPropertyValue("pv_value", 0) Thread.sleep(1000)
def copy_pvs(this_display, this_pvs): """ Copies PVs Args: this_display: The display that has called this script. Used to control modification of global CSS variables this_pvs: PVs passed to the script by CSS. Used to control modification of global CSS variables List of PVs, first one is the trigger, then in pairs which copy to their partner. E.g: ["trigger", "PVA-source", "PVA-target", "PVB-source", "PVB-target", "PVC-source", "PVC-target", ] Returns: None """ # Make sure this has been triggered, then reset the trigger actioned = PVUtil.getDouble(this_pvs[0]) == 1 this_pvs[0].setValue(0) if actioned: these_pvs = iter(this_pvs) # Skip the trigger PV these_pvs.next() # Iterate through PVs, copying every other PV to the next one for value in these_pvs: these_pvs.next().setValue(PVUtil.getDouble(value))
from org.csstudio.opibuilder.scriptUtil import PVUtil from org.eclipse.jface.dialogs import MessageDialog #filePath = display.getWidget("Text Input").getValue() #MessageDialog.openInformation( # None, "Dialog from Hdf5 Script", "HDF5File says: The File is " + filePath); ##############################################################3 fileName = display.getWidget("Text Input").getValue() PVUtil.writePV("vs://CODES/test/input",fileName) PVUtil.writePV("vs://CODES/test/inputtrg",1) MessageDialog.openInformation( None, "Dialog from Hdf5 Script", "HDF5File says: The File is " + fileName);
from org.csstudio.opibuilder.scriptUtil import PVUtil from org.csstudio.opibuilder.scriptUtil import ColorFontUtil table = widget.getTable() nbColPVs = 2 #find index of the trigger PV i = 0 while triggerPV != pvs[i]: i += 1 s = PVUtil.getSeverity(triggerPV) color = ColorFontUtil.WHITE if s == 0: color = ColorFontUtil.GREEN elif s == 1: color = ColorFontUtil.RED elif s == 2: color = ColorFontUtil.YELLOW elif s == 3: color = ColorFontUtil.PINK elif s == 4: color = ColorFontUtil.GREEN # table.setCellBackground(i/nbColPVs, i%nbColPVs + 3, color) if "-CUBHLTS" in triggerPV.getName(): table.setCellText(i / nbColPVs, 3, PVUtil.getString(triggerPV)) table.setCellBackground(i / nbColPVs, 3, color) if "-PLCHLTS" in triggerPV.getName(): table.setCellText(i / nbColPVs, 4, PVUtil.getString(triggerPV)) table.setCellBackground(i / nbColPVs, 4, color)
#loc://$(LCID)_NODE (pv[0]) change, triggering nodeMenuUpdate.py for all buttons. #Warning - some danger of infinite recursion here. Careful" #The $(LCID) macro is used to make local PVs per instance. So several instances could be run from the same CSS #without interfering. #For example loc://$(LCID)_NODE pv is like this: B_SYS_HV_ECAL_SEC1_..... #split into list with elements 0 1 2 3 4 5 #eg - with N for the menu N = 3 * # nodeLoader.readTree() #Read in the node tree n = int(widget.getMacroValue("N")) #Get N,B and NODE topnode = widget.getMacroValue("TOP") node = PVUtil.getString(pvArray[0]) if not node in nodeLoader.NodeIndex: # check node defined, or force to top node node = topnode nlist = node.split( "_") #make a list of the parts of node nlist = (B,SYS,HV,ECAL,SEC1,....) #widget.setPropertyValue("height",24 ) #and size #widget.setPropertyValue("visible","false") #assume invisible until other decision made widget.setPropertyValue("enabled", "false") #assume invisible until other decision made widget.setPropertyValue( "background_color", "OPI_Background") #assume invisible until other decision made
from org.csstudio.opibuilder.scriptUtil import PVUtil from java.lang import System from org.eclipse.jface.dialogs import MessageDialog ok = PVUtil.getDouble(pvs[0]) if ok == 1: userName = System.getProperty("UserName") password = System.getProperty("Password") if userName == "admin" and password == "123456": widget.setPropertyValue("visible", True) else: MessageDialog.openError(None, "Error", "The user name or password is wrong!") pvs[0].setValue(0)
from org.csstudio.opibuilder.scriptUtil import PVUtil, WidgetUtil, ConsoleUtil slotlist = PVUtil.getString(pvArray[0]) #P should be the Crate. eg B_DET_MM_FEU_Cr1 P = widget.getMacroValue("P") C = widget.getMacroValue("CRATE") slots = slotlist.split() #ConsoleUtil.writeInfo(str(slots)) for n in range(0, len(slots)): linkingContainer = WidgetUtil.createWidgetModel( "org.csstudio.opibuilder.widgets.linkingContainer") linkingContainer.setPropertyValue("opi_file", "slot_full.opi") newP = P + "_Cr" + C + "_Sl" + slots[n] #ConsoleUtil.writeInfo(newP) linkingContainer.addMacro("P", newP) linkingContainer.setPropertyValue("width", 862) linkingContainer.setPropertyValue("height", 20) linkingContainer.setPropertyValue("resize_behaviour", 2) #linkingContainer.setPropertyValue("border_style", 2) widget.addChildToBottom(linkingContainer)
from org.csstudio.opibuilder.scriptUtil import PVUtil widgetname = widget.getPropertyValue("pv_name") nameparts = widgetname.split(":") pvname = "CB:CB:HV:BOX:%s:%s:%s:InUse" % (nameparts[4],nameparts[5],nameparts[6]) pv = widget.getPVByName("%s" % pvname) newpvvalue = -1 pvvalue = PVUtil.getLong(pv) if pvvalue == 0: newpvvalue = 1 elif pvvalue == 1: newpvvalue = 0 pv = widget.getPVByName("%s" % pvname) print pv pv.setValue(newpvvalue)
from org.csstudio.opibuilder.scriptUtil import ConsoleUtil from org.csstudio.opibuilder.scriptUtil import PVUtil from org.csstudio.opibuilder.scriptUtil import ColorFontUtil import WidgetUtil value = PVUtil.getDouble(pvs[0]) name = pvs[1].getName() if value == 0: PVUtil.writePV(name, "Model") elif value == 1: PVUtil.writePV(name, "CONST") elif value == 2: PVUtil.writePV(name, "AWG") elif value == 3: PVUtil.writePV(name, "0")
from org.csstudio.opibuilder.scriptUtil import PVUtil, ConsoleUtil pv = widget.getPV() current_value = int(PVUtil.getDouble(pv)) if current_value == 0: pv.setValue(1) else: pv.setValue(0)
from org.csstudio.opibuilder.scriptUtil import PVUtil from org.eclipse.ui import PlatformUI if PVUtil.getDouble(pvs[0]): selection_type = PVUtil.getString(pvs[1]) #if selection_type in ['ch', 'cv', 'fch', 'fcv', 'qs']: selection_type = "Corrector" title = selection_type.upper() + ' Selection' window = PlatformUI.getWorkbench().getActiveWorkbenchWindow() window.getShell().setText(title) pvs[0].setValue(0)
from org.csstudio.opibuilder.scriptUtil import PVUtil value = PVUtil.getDouble(pvs[0]) width = 5*value; oldY=widget.getPropertyValue("y") oldHeight = widget.getPropertyValue("height"); #module in the same directory is visible to this script import WidgetUtil WidgetUtil.setMyBounds(widget, value*40, 500 - width/2, width, width)
from org.csstudio.opibuilder.scriptUtil import PVUtil from org.eclipse.ui import PlatformUI magnet_type = PVUtil.getString(pvs[0]).capitalize() title = magnet_type + ' Power Supply' window = PlatformUI.getWorkbench().getActiveWorkbenchWindow() window.getShell().setText(title)
#Fill PV Name only once if widget.getVar("firstTime") == None: widget.setVar("firstTime", True) i=0 for pv in pvs: 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) color = ColorFontUtil.WHITE if s == 0: color = ColorFontUtil.GREEN elif s == 1: color = ColorFontUtil.RED elif s == 2: color = ColorFontUtil.YELLOW elif s == 3: color = ColorFontUtil.PINK
from org.csstudio.opibuilder.scriptUtil import PVUtil from org.csstudio.opibuilder.scriptUtil import DataUtil macroInput = DataUtil.createMacrosInput(True) boxpv = widget.getPVByName("loc://monitor_box") boxnumber = PVUtil.getLong(boxpv) macroInput.put("BOXNO", "%s" % boxnumber) macroInput.put("BOX", "BOX:%s" % boxnumber) macroInput.put("P", "CB:CB:HV") widgetController.setPropertyValue("macros", macroInput) widgetController.setPropertyValue("opi_file", widgetController.getPropertyValue("opi_file"), True)
from org.csstudio.opibuilder.scriptUtil import PVUtil, ScriptUtil, DataUtil from org.eclipse.ui import PlatformUI ## Get PV error_type = PVUtil.getDouble(pvArray[0]) ## Get Widgets error_window = display.getWidget("Window") error = error_window.getWidget("Error Type") error_cause_1 = error_window.getWidget("Error Cause 1") error_cause_2 = error_window.getWidget("Error Cause 2") ## Set Error Text if error_type == 1: error.setPropertyValue("text", "Matrix measurent request could not be processed.") error_cause_1.setPropertyValue("text", "Automatic correction is running.") elif error_type == 2: error.setPropertyValue("text", "Number of samples could not be set.") error_cause_1.setPropertyValue("text", "Value out of range. Maximun value is 100.") elif error_type == 3: error.setPropertyValue("text", "Orbit average could not be calculated.") error_cause_1.setPropertyValue("text", "Orbit was not correctly read.") elif error_type == 4: error.setPropertyValue("text", "Matrix could not be set.") error_cause_1.setPropertyValue("text", "Automatic correction is running.") error_cause_2.setPropertyValue("text", "Variables are being update.") elif error_type == 5: error.setPropertyValue("text", "Reference orbit could not be set.") error_cause_1.setPropertyValue("text", "Automatic correction is running.") error_cause_2.setPropertyValue("text", "Variables are being update.") elif error_type == 6:
from org.csstudio.opibuilder.scriptUtil import PVUtil from org.csstudio.opibuilder.scriptUtil import ConsoleUtil sys = widget.getMacroValue("SYS") subsys = widget.getMacroValue("SUBSYS") dev = widget.getMacroValue("DEV") par = widget.getMacroValue("PAR") pv_name = sys + "-" + subsys + ":" + dev + ":" + "v0set" text_box = "text_set_voltage_" + par value = display.getWidget(text_box).getPropertyValue("text") PVUtil.writePV(pv_name, value) #ConsoleUtil.writeInfo(value)
from org.csstudio.opibuilder.scriptUtil import PVUtil, ConsoleUtil table = widget.getTable() times = PVUtil.getDoubleArray(pvs[0]) codes = PVUtil.getDoubleArray(pvs[1]) mask = PVUtil.getDoubleArray(pvs[2]) ena = PVUtil.getDoubleArray(pvs[3]) N = min(len(times), len(codes), len(mask), len(ena)) while table.getRowCount() < N: table.insertRow(table.getRowCount()) while table.getRowCount() > N: table.deleteRow(table.getRowCount() - 1) times, codes, mask, ena = times[:N], codes[:N], mask[:N], ena[:N] for row, (T, C, M, EN) in enumerate(zip(times, codes, mask, ena)): table.setCellText(row, 0, str(T)) table.setCellText(row, 1, "%d" % C) table.setCellText(row, 2, "%d" % M) table.setCellText(row, 3, "%d" % EN)
from org.csstudio.opibuilder.scriptUtil import PVUtil, DataUtil import math ref_orbit_pv = pvArray[0] bpm_pos_pv = pvArray[1] orbit_pv = pvArray[2] y_pv = pvArray[3] try: bpm_pos = PVUtil.getDoubleArray(bpm_pos_pv) ref_orbit = PVUtil.getDoubleArray(ref_orbit_pv) orbit = PVUtil.getDoubleArray(orbit_pv) y = DataUtil.createDoubleArray(len(orbit)) for i in range(len(orbit)): y[i] = orbit[i] - ref_orbit[i] y_pv.setValue(y) # Set y axis limits abs_y = [math.fabs(i) for i in y] default = 10 maximum = max(abs_y) if len(abs_y) > 0 else default if maximum <= default: widget.setPropertyValue("axis_1_maximum", default) widget.setPropertyValue("axis_1_minimum", -default) else: widget.setPropertyValue("axis_1_maximum", maximum) widget.setPropertyValue("axis_1_minimum", -maximum) except: pass
from org.csstudio.opibuilder.scriptUtil import PVUtil import datetime pv = pvs[0] s = PVUtil.getTimeInMilliseconds(pv) t = datetime.datetime.fromtimestamp(float(s)/1000.) format = "%H:%M:%S" widget.setPropertyValue("on_label", t.strftime(format)) widget.setPropertyValue("off_label", t.strftime(format))
from org.csstudio.opibuilder.scriptUtil import PVUtil, WidgetUtil, ConsoleUtil import fnmatch import nodeLoader from java.util import Arrays nodeLoader.readTree() #Read in the node tree topnode = widget.getMacroValue("TOP") #Get the top node nodesearch = PVUtil.getString(pvArray[0]) #Get the search string if nodesearch.find(topnode) < 0: #if the search doesn't contain topnode nodesearch = topnode + "*" #force to top + wildcard if nodesearch in nodeLoader.NodeIndex: #if it's a node, tag a wildcard on the end nodesearch = nodesearch + "*" nlist = fnmatch.filter(nodeLoader.NodeNames, nodesearch) #filter on the node search if (len(nlist) >= 1): nlist.sort() #make a sorted list of them else: nlist = ["None"] widget.setPropertyValue("items", Arrays.asList(nlist)) #set the choice list widget.setPropertyValue("pv_value", nlist[0]) #set selected as first in the list
from org.csstudio.opibuilder.scriptUtil import ConsoleUtil from org.csstudio.opibuilder.scriptUtil import PVUtil import WidgetUtil from org.eclipse.jface.dialogs import MessageDialog meas = PVUtil.getString(pvs[0]) temp = PVUtil.getString(pvs[1]) value = PVUtil.getString(pvs[2]) if meas=="" or temp =="" or value == "": MessageDialog.openWarning(None, "Warning", "At least one field is empty!") flag = 0 else: flag = 1 if flag ==1: StringToSend = meas+":"+temp+":"+value PVUtil.writePV("LLRF_USER:CavitySimulator:StringToSendTemp", StringToSend)
def run(self): #this method must be called in UI thread leftAnnotation.setValues(PVUtil.getDouble(leftPV), leftAnnotation.getYValue()) rightAnnotation.setValues(PVUtil.getDouble(rightPV), rightAnnotation.getYValue())
[2,3,3,3,3,3,3,3], [2,3,3,3,3,3,3,2], [3,3,3,3,3,3,3], [2,3,3,3,3,3,3], [2,3,3,3,3,3,2], [3,3,3,3,3,3], [2,3,3,3,3,3], [2,3,3,3,3,2], [3,3,3,3,3], [2,3,3,3,3], [2,3,3,3,2], [3,3,3,3], [2,3,3,3], [2,3,3,2], [3,3,3], [3,2,3], [2,3,2], [3,3]]; panelnum=1 rowcount=1 for i in ARRAY: for j in i: pv = PREFIX+"_ROW"+str(rowcount)+"_PANEL"+str(panelnum)+":pwonoff" PVUtil.writePV(pv,1) panelnum+=1 rowcount+=1 panelnum=1
from org.csstudio.opibuilder.scriptUtil import PVUtil, WidgetUtil, ConsoleUtil nodefull = PVUtil.getString( pvArray[0]) #Full name of the node Eg. B_SYS_HV_ECAL_SEC1 bgcol = widget.getMacroValue("BGCOL") #BG color for button #Write this command as the tooltip, to make it available as a macro for the action (a fudge suggested in the CSS/Boy forum) widget.setPropertyValue("tooltip", nodefull) widget.setPropertyValue("background_color", bgcol)
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)
from org.csstudio.opibuilder.scriptUtil import PVUtil box = 1 while box < 20: level = 0 while level < 5: channel = 0 while channel < 8: getpv = widget.getPVByName("CB:CB:HV:BOX:%s:%s:%s:WriteInUse" % (box, level, channel)) newvalue = PVUtil.getLong(getpv) print newvalue newvalue = int(newvalue) setpv = widget.getPVByName("CB:CB:HV:BOX:%s:%s:%s:InUse" % (box, level, channel)) setpv.setValue(newvalue) channel+=1 level+=1 box+=1
from org.csstudio.opibuilder.scriptUtil import PVUtil, WidgetUtil, DataUtil def add_header(table, header_opi): linkingContainer = WidgetUtil.createWidgetModel("org.csstudio.opibuilder.widgets.linkingContainer") linkingContainer.setPropertyValue("opi_file", header_opi) linkingContainer.setPropertyValue("resize_behaviour", 1) linkingContainer.setPropertyValue("border_style", 0) table.addChildToBottom(linkingContainer) device_type = PVUtil.getString(pvs[0]).lower() if device_type == 'bpm': left_header_opi = "table/selection_table_bpm.opi" elif device_type == 'ch': left_header_opi = "table/selection_table_ch.opi" elif device_type == 'cv': left_header_opi = "table/selection_table_cv.opi" up_header_opi = "table/selection_table_up_header.opi" low_header_opi = "table/selection_table_low_header.opi" table_container = display.getWidget("table_container") if device_type is None: table_container.setPropertyValue("visible", False) else: add_header(table_container, up_header_opi) add_header(table_container, left_header_opi) add_header(table_container, low_header_opi)
from org.csstudio.opibuilder.scriptUtil import PVUtil, DataUtil, ConsoleUtil from math import sqrt rms_pv = pvArray[1] mean_pv = pvArray[2] max_pv = pvArray[3] min_pv = pvArray[4] try: y = PVUtil.getDoubleArray(pvArray[0]) rms_val = sqrt(sum([pow(y_i,2) for y_i in y])/len(y)) mean_val = sum(y)/len(y) max_val = max(y) min_val = min(y) widget.getWidget("RMS").setPropertyValue("text", int(rms_val)) widget.getWidget("Mean").setPropertyValue("text", int(mean_val)) widget.getWidget("Max").setPropertyValue("text", int(max_val)) widget.getWidget("Min").setPropertyValue("text", int(min_val)) except: pass
#!/bin/python # Description: Automatically turn on or off the frequency offset # based on the frequency offset value from org.csstudio.opibuilder.scriptUtil import PVUtil # pvs[0] = $(TS)$(LLRF):DRV0:sel2_phstep_ao # pvs[1] = $(TS)$(LLRF):DRV0:sel2_dds_bo # Get the scalar value val = PVUtil.getLong(pvs[0]) # Set the boolean value based on this: if val != 0: pvs[1].setValue(1) # Turn it on elif val == 0: pvs[1].setValue(0) # Turn it off
from org.csstudio.opibuilder.scriptUtil import PVUtil, WidgetUtil, ConsoleUtil 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)
from org.csstudio.opibuilder.scriptUtil import PVUtil import time sys = widget.getMacroValue("SYS") subsys = widget.getMacroValue("SUBSYS") dev = widget.getMacroValue("DEV") par = widget.getMacroValue("PAR") pv_name_absolute_angle = sys + "-" + subsys + ":" + dev + ":SEQ:Aabs" pv_name_absolute_move = sys + "-" + subsys + ":" + dev + ":SEQ:Mabs" widget_text_box = "text_user_" + par widget_text_box_value = display.getWidget(widget_text_box).getPropertyValue( "text") PVUtil.writePV(pv_name_absolute_angle, widget_text_box_value) time.sleep(0.5) PVUtil.writePV(pv_name_absolute_move, "1")
from org.csstudio.opibuilder.scriptUtil import PVUtil op1=PVUtil.getDouble(pvs[0]) op2=PVUtil.getDouble(pvs[1]) operator = PVUtil.getString(pvs[2]) resultPV=pvs[3] if operator=="+": resultPV.setValue(op1 + op2) elif operator=="-": resultPV.setValue(op1 - op2) elif operator=="*": resultPV.setValue(op1 * op2) elif operator=="/": resultPV.setValue(op1 / op2)
from org.csstudio.opibuilder.scriptUtil import PVUtil from org.csstudio.opibuilder.scriptUtil import ColorFontUtil table = widget.getTable() nbColPVs = 2 #find index of the trigger PV i = 0 while triggerPV != pvs[i]: i += 1 table.setCellText(i / nbColPVs, i % nbColPVs + 3, PVUtil.getString(triggerPV)) s = PVUtil.getSeverity(triggerPV) color = ColorFontUtil.WHITE if s == 0: color = ColorFontUtil.GREEN elif s == 1: color = ColorFontUtil.RED elif s == 2: color = ColorFontUtil.YELLOW elif s == 3: color = ColorFontUtil.PINK table.setCellBackground(i / nbColPVs, i % nbColPVs + 3, color)
[2,3,3,3,3,3,3,3], [2,3,3,3,3,3,3,2], [3,3,3,3,3,3,3], [2,3,3,3,3,3,3], [2,3,3,3,3,3,2], [3,3,3,3,3,3], [2,3,3,3,3,3], [2,3,3,3,3,2], [3,3,3,3,3], [2,3,3,3,3], [2,3,3,3,2], [3,3,3,3], [2,3,3,3], [2,3,3,2], [3,3,3], [3,2,3], [2,3,2], [3,3]]; panelnum=1 rowcount=1 for i in ARRAY: for j in i: pv = PREFIX+"_ROW"+str(rowcount)+"_PANEL"+str(panelnum)+":pwonoff" PVUtil.writePV(pv,0) panelnum+=1 rowcount+=1 panelnum=1