# running from PSLV_Channels.opi # bild a dinamic list of LV Channels # # from org.csstudio.opibuilder.scriptUtil import PVUtil from org.csstudio.opibuilder.scriptUtil import WidgetUtil from org.csstudio.opibuilder.scriptUtil import ConsoleUtil from org.csstudio.utility.pv import PVFactory from org.csstudio.opibuilder.scriptUtil import ColorFontUtil from java.lang import Thread, Runnable import re import os import time import sys import threading import bs_PSTableChannelSatusColorCrateSlot # PS Bias parameters import bs_PSParameters class MyTask_table(Runnable): def __init__(self, wid ) : self.widget = wid #self.widget.removeAllChildren() self.widget.setPropertyValue("height",500.0) self.lc = [] self.addedChannels = [] return def AddContainer(self) : columnMutex.acquire() for iLC in range( 0, len(self.lc) ): self.widget.addChildToBottom( self.lc[iLC] ) #ConsoleUtil.writeInfo("Added "+str(iLC+1) + " of" + str(len(self.lc))) #ConsoleUtil.writeInfo("Added PVName "+str(self.addedChannels[iLC]) ) lcName = self.lc[iLC].getPropertyValue("name") pvName = self.addedChannels[iLC]; bs_PSTableChannelSatusColorCrateSlot.getChannelSatusColorCrateSlot( self.widget, lcName, pvName ) columnMutex.release() return #----- def run(self): columnMutex.acquire() Arr=[] channelEnable = [] Pref= widget.getParent().getMacroValue("pref") ModuleType = widget.getParent().getMacroValue("moduleType") ModuleNumber = widget.getParent().getMacroValue("moduleNumber") SelectionModule = widget.getParent().getMacroValue("moduleName") ##-- 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 #----------------- NChannels=len(Module) #ConsoleUtil.writeInfo( "NChannels = "+str(NChannels)) for i in range(0,NChannels): shortCHANNUM= Module[i] CHANNUM=Pref + "PS:bias:"+ Module[i] #----------- PVEnable = CHANNUM + ":enable" pvE = PVFactory.createPV(PVEnable) pvE.start() cnt = 0 #status0E = pvE.getStateInfo() #ConsoleUtil.writeInfo( "status of getStateInfo() is "+status0) status1E = pvE.isConnected() #ConsoleUtil.writeInfo( "status of isConnected() is "+str(status1)) while (( not (status1E)) and (cnt<5) ): cnt += 1 #time.sleep(0.1) time.sleep(bs_PSParameters.sleepTime) status1E = pvE.isConnected() if (cnt<5): #ConsoleUtil.writeInfo( "epics variable is connected!") ChannelEnable = PVUtil.getLong(pvE) if (ChannelEnable==1): #ConsoleUtil.writeInfo( "=====epics variable is connected!") locLC = WidgetUtil.createWidgetModel("org.csstudio.opibuilder.widgets.linkingContainer") locLC.setPropertyValue("opi_file", "PSBS_channel.opi") locLC.setPropertyValue("auto_size", True) locLC.setPropertyValue("zoom_to_fit", False) locLC.setPropertyValue("border_style", 0) locLC.setPropertyValue("x", 0 ) locLC.setPropertyValue("name", "LC" + str(i) ) locLC.addMacro("CHANNUM", CHANNUM) locLC.addMacro("shortCHANNUM", shortCHANNUM) self.addedChannels.append(CHANNUM) self.lc.append( locLC ) else: ConsoleUtil.writeInfo( "epics channels "+ PVEnable + " is NOT connected!") pvE.stop() columnMutex.release() return ############################################################################################### task = MyTask_table( widget ) columnMutex = threading.BoundedSemaphore(1) thread = Thread( task ) thread.start() Thread.sleep(1) #task.AddContainer() while( not columnMutex.acquire( 0 ) ) : #ConsoleUtil.writeInfo( "Locked" ) Thread.sleep( 1 ) columnMutex.release() #ConsoleUtil.writeInfo( "Now unlocked" ) task.AddContainer()