GrabTrigger#

GrabTrigger.py#
from itala import itala

ACQUIRE_COUNT = 5


def grab_trigger():
    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
    print("Configure trigger mode..")

    # Select the "action" that must be performed when the trigger is received.
    trigger_selector_node = nodemap.TriggerSelector
    if(not itala.is_writable(trigger_selector_node)):
        print("Unable to select the trigger type. Aborting.")
        exit(1)
    trigger_selector_node.from_string("FrameBurstStart")

    # Set the source of the trigger. In this case, a software trigger (which is
    # just a command) is used.
    trigger_source_node = nodemap.TriggerSource
    if(not itala.is_writable(trigger_selector_node)):
        print("Unable to configure the trigger. Aborting.")
        exit(1)
    original_trigger_source = trigger_source_node.get_int_value()
    trigger_source_node.from_string("Software")

    # Finally, enable the trigger mode.
    trigger_mode_node = nodemap.TriggerMode
    if(not itala.is_writable(trigger_selector_node)):
        print("Unable to configure the trigger. Aborting.")
        exit(1)
    original_trigger_mode = trigger_mode_node.get_int_value()
    trigger_mode_node.from_string("On")

    device.start_acquisition()
    print("Acquisition started.")

    trigger_software_node = nodemap.TriggerSoftware
    if(not itala.is_writable(trigger_selector_node)):
        print("Unable to send software trigger command. Aborting.")
        exit(1)
    for i in range(ACQUIRE_COUNT):
        trigger_software_node.execute()
        print("\tSoftware trigger sent, image acquired.")
        input("\tPress Enter to grab the acquired image.")

        image = device.get_next_image(1000)
        if(image.is_incomplete):
            print(f"\n\tImage {image.frame_id} is incomplete.")
            print(f"\t\tBytes filled: {image.bytes_filled}/{image.payload_size}")
            print(f"\t\tTimestamp: {image.timestamp}")
        else:
            print(f"\n\tImage {image.frame_id} grabbed.")

        # DO SOMETHING WITH THE IMAGE
            
        image.dispose()

    device.stop_acquisition()

    # Restore the original values
    trigger_source_node.set_int_value(original_trigger_source)
    trigger_mode_node.set_int_value(original_trigger_mode)

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

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


if __name__ == "__main__":
    try:
        grab_trigger()
    except Exception as e:
        print(str(e))
        exit(1)
    exit(0)