from PyTango import *
import sys
import time
def set_nbmotors(lensesbox,nb_motors):
"""The set_nbmotors function is used to initialized the given number of motors."""
lensesbox.write_attribute("NbMotors",nb_motors)
def get_nbmotors(lensesbox):
"""The get_nbmotors function is used to read the number of initialized motors."""
print "Number of motors:"
print lensesbox.NbMotors
def set_lensesToMoveIn(lensesbox, lenses):
"""The set_lensesToMoveIn function is used to select the lenses that will go to the IN by performing the next movement."""
values = []
for p in lenses:
values.append(p)
lensesbox.write_attribute("SetIN",values)
def get_lensesToMoveIn(lensesbox):
"""The get_lensesToMoveIn function is used to read the lenses that will go to the IN by performing the next movement."""
dim_x = lensesbox.read_attribute("SetIN").dim_x
if dim_x > 0:
lenses_inout = lensesbox.SetIn
print "Lenses to move In (flaged to 1):"
for lens in lenses_inout:
print lens
def get_statusIN(lensesbox):
"""The get_statusIN function is used to read the status of the lenses (1 IN, 0 OUT)."""
dim_x = lensesbox.read_attribute("StatusIN").dim_x
if dim_x > 0:
lenses_inout = lensesbox.StatusIn
print "Lenses IN (flaged to 1):"
for lens in lenses_inout:
print lens
def get_statusOK(lensesbox):
"""The get_statusOK function is used to read the status of the lenses (1 OK)."""
dim_x = lensesbox.read_attribute("StatusOK").dim_x
if dim_x > 0:
lenses_inout = lensesbox.StatusOK
print "Lenses OK (flaged to 1):"
for lens in lenses_inout:
print lens
def get_statusGeneral(lensesbox):
"""The get_statusGeneral function is used to read the status of the lenses system"""
dim_x = lensesbox.read_attribute("StatusGeneral").dim_x
if dim_x > 0:
lenses_inout = lensesbox.StatusGeneral
dict_general_status = []
dict_general_status.append("Done:")
dict_general_status.append(" Enabled:")
dict_general_status.append(" Power:")
dict_general_status.append(" Busy:")
dict_general_status.append(" Reset:")
i = 0
for lens in lenses_inout:
print dict_general_status[i]
print " " + str(lens)
i = i + 1
def set_position(lensesbox,position):
"""The set_position function is used to move the lenses to the given position (12 bits in decimal)."""
lensesbox.write_attribute("Position",position)
def get_position(lensesbox):
"""The get_position function is used to read the current position (12 bits in decimal)."""
print "Current position (decimal):"
print lensesbox.Position
def move(lensesbox):
"""The move function is used to perform the movement of the lenses"""
lensesbox.Move()
def reboot(lensesbox):
"""The reboot function is used to make a hardware reboot of the system"""
lensesbox.Reboot()
def stop(lensesbox):
"""The reboot function is used to make a hardware reboot of the system"""
lensesbox.Stop()
#
# main
#
try :
lensesbox = DeviceProxy( "//haso111n:10000/exp/lensesbox/1")
if( len( sys.argv) == 1):
get_nbmotors(lensesbox)
get_position(lensesbox)
get_lensesToMoveIn(lensesbox)
get_statusIN(lensesbox)
get_statusOK(lensesbox)
get_statusGeneral(lensesbox)
print " "
print "Run 'python lensesbox.py help' to see program options"
print " "
else:
if(sys.argv[1] == "help"):
print "Usage:"
print "-> to perform movement"
print "python lensesbox.py move"
print "-> to move lenses to the given position"
print "python lensesbox.py setPosition x"
print "where x is the decimal representation of 12 bits (1-> move in)"
print "-> to stop movement"
print "python lensesbox.py stop"
print "-> to reboot"
print "python lensesbox.py reboot"
print "-> to set lenses to move"
print "python lensesbox.py set2move x y z ..."
print "where 'x, y, z ...' would be 0's or 1's"
print "depending on the lenses set for moving in"
print "-> to set number of motors"
print "python lensesbox.py setNbMotors x"
print "where x is the number of motors to be initialized"
print "-> to get information and status"
print "python lensesbox.py"
if(sys.argv[1] == "move"):
print "Moving"
move(lensesbox)
elif(sys.argv[1] == "reboot"):
print "Rebooting"
reboot(lensesbox)
elif(sys.argv[1] == "stop"):
print "Stopping"
stop(lensesbox)
elif(sys.argv[1] == "set2move"):
print "Set lenses to move in "
i = 0
values = []
for lens in sys.argv:
if(i > 1):
values.append(int(sys.argv[i]))
i = i + 1
print values
set_lensesToMoveIn(lensesbox,values)
elif(sys.argv[1] == "setNbMotors"):
print "Set number of motors to "
print sys.argv[2]
set_nbmotors(lensesbox,int(sys.argv[2]))
elif(sys.argv[1] == "setPosition"):
print "Moving lenses"
print sys.argv[2]
set_position(lensesbox,int(sys.argv[2]))
else:
print "Run 'python lensesbox.py help' to see program options"
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