Example Client

The following script moves a Spk motor. If no destination is supplied, the current position is displayed.

#!/usr/bin/python 

from PyTango import *
import sys, time, termios

init = 0

def inkey():
    global init
    if( not init):
	init = 1
	fd = sys.stdin.fileno()
	old = termios.tcgetattr( fd)
	new = termios.tcgetattr( fd)
	new[3] = new[3] & ~termios.ICANON & ~termios.ECHO
	#
	# VMIN - the minimum number of characters to be read
	#
	new[6] [termios.VMIN] = 0
	#
	# VTIME - how long the driver waits for VMIN characters, unit 0.1s
	#
	new[6] [termios.VTIME] = 1
	termios.tcsetattr( fd, termios.TCSADRAIN, new)
	sys.exitfunc = lambda: termios.tcsetattr( fd, termios.TCSADRAIN, old)
	    
    key = sys.stdin.read(1)
    if( len( key) == 0):
	key = -1
    else:
	key = ord( key)
    return key
#
#
#
def move_to( proxy, newPos):
    proxy.write_attribute( "Position", newPos)   
    while( proxy.state() == DevState.MOVING):
        print " state ", proxy.state()
	print " Current position ",proxy.read_attribute( "Position").value
	time.sleep( 0.5)
	if inkey() == 32:
	    print " stopping all moves"
	    proxy.command_inout( "StopMove")
	    return 0
#
# main
#
try :
    proxy = DeviceProxy( "//haso107tk:10000/hires/exp/spk1")

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