# Script to have control over the continuos mode behavior of given channels on the channel mask. # The script is triggered by a local variable, should be changed to an epics variable. # The input text widget for npulses has this Proccess Variable (PV) asociated on his script. # 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. 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 # Previous value. return def run(self): pv = self.pv value = self.value pv.start() # Starting 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) ) if value : # If value is distinct from 0, set continuous mode on. pv.setValue(-1) # Writing -1 (0xFFFFFFFF) on channel npulses register. elif PVUtil.getDouble(pv) == -1 : # If the value is already -1 put 0. pv.setValue(0) # Writing 0. pv.stop() # Stopping PV. return ################################################# 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]) # Getting actual value of npulses. thread = [] # Thread array. Left here in case any modification is needed, could be just a regular variable. for i in range(32): if not (mask&(1<