Example: simulate a scan, send pairs of x- and y-values

#!/usr/bin/env python
'''
this script simulates a scan. Pairs of x- and y-values are sent 
to the pyspMonitor.
'''
import random, time
import PySpectra.zmqIfc as zmqIfc

def main():

    (status, wasLaunched) = PySpectra.assertPyspMonitorRunning()

    ret = PySpectra.toPyspLocal( { 'command': ["cls", "delete"]}) 
    if ret[ 'result'].upper() != 'DONE':
        print( "error from pyspMonitor %s" % ret[ 'result'])
        return

    ret = PySpectra.toPyspLocal( { 'command': ["setTitle \"An important title\"", 
                                        "setComment \"An interesting comment\""]}) 

    max = 101
    name = "TestScan"
    ret = PySpectra.toPyspLocal( {'Scan': { 'name': name,
                                     'xMin': 0., 'xMax': 100., 
                                     'yMin': 0., 'yMax': 1.,
                                     'symbol': '+','symbolColor': 'red',
                                     'symbolSize': 7, 'lineColor': 'blue',
                                     'nPts': max,
                                     'autoscaleX': False, 'autoscaleY': True}})
         
    for i in range( max): 
        pos = float(i)
        posY = random.random()*10
        PySpectra.toPyspLocal( { 'command': ['setXY %s %d %s %s' % (name, i, repr(pos), repr(posY))]})
        PySpectra.toPyspLocal( { 'command': ["display"]}) 
        time.sleep( 0.1)

    #
    # if the pyspMonitor was launched by this script, kill it.
    #
    if wasLaunched:
        PySpectra.killPyspMonitor()

    return 

if __name__ == "__main__":
    main()



2020-05-12