# Script to write into channels on the channel mask. # The script is triggered by changes to the local variable asociated with the input text widget. # Orlando Soto, March 2014. from org.csstudio.opibuilder.scriptUtil import PVUtil, ConsoleUtil from org.csstudio.utility.pv import PVFactory import time from java.lang import Thread, Runnable from BCAL_LEDControl_parameters import delay_time # Waiting time to retry. mask = int(widget.getParent().getMacroValue("chmask"),16) # Getting the channel mask from the macro variable "chmask". par = widget.getMacroValue("par") # Getting the macro value for "par", the parameter macro. This allow to copy & paste code and muliple uses. base = 32 # Base channel. PVs = [] # Array to store proccess variables. Left here in case any modification is needed could be just a regular variable. pv0 = PVUtil.getDouble(pvs[0]) # Value to be written. ########## Class to handle the connection ####### class PVconnect(Runnable): # Class inherit from Runnable, this allow to run it in threads. def __init__(self,pv,value): self.pv = pv # PV object self.value = value # Value to be written. return def run(self): pv = self.pv value = self.value pv.start() # Starting the PV. cnt = 0 # Retrying counter. status = pv.isConnected() # Getting connected status. while ( not status) and (cnt<5) : # Retry if is not connected and retry counter is below 5 cnt += 1 Thread.sleep(delay_time) # Wait delay_time for retry. status = pv.isConnected() # Get new connected status. if cnt == 5: # If time out is reached. ConsoleUtil.writeInfo("Error: Timeout to connect with PV %s --- %d (ms)" % (pv.getName(), cnt*delay_time)) if par == 'width': value /= 10 elif par == 'period': if value <> 0: value = 1.0/float(value)/10e-9 else: value = 1000000.0 elif par == 'npulses': value = int(value) else: ConsoleUtil.writeInfo("Parameter %s not found" % par) pv.setValue(value) # Writing value. #ConsoleUtil.writeInfo( "child says: thread: %d %s in cnt: %d running " % (Thread.currentThread().getId(), pv.getValue(),cnt)) return ################################################# pref = widget.getMacroValue("prefpulser1") if widget.getMacroValue("trigSide") == "UP" else widget.getMacroValue("prefpulser2") # Setting the value for "pref". The prefix for the IOC. thread = [] # Thread array. if par == 'npulses' and pv0 <> -1: # Checking if npulses parameter is written and the value is not -1. pvs[1].setValue(0) # Setting continuous button off. Link to the countinuous mode button variable. for i in range(32): if not (mask&(1<