Example: send data as columns

#!/usr/bin/env python
'''
the script sends 4 columns to the pyspMonitor, displays them
and reads them back. The first column contains the motor position, 
the common x-axis, the other contain counter readings
'''
import PySpectra
import PySpectra.utils as utils
import sys
import numpy as np

def main(): 
    #
    # make sure that the pyspMonitor is running
    #
    (status, wasLaunched) = PySpectra.assertPyspMonitorRunning()

    MAX = 10
    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 = PySpectra.toPyspMonitor( hsh)
    if hshRet[ 'result'].upper() != 'DONE':
        print( "toPyspMonitor: returns %s" % hshRet[ 'result'])
        sys.exit(255)

    hshRet = PySpectra.toPyspMonitor( { 'command': [ 'display']})
    if hshRet[ 'result'].upper() != 'DONE':
        print( "toPyspMonitor: returns %s" % hshRet[ 'result'])
        sys.exit(255)

    utils.prtc()
    #
    # get the data back
    # 
    hsh = PySpectra.toPyspMonitor( { 'getData': True})

    print( "getData received: %s" % repr( hsh))
    #
    # if the pyspMonitor was launched by this script, kill it.
    #
    if wasLaunched:
        PySpectra.killPyspMonitor()
        
    return

if __name__ == "__main__":
    main()



2020-07-03