# Given a channel mask for the upper 32 output channels of BCAL LED pulsers (16 for Up and 16 for Down), the Start mask and stop mask is written. # This script performs an OR over the start mask over the selected side (upstream or downstream) # Here, only changes on the F connector are applied. # This script is triggered by changes on the start masks of the pulsers. # Orlando Soto, March 2014 from org.csstudio.opibuilder.scriptUtil import PVUtil, ConsoleUtil from java.lang import Thread, Runnable LEDStartMask = int(PVUtil.getDouble(pvs[1])) # Getting the start mask for BCAL LED pulser channels (16 for Up and 16 for Down). oldStartMask = int(PVUtil.getDouble(pvs[2])) # Getting the old start mask for the 23 upper pulser channels. chann_mask = int(widget.getMacroValue("chmask"),16) # Getting the BCAL LED pulser channel mask from the macro value "chmask", the value is read on base 16 (hex). apply_changes = 0x00078000 # This variable define where the changes must be performed and by definition, the complementary channels. class runInThread(Runnable): # Class to run the script on a thread. Inherit from Runnable, this allow to run it in threads. def run(self): mask = 0x0000FFFF if widget.getMacroValue("trigSide")=="UP" else 0xFFFF0000 # Select start mask portion depending on which side is indicated in the "trigSide" macro, Up or DOWN. #ConsoleUtil.writeInfo("LED mask = %x, mask = %x and = %x" % (LEDStartMask, mask, LEDStartMask & mask)) if PVUtil.getDouble(pvs[0]): # If start button is on. if LEDStartMask & mask: # Perform the OR over the start mask. #ConsoleUtil.writeInfo("I'm into the truth") mask = (oldStartMask & ~apply_changes) | chann_mask # Start mask bits for the four lower channels of the F connector are set. pvs[3].setValue(mask) # Updating the start mask pvs[4].setValue(0) # Stop pulsing. pvs[4].setValue(1) # Start pulsing. else: #ConsoleUtil.writeInfo("I'm into the untruth") mask = (oldStartMask & ~apply_changes) # The start mask bits for the four lower channels of the F connector are unset. pvs[3].setValue(mask) # Updating the start mask else: # If start button is off. pvs[4].setValue(0) # Stop pulsing. th = Thread(runInThread()) # Creating the thread. th.start() # Running the thread.