# running from BCAL_Channels.opi # bild a dinamic list of Bias 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 lv_PSTableChannelSatusColorCrateSlot # PS LV parameters import lv_PSParameters class MyTask_table(Runnable): def __init__(self, wid ) : self.widget = wid #self.widget.removeAllChildren() self.widget.setPropertyValue("height",400.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]; lv_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 All if (int(ModuleType)==0): Module=lv_PSParameters.All #-- for group if (int(ModuleType)==1): Module=lv_PSParameters.Sectors[int(ModuleNumber)-1] NChannels=len(Module) #ConsoleUtil.writeInfo( "NChannels = "+str(NChannels)) for i in range(0,NChannels): shortCHANNUM= Module[i] CHANNUM=Pref + "PS:lv:"+ 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(lv_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", "PSLV_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()