#! /usr/bin/env mpscript # # This script moves the motor to the requested position. # import time #--------------------------------------------------------------------------- def position_callback( callback, args ): nf = callback.nf position = nf.get_local_value() print( "'%s' = %f" % ( nf.name, position ) ) #--------------------------------------------------------------------------- def main( record_list, argv ): if ( len(argv) != 2 ): print( "" ) print( "Usage: mp_move motorname new_position" ) print( "" ) sys.exit(1); motorname = argv[0] new_position = float( argv[1] ) # # Find the motor and verify that it is a 'network_motor' record. # motor = record_list.get_record( motorname ) mx_type = motor.get_field("mx_type") if ( mx_type != "network_motor" ): print( "%s is not an MX network motor. Exiting ..." \ % motorname ) sys.exit(1) # # Get the server record and remote motor name for this network motor. # server_record_name = motor.get_field("server_record") server_record = record_list.get_record(server_record_name) remote_motor_name = motor.get_field("remote_record_name") field_name = "position" # # Create a network field for the remote motor record's 'position' field. # nf_name = "%s.%s" % ( remote_motor_name, field_name ) position_nf = Mp.Net( server_record, nf_name ) # # Add a value changed callback for the 'position' network field. # callback = position_nf.add_callback( Mp.MXCBT_VALUE_CHANGED, \ position_callback, None ) # # Synchronously start the motor move. # units = motor.get_field("units") print( "Moving motor '%s' to %f %s" \ % ( motorname, new_position, units ) ) motor.move_absolute( new_position ) # # Wait for callbacks from the server. # while (1): try: record_list.wait_for_messages(1.0) except Mp.Timed_Out_Error: pass