# Simple python script to poll or update nodes

**URL:** <https://forum.commonvisionblox.com/t/simple-python-script-to-poll-or-update-nodes/2116>\
**Category:** Python API\
**Tags:** genicam, python\
**Created:** [February 13, 2024, 12:01pm UTC](https://forum.commonvisionblox.com/t/simple-python-script-to-poll-or-update-nodes/2116 "2024-02-13T12:01:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![adam.honeybell](https://avatars.discourse-cdn.com/v4/letter/a/ce73a5/32.png) [@adam.honeybell](https://forum.commonvisionblox.com/u/adam.honeybell)\
**Post date:** [February 13, 2024, 12:01pm UTC](https://forum.commonvisionblox.com/t/simple-python-script-to-poll-or-update-nodes/2116/1 "2024-02-13T12:01:23Z")

</div>

My company make lighting controllers and support various registers for controlling behaviour. I need a way to periodically read the data, but I don’t seem to be able to do so after the first connection and read. What should I do? Below is the script I’ve written so far…

```auto
def main3():
    device = None

    readable_nodes = (
        cvb.IntRegNode, 
        cvb.FloatNode, 
        cvb.IntegerNode,
        cvb.EnumerationNode, 
        cvb.CommandNode, 
        cvb.StringRegNode, 
        cvb.BooleanNode)

    nodes_to_read = (
        "Cust::ChannelDutyCycle",
        "Cust::ChannelLoadCurrent",
        "Cust::ChannelLoadVoltage",
        "Cust::ControllerTemperature",
        "Cust::TriggerCount"
    )

    try:
        serial_number = "920062"
        device = connect_to_controller(serial_number)

        if device is not None:
            dev_node_map = device.node_maps["Device"]                        
            
            for t in range(5):                
                for name, node in dev_node_map.nodes.items():
                    try:                        
                        if isinstance(node, readable_nodes):
                            # print(dir(node))
                            if node.is_readable:
                                if node.name in nodes_to_read:
                                    print(f"{node.name}, {node.display_name}, {node.description}, {node.tool_tip}, {node.value}")
                        else:
                            pass
                            # print(node.name)
                            # print(type(node))
                    
                    except Exception as e:
                        print("Exception reading node: " + str(e))

                time.sleep(5)
                dev_node_map.poll_nodes()
                dev_node_map.nodes.update()
                
    
    except Exception as e:
        print(e)

    finally:
        if device is not None:
            device.close()

main3()

```

---

<div class="post-metadata">

**Author:** ![Chris](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/chris/32/1154_2.png) [@Chris](https://forum.commonvisionblox.com/u/Chris)\
**Post date:** [February 14, 2024, 1:29pm UTC](https://forum.commonvisionblox.com/t/simple-python-script-to-poll-or-update-nodes/2116/2 "2024-02-14T13:29:10Z")

</div>

Hi @adam.honeybell

if you know which nodes you want to read, there is no need to query all of the nodes.

Here is a simple example:

```py

import os 
import cvb    

# Read and write values from/to NodeMap 
#Tested With Dalsa Genie Nano, names of Nodes may be different on other devices   

# Load driver -> You can keep your routine to open a device here with your
# connect_to_controller() as this seems to be working fine.
device = cvb.DeviceFactory.open(os.path.join(cvb.install_path(), "drivers", "GenICam.vin"), port=0) 

#Load NodeMap for the device  
dev_node_map = device.node_maps["Device"]   
camModel = dev_node_map["DeviceModelName"]  
print("Loaded device: " + camModel.value)  

camFirmware = dev_node_map["DeviceFirmwareVersion"]  
print("Current Firmwareversion : " + camFirmware.value)  

exposureTime = dev_node_map["ExposureTime"] 
print("Current exposure time : " + str(exposureTime.value))  
exposureTimeOld = exposureTime.value 

exposureTime.value = 32  
print("Small exposure time : " + str(exposureTime.value))  

exposureTime.value = exposureTimeOld 
print("Resetted to old exposure time : " + str(exposureTime.value)) 

```

So in your case you would only want to iterate through your nodes\_to\_read and check the nodemap at the corresponding entry like: dev\_node\_map[current\_node\_to\_read]

Cheers  
Chris
