# Set the "value" to the PV with the "suff" suffix for the Bias channels on the Module (all or Group) of the PS import re import os import time import sys from org.csstudio.opibuilder.scriptUtil import PVUtil from org.csstudio.opibuilder.scriptUtil import ConsoleUtil from org.csstudio.utility.pv import PVFactory from org.csstudio.opibuilder.scriptUtil import ColorFontUtil # PS Bias parameters import bs_PSParameters channelAddress = [] # Arr=[] channelEnable = [] def bs_PSModule(value,suff,widget): #from threading import Thread from java.lang import Thread, Runnable Pref= widget.getParent().getMacroValue("pref") ModuleType = widget.getParent().getMacroValue("moduleType") ModuleNumber = widget.getParent().getMacroValue("moduleNumber") #ConsoleUtil.writeInfo("ModuleType = " + str(ModuleType)) #ConsoleUtil.writeInfo("ModuleNumber = " + str(ModuleNumber)) #ConsoleUtil.writeInfo("value = " + str(value)) #ConsoleUtil.writeInfo("suff=" + suff) #-- for Groups if (int(ModuleType)==1): Module=bs_PSParameters.Sectors[int(ModuleNumber)-1] #-- for Channel if (int(ModuleType)==2): Module=bs_PSParameters.BsChannels[int(ModuleNumber)-1] #-- for All if (int(ModuleType)==0): Module=bs_PSParameters.All #-- for Channel # if (int(ModuleType)==2): # i=int(ModuleNumber)-1 # bschan = chr(i+65) # #ConsoleUtil.writeInfo("Channel = " + str(ring)) # for j in range(1, bs_PSParameters.BsNumbers[i]+1): # Arr.append( bschan + ":" + str(j) ) # Module=Arr #----------------------------------------------------------------- NChannels=len(Module) # ConsoleUtil.writeInfo("ChannelsNumber = " + str(NChannels)) for i in range(0,NChannels): PVName =Pref + "PS:bias:" + Module[i] + suff PVEnable=Pref + "PS:bias:" + Module[i] + ":enable" channelAddress.append(PVName) channelEnable.append(PVEnable) #ConsoleUtil.writeInfo("PVEnable = " + PVEnable) #ConsoleUtil.writeInfo("PVName = " + PVName) class MyTask_bs(Runnable): def run(self): # loop over all PS channels and switch the state to NewState for k in range(0,NChannels): str1 = channelAddress[k] str2 = channelEnable[k] #ConsoleUtil.writeInfo( "Connect to "+str1) pvN = PVFactory.createPV(str1) pvN.start() pvE = PVFactory.createPV(str2) pvE.start() cnt = 0 #status0 = pvN.getStateInfo() #status0E = pvE.getStateInfo() #ConsoleUtil.writeInfo( "status of getStateInfo() is "+status0) status1 = pvN.isConnected() status1E = pvE.isConnected() #ConsoleUtil.writeInfo( "status of isConnected() is "+str(status1)) while (( not (status1E)) and( not (status1)) and (cnt<5) ): cnt += 1 time.sleep(bs_PSParameters.sleepTime) #time.sleep(.1) status1 = pvN.isConnected() status1E = pvE.isConnected() if (cnt<5): #ConsoleUtil.writeInfo( "epics variable is connected!") val = pvN.getValue() #ConsoleUtil.writeInfo( "and the value is "+str(val)) ChannelEnable = PVUtil.getLong(pvE) if (ChannelEnable==1): time.sleep(bs_PSParameters.sleepTime) pvN.setValue(value) # else: # ConsoleUtil.writeInfo( "Channel " + str1 + " , Ignor On/Off: Enable value is "+ str(ChannelEnable)) else: ConsoleUtil.writeInfo( "epics channels "+str1+" or/and "+ str2 +" is NOT connected!") pvN.stop() pvE.stop() # this is the end of the loop # this is the end of the task thread thread = Thread(MyTask_bs()) thread.start() #===============================================================================