NodeMapPolling#

from itala import itala
import time 

TEMPERATURE_READS = 10
POLL_FREQ_S = 750

def OnDeviceTemperatureChanged(node):
    print("\tOnDeviceTemperatureChanged function called.")
    print("\tDevice temperature node changed. New value is " + str(node.value) +" C\n")

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

device_temperature_node = nodemap.DeviceTemperature
if(not itala.is_readable(device_temperature_node)):
    print("DeviceTemperature feature not available. Aborting.")
    exit(1)

# Register the OnDeviceTemperatureChanged callback to the DeviceTemperature node
callback_handle = itala.register(device_temperature_node.node, OnDeviceTemperatureChanged)
print("OnDeviceTemperatureChanged register to Deviceemperature node\n")

for i in range(TEMPERATURE_READS):
    # Sleep for a bit
    time.sleep(POLL_FREQ_S*0.001)
    print("Polling temperature...")

    # And then poll nodes of the map. At this point, all nodes with a polling time
    # shorter than the elapsed time are updated and their callback executed, if any.
    nodemap.poll(POLL_FREQ_S)

itala.deregister(callback_handle)

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

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