LiquidLens#

from itala import itala

system = itala.create_system()
devices_info = system.enumerate_devices(500)
if(len(devices_info) == 0):
    print("No devices found. Example canceled.")
    exit(1)
if(devices_info[0].access_status != itala.DeviceAccessStatus_AvailableReadWrite):
    print("Target device is unaccessible in RW mode. Example cancelled.")
    exit(1)
device = system.create_device(devices_info[0])
print("First device initialized.")
nodemap = device.node_map

# Enable the liquid lens functionality. Keep the original activation state and restore
# it at the end of the program.
oe_liquid_lens_enable = nodemap.oeLiquidLensEnable
if(not itala.is_writable(oe_liquid_lens_enable)):
    print("Unable to activate liquid lens functionality. Aborting.")
    exit(1)
original_liquid_lens_enable = oe_liquid_lens_enable.value
oe_liquid_lens_enable.value = True

print("Liquid lens functionality enabled.")

# Gather some information about the connected liquid lens.
oe_liquid_lens_temperature = nodemap.oeLiquidLensTemperature
if(not itala.is_readable(oe_liquid_lens_temperature)):
    print("Unable to read liquid lens temperature. Aborting.")
    exit(1)

oe_liquid_lens_serial_number = nodemap.oeLiquidLensSerialNumber
if(not itala.is_readable(oe_liquid_lens_serial_number)):
    print("Unable to read liquid lens serial number. Aborting.")
    exit(1)

print("Connected lens is: " + str(oe_liquid_lens_serial_number.value))
print("Lens temperature: " + str(oe_liquid_lens_temperature.value))

# Liquid lenses can be controlled in current or power mode. In the first case, the
# input given to the lens is an amount of current which leads to a certain
# optical power. The second case is the opposite: by specifing the optical power
# as input, the liquid lens absorbs a certain amount of current.
# Let's start with current mode.
oe_liquid_lens_mode = nodemap.oeLiquidLensMode
if(not itala.is_writable(oe_liquid_lens_mode)):
    print("Unable to configure the liquid lens mode. Aborting.")
    exit(1)
oe_liquid_lens_mode.from_string("CurrentMode")

print("\tCurrent mode enabled.")

# Define the amount of current to be set in mA.
lens_current = 10

# Write it to the node
oe_liquid_lens_current = nodemap.oeLiquidLensCurrent
if(not itala.is_writable(oe_liquid_lens_current)):
    print("Unable to configure the amount of current of the lens. Aborting.")
    exit(1)
oe_liquid_lens_current.value=lens_current

# Read the amount of optical power resulting from the electrical current set
oe_liquid_lens_resulting_power = nodemap.oeLiquidLensResultingPower
if(not itala.is_readable(oe_liquid_lens_resulting_power)):
    print("Unable to read the resulting amount of power from the lens. Aborting.")
    exit(1)

print("\tLens current se to "+str(lens_current)+" mA.")
print("\tResulting lens power is "+str(oe_liquid_lens_resulting_power.value)+" dpt.")

# Switch to power mode
oe_liquid_lens_mode.from_string("PowerMode")
print("\tPower mode enabled.")

# Define the lens power to be set in dpt.
lens_power = 2

# Write it to the node.
oe_liquid_lens_power = nodemap.oeLiquidLensPower
if(not itala.is_writable(oe_liquid_lens_power)):
    print("Unable to configure the amount of power of the lens. Aborting.")
    exit(1)
oe_liquid_lens_power.value = lens_power

# Read the amount of current resulting from the optical power set.
oe_liquid_lens_resulting_current = nodemap.oeLiquidLensResultingCurrent
if(not itala.is_readable(oe_liquid_lens_resulting_current)):
    print("Unable to read the resulting amount of current from the lens. Aborting.")
    exit(1)

print("\tLens se to " + str(lens_power) + " dpt.")
print("\tResulting lens is " + str(oe_liquid_lens_resulting_current.value) + " mA")

# Restore the original lens activation state.
oe_liquid_lens_enable.value = original_liquid_lens_enable

device.dispose()
print("Device instance disposed.")

system.dispose()
print("System instance disposed.")