The following examples demonstrates how a Spk motor position is read from a PLC. IndexGroup and IndexOffset select the process variable.
#!/usr/bin/python from PyTango import * import time, sys, 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 new[6] [termios.VMIN] = 0 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 # # move a motor # def move_to( sps, newPos): # # Freigabe & Regelart 1 # 0xf020: 61472 # 0xf030: 61488 sps.command_inout( "WriteLong", [ 0xf020, 0xc0, 0x8001e]) # control register time.sleep( 0.1) print " Control: 0x%x " % sps.command_inout( "ReadLong", [ 0xf020, 0xc0]) print " Status: 0x%x " % sps.command_inout( "ReadLong", [ 0xf030, 0xe1]) print " Status2: 0x%x " % sps.command_inout( "ReadChar", [ 0xf030, 0xe5]) sps.command_inout( "WriteFloat", [ 0xf020, 0x80, newPos]) time.sleep( 0.1) print " Sollposition ", sps.command_inout( "ReadFloat", [ 0xf020, 0x80]) status = sps.command_inout( "ReadLong", [ 0xf030, 0xe1]) while not (status & 1): status = sps.command_inout( "ReadLong", [ 0xf030, 0xe1]) print " Position: %9g, Status: 0x%x" % \ (sps.command_inout( "ReadFloat", [ 0xf030, 0x80]), status) time.sleep( 0.5) if inkey() == 32: # # control register # bit # 0 -> stopp all # sps.command_inout( "WriteLong", [ 0xf020, 0xc0, 0x80001]) # print " stopping all moves" return 0 return 1 # # main # try : sps = DeviceProxy( "hires/exp/sps2") if( len( sys.argv) == 1): print " Position: %g, Status: 0x%x " % \ (sps.command_inout( "ReadFloat", [ 0xf030, 0x80]), \ sps.command_inout( "ReadLong", [ 0xf030, 0xe1])) 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