The following piece of code plots some data from a Macro, see 7.2.5.
#!/bin/env python3 from sardana.macroserver.macro import * import sys import numpy as np import HasyUtils, PySpectra class toPysp( Macro): ”' demonstrate the HasyUtils.toPyspMonitor() from a Macro ”' param_def = [] result_def = [] def run( self): # # make sure that the pyspMonitor is running # (status, wasLaunched) = PySpectra.assertPyspMonitorRunning() if wasLaunched == 1: self.output( "toPysp: launching pyspMonitor does not work from a Macro.") self.output( " Please start pyspMonitor3.py before.") return self.output( "toPysp: status %d, wasLaunched %d" % (status, wasLaunched)) MAX = 20 pos = np.linspace(0, 10, MAX) d1 = np.random.random_sample( (len( pos), ))*1000. d2 = np.random.random_sample( (len( pos), ))*1000. d3 = np.random.random_sample( (len( pos), ))*1000. hsh = { 'putData': { 'title': "Important Data", 'columns': [ { 'name': "eh_mot01", 'data' : pos}, { 'name': "eh_c01", 'data' : d1}, { 'name': "eh_c02", 'data' : d2}, { 'name': "eh_c03", 'data' : d3}, ]}} hshRet = HasyUtils.toPyspMonitor( hsh) if hshRet[ 'result'].upper() != 'DONE': self.output( "toPysp: returns %s" % hshRet[ 'result']) return hshRet = HasyUtils.toPyspMonitor( { 'command': [ 'display']}) if hshRet[ 'result'].upper() != 'DONE': self.output( "toPysp: returns %s" % hshRet[ 'result']) return HasyUtils.utils.prtc() # # get the data back # hsh = HasyUtils.toPyspMonitor( { 'getData': True}) self.output( "getData received: %s" % repr( hsh)) return