Example client, Lom

The following examples demonstrates how a Lom motor position is read from a PLC. IndexGroup and IndexOffset select the process variable.

#!/usr/bin/python 

from PyTango import *
import sys
import time

#
# get the current position
#
def get_current( sps, chan):
    return sps.command_inout( "ReadDouble", [ 0xf030, 512])
#
# move a motor
#
def move_to( sps, chan, newPos):
    minPos =  sps.command_inout( "ReadDouble", [ 0xf020, 512])
    maxPos =  sps.command_inout( "ReadDouble", [ 0xf020, 540])
    print " min ", minPos, ", max ", maxPos
    if (newPos > maxPos or newPos < minPos):
	print "\n Position", newPos, "outside limits", minPos, maxPos
	return 0
    sps.command_inout( "WriteDouble", [ 0xf020, 512, newPos])
    sps.command_inout( "WriteChar", [ 0xf020, 0, 1]) # StartAll
    time.sleep( 0.03)
    sps.command_inout( "WriteChar", [ 0xf020, 0, 0])

    status = 1 
    while status & 1:
	status = sps.command_inout( "ReadLong", [ 0xf030, 520])
	errMaster = sps.command_inout( "ReadChar", [ 0xf030, 1])
	print " status", status, ",", get_current( sps, chan), ", err ", errMaster
	time.sleep( 0.2)
    return 1
#
# main
#
try :
    chan = 1
    sps = DeviceProxy( "hires/exp/sps1")

    if( len( sys.argv) == 1):
	print " Current position ", get_current( sps, chan)
    else:
	move_to( sps, chan, float(sys.argv[1]))
    
except Exception, inst :
    print "Failed with exception !"
    print sys.exc_info()[0]
    print type(inst)     # the exception instance
    print inst.args      # arguments stored in .args