Example Client

The following client operates a TangoMotor. Depending on the command line the current position is read or, if a destination is supplied, the motor is moved.

#!/usr/bin/python 
#
from PyTango import *
import sys, time, termios

init = 0

def move_to( sps, newPos):
    attr= sps.read_attribute( "UnitLimitMin")
    minPos =  attr.value
    attr = sps.read_attribute( "UnitLimitMax")
    maxPos =  attr.value
    print " min ", minPos, ", max ", maxPos
    if (newPos > maxPos or newPos < minPos):
	    print "\n Position", newPos, "outside limits", minPos, maxPos
	    return 0

    posAttr = sps.read_attribute( "Position")
    posAttr.value = newPos
    sps.write_attribute( posAttr)
    status = 1 
    while (sps.state() == DevState.MOVING):
	    print " Current position ",sps.read_attribute( "Position").value
	    time.sleep( 0.2)
    return 1	
#
# main
#
try :
    sps = DeviceProxy( "//haso107XX:10000/pXX/tcpipmotorp10/exp.01")

    if( len( sys.argv) == 1):
	    print " Current position ", sps.read_attribute( "Position").value
    else:
	    move_to( sps, 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