# 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, February 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 lv_FCALParameters import delay_time # Waiting time to retry. mask = int(widget.getParent().getMacroValue("chmask"),16) # Getting the channel mask from the macro variable "chmask". pref = widget.getMacroValue("pref") # Getting the macro value for "pref". The prefix for the IOC. 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. ########## 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("Timeout trying to connect pv : %s %d (ms)" % (pv.getName(),cnt*delay_time) ) #### Switch case for parameter selection.#### 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(round(value)) # Writing value. pv.stop() #ConsoleUtil.writeInfo( "child says: thread: %d %s in cnt: %d running " % (Thread.currentThread().getId(), pv.getValue(),cnt)) return ################################################# class runInThread(Runnable): # Class to run the script on a thread. def run(self): 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. thread = [] # Thread array. count = 0; # Counter. for i in range(32): if not (mask&(1< -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. th = Thread(runInThread()) # Creating the thread. th.start() # Running the thread.