00001 #!/usr/local/bin/python 00002 # 00003 # Copyright 2002 00004 # by 00005 # The Board of Trustees of the 00006 # Leland Stanford Junior University. 00007 # All rights reserved. 00008 # 00009 00010 __facility__ = "Online" 00011 __abstract__ = "Example TKR test application" 00012 __author__ = "R. Claus <Claus@SLAC.Stanford.edu> SLAC - GLAST LAT I&T/Online" 00013 __date__ = "11/21/2002" 00014 __version__ = "$Revision: 1.2 $" 00015 __credits__ = "SLAC" 00016 00017 import LATTE.copyright_SLAC 00018 00019 import threading 00020 from sihippo import * 00021 from time import sleep, time 00022 import logging as log 00023 00024 from LATTE.runcontrol.rcTransitions import rcTransitions 00025 from LATTE.runcontrol.ArgumentImpl import ArgumentImpl 00026 00027 # This class puts up a GUI for inputting a value of some sort. It is used by 00028 # the userApplication example to get the number of self triggers to take. 00029 class userArgument(ArgumentImpl): 00030 "GUI for getting the user to input some sort of value." 00031 def __init__(self, parent = None, name = None, modal = 0, fl = 0): 00032 ArgumentImpl.__init__(self, parent, name, modal, fl) 00033 self.__value = 0 00034 self.setCaption("Hello world!") 00035 00036 def OKButtonClicked(self): 00037 self.__value = int(self.ArgumentList.text().latin1()) 00038 self.close() 00039 00040 def CancelButtonClicked(self): 00041 self.__value = None 00042 self.close() 00043 00044 def getValue(self, caption): 00045 self.setCaption(caption) 00046 self.show() 00047 self.exec_loop() 00048 return self.__value 00049 00050 class userArgText(object): 00051 "Text user interface for getting the user to input some sort of value" 00052 def __init__(self): 00053 pass 00054 00055 def getValue(self, caption): 00056 return int(raw_input("%s: " % (caption))) 00057 00058 00059 # Example application implementation. 00060 # Note that the name of the class must be userApplication. 00061 # Look at rcTransitions for names of other transition methods that can be used. 00062 class userApplication(rcTransitions): 00063 "Implmentation class for a user application" 00064 def __init__(self, gui, userId, debug): 00065 rcTransitions.__init__(self, gui, userId, debug) 00066 log.debug("userApplication.__init__()") 00067 self.__cmdSynchSem = threading.Semaphore(0) 00068 00069 def getName(self): 00070 return __name__ 00071 00072 def setup(self): 00073 log.debug("userApplication.setup()") 00074 if self.gui is None: 00075 self.__arg = userArgText() 00076 else: 00077 self.__arg = self.gui.createGUI(userArgument, self.gui, 'test1', 1) 00078 00079 self.gui.execGUImethod(self.__initHippo) 00080 00081 # A state transition can be rejected by not returning None 00082 return None 00083 00084 00085 def startRun(self): 00086 log.debug("userApplication.startRun()") 00087 self.__cmdSynchQuit = False 00088 caption = "Enter number of data groups to read" 00089 if self.gui is None: 00090 cnt = self.__arg.getValue(caption) 00091 else: 00092 cnt = self.gui.execGUImethod(self.__arg.getValue, caption) 00093 00094 # The user pressed 'Cancel' 00095 if cnt is None: return -1 00096 self.__cnt = cnt 00097 00098 self.gui.execGUImethod(self.__initPlots) 00099 00100 # A state transition can be rejected by not returning None 00101 return None 00102 00103 def stopRun(self): 00104 self.__cmdSynchQuit = True 00105 00106 # The STOP_RUN transition can not be rejected 00107 00108 def stop (self): 00109 return self.stopRun() 00110 00111 def teardown(self): 00112 log.debug("userApplication.teardown()") 00113 # Allow the C++ object to be deleted 00114 if self.gui is not None and self.__arg is not None: 00115 self.__arg.deleteLater() 00116 00117 def process(self, (status, buffer)): 00118 "Method called back for each data event taken" 00119 ###print "userApplication.process()" 00120 00121 #def __commandSynch(self, count): 00122 def commandSynch(self): 00123 "Method called by the command synchronization task" 00124 cnt = 0 00125 count = self.__cnt 00126 tic = self.lat.TEM[0].TIC 00127 while cnt < count and not self.__cmdSynchQuit: 00128 cnt = cnt + 1 00129 volts = tic.adc_tem_digital_3_3v 00130 amps = tic.adc_tem_digital_3_3i 00131 self.__nt.addRow([cnt, volts]) 00132 self.__nt2.addRow([cnt, amps]) 00133 sleep(.1) 00134 00135 # Get out of waiting when in standalone mode 00136 self.sync() 00137 00138 # execute the GUI functions for stopRun, just in case 00139 if not self.__cmdSynchQuit and not self.isRunFromSuite(): 00140 if self.rc is not None: 00141 self.rc.doStop() 00142 00143 00144 def wait(self): 00145 self.__cmdSynchSem.acquire() 00146 00147 def sync(self): 00148 if __name__ == "__main__": 00149 self.__cmdSynchSem.release() 00150 00151 def __initHippo(self): 00152 label1 = ['Time', 'TEM Voltage'] 00153 label2 = ['Time', 'TEM Current'] 00154 ntc = NTupleController.instance() 00155 self.__nt = ntc.createCircularBuffer(2) 00156 self.__nt2 = ntc.createCircularBuffer(2) 00157 self.__nt.setLabels(label1) 00158 self.__nt2.setLabels(label2) 00159 self.__nt.setTitle('GTIC Test') 00160 self.__nt2.setTitle('GTIC Test2') 00161 self.__nt.reserve(100) 00162 self.__nt2.reserve(100) 00163 if __name__ == "__main__": 00164 app = QApplication ( sys.argv ) 00165 self.__canvas = CanvasWindow() 00166 self.__canvas.show() 00167 else: 00168 wc = WindowController.instance() 00169 self.__canvas = wc.currentCanvas() 00170 00171 dc = DisplayController.instance() 00172 00173 def __initPlots(self): 00174 self.__canvas.clear() 00175 00176 self.__nt.clear() 00177 self.__nt2.clear() 00178 00179 #self.__nt.setIntervalCount ( 500 ) 00180 #self.__nt2.setIntervalCount ( 100 ) 00181 dc = DisplayController.instance() 00182 self.__hist = dc.createDisplay('Strip Chart',self.__nt,['Time', 'TEM Voltage']) 00183 self.__hist2 = dc.createDisplay('Strip Chart',self.__nt2,['Time', 'TEM Current']) 00184 self.__canvas.addDisplay(self.__hist) 00185 self.__canvas.addDisplay(self.__hist2) 00186 self.__hist.setRange ( 'y', 2660, 2680 ) 00187 self.__hist2.setRange ( 'y', 200, 300 ) 00188 #self.__canvas.setIntervalEnabled ( 1 ) 00189 self.__canvas.show() 00190 00191 if __name__ == "__main__": 00192 ua = userApplication(None, 321, 0) 00193 ua.rcSetup('../repos/simpleTEMSchema.xml') 00194 ua.rcStartRun() 00195 ua.wait() 00196 ua.rcStopRun() 00197 ua.rcTeardown() 00198 raw_input("Press any key to end") 00199 00200 # History: 00201 # $Log: hTestEnv.py,v $ 00202 # Revision 1.2 2004/08/18 18:00:15 stuvi 00203 # Updated for LATTE 4. 00204 # All hippo functions go through the Qt GUI bridge now. 00205 # 00206 # Revision 1.1 2004/08/07 02:14:33 stuvi 00207 # no message 00208 # 00209 # Revision 1.8 2004/04/17 02:22:17 stuvi 00210 # Various Hippo related fixes 00211 # Added teardown() to delete the C++ object for the userArgument 00212 # 00213 # Revision 1.7 2004/04/08 00:32:39 stuvi 00214 # Modularized hippodraw code. 00215 # Changed tuples to circular buffer. 00216 # 00217 # Revision 1.6 2004/03/10 22:24:50 panetta 00218 # Upgraded trigger interface. 00219 # Removed dependencies on self.glt. 00220 # 00221 # Revision 1.5 2004/02/24 02:13:34 stuvi 00222 # Changes for long transition support. 00223 # 00224 # Revision 1.4 2003/07/17 00:01:35 stuvi 00225 # no message 00226 # 00227 # Revision 1.3 2003/03/31 19:28:53 stuvi 00228 # Fixed name 00229 # 00230 # Revision 1.2 2003/03/26 21:59:36 stuvi 00231 # Fixed standalone mode 00232 # 00233 # Revision 1.1 2003/03/11 21:20:54 stuvi 00234 # Moved from RunControl directory 00235 # 00236 # Revision 1.3 2003/02/06 05:20:22 claus 00237 # Added resume; StopRun bug fix 00238 # 00239 # Revision 1.2 2003/01/16 02:38:25 stuvi 00240 # Removed extra stuff 00241 # 00242 # Revision 1.1 2002/12/10 00:59:16 stuvi 00243 # Runcontrol example that uses Hippo. Currently it doesn't work in GUI mode. 00244 # 00245 # Revision 1.4 2002/12/02 17:17:09 claus 00246 # Added provision to allow application to run stand-alone 00247 # 00248 # Revision 1.3 2002/11/28 02:02:04 claus 00249 # Shuffled constructor arguments 00250 # 00251 # Revision 1.2 2002/11/27 23:49:27 claus 00252 # Initialize semaphore with zero count 00253 # 00254 # Revision 1.1 2002/11/27 05:02:48 claus 00255 # Initial version of Run Control 00256 #