Users who want to look at the data as they arrive, may write an application based on the simple Door.
User action: create simpleDoorTest.py and simpleDoor.py in a directory, run simpleDoorTest.py, launch another terminal, start spock and execute e.g. an ascan.
This is simpleDoorTest.py, the program to execute:
#!/usr/bin/env python3 # # file name simpleDoorTest.py # # to test the simple door # import PySpectra, time, HasyUtils import taurus import simpleDoor doorName = 'p09/door/haso107d10.01' def main(): door = taurus.Device( doorName) print( "Press <space> to quit") while 1: PySpectra.processEvents() key = HasyUtils.inkey() if key == 32: return time.sleep( 0.1) return if __name__ == "__main__": main()
This is simpleDoor.py, a door which is imported by simpleDoorTest.py. You will modify the function myAnalysis.
#!/usr/bin/env python ”' this is a simple door, demonstrating how data are received be sure to 'senv JsonRecorder True' ”' import sardana.taurus.core.tango.sardana.macroserver as sms import pprint pp = pprint.PrettyPrinter() sms.registerExtensions() class simpleDoor( sms.BaseDoor): def __init__( self, name, **kw): self.call__init__( sms.BaseDoor, name, **kw) def myAnalysis( dataRecord): """ here goes your code """ pp.pprint( dataRecord) return def recordDataReceived( self, s, t, v): print( ">>> recordDataReceived") dataRecord = sms.BaseDoor.recordDataReceived( self, s, t, v) if dataRecord == None: print( ">>> recordDataReceived, dataRecord == None, return ") return pp.pprint( dataRecord) # # it may happen that no 'type' is in the record, ignore # try: if 'type' not in dataRecord[1]: return except Exception as e: print( "recordDataReceives, check for 'type', exception") print( "%s" % repr( e)) return # # a new scan # if dataRecord[1]['type'] == "data_desc": return if dataRecord[1]['type'] == "record_end": return if not dataRecord[1]['type'] == "record_data": return if not hasattr( self, 'unknownScanType'): return if self.unknownScanType: return # +++ do sommething with the data dataRecord self.myAnalysis( dataRecord) print( ">>> recordDataReceived DONE") return dataRecord # import taurus factory = taurus.Factory() factory.registerDeviceClass( 'Door', simpleDoor) # # returns a simpleDoor #