NodeCallback#

NodeCallback.py#
from itala import itala


def on_payload_size_changed(node: itala.INode):
    print("\ton_payload_size_changed function called.")
    print(f"\tPayloadSize node changed. New value is {node.value}\n")


def node_callback():
    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

    # Get the PixelFormat node and set its value to Mono8 for example
    # purposes. The original value is saved and then restored at the end of
    # the program.
    pixel_format_node = nodemap.PixelFormat
    if(not itala.is_writable(pixel_format_node)):
        print("Unable to configure the pixel format. Aborting.")
        exit(1)
    original_pixel_format = pixel_format_node.get_int_value()
    pixel_format_node.from_string("Mono8")

    # Get PayloadSize node
    payload_size_node = nodemap.PayloadSize
    if(not itala.is_readable(payload_size_node)):
        print("Unable to get the image payload size. Aborting.")
        exit(1)
    print(f"\nThe payload sixe is {payload_size_node.value} with Mono8 format.")

    # Register the callback to the PayloadSize node so that when a
    # change in its value occurs, the function is executed
    callback_handle = itala.register(payload_size_node.node, on_payload_size_changed)
    print("on_payload_size_changed function registered to PayloadSize node.")

    print("Setting pixel format to Mono12p..")

    # Set the pixel format to Mono12p. At this point, the callback gets
    # automatically executed by GenApi since the PayloadSize feature
    # is changed after the new PixelFormat.
    pixel_format_node.from_string("Mono12p")

    # Deregister the callback function when done.
    itala.deregister(callback_handle)

    # Restore the original pixel format value.
    pixel_format_node.set_int_value= original_pixel_format

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

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


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