# Set the "value" to the PV with the "suff" suffix for the LV 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 LV parameters import lv_PSParameters channelAddress = [] channelEnable = [] def lv_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=lv_PSParameters.Sectors[int(ModuleNumber)-1] #-- for All if (int(ModuleType)==0): Module=lv_PSParameters.All NChannels=len(Module) # ConsoleUtil.writeInfo("ChannelsNumber = " + str(NChannels)) for i in range(0,NChannels): PVName =Pref + "PS:lv:"+ Module[i] + suff PVEnable=Pref + "PS:lv:"+ Module[i] + ":enable" channelAddress.append(PVName) channelEnable.append(PVEnable) #ConsoleUtil.writeInfo("PVEnable = " + PVEnable) #ConsoleUtil.writeInfo("PVName = " + PVName) class MyTask_lv(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(.1) time.sleep(lv_PSParameters.sleepTime) 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(lv_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_lv()) thread.start() #===============================================================================