Simple python script to poll or update nodes

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…

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()

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:


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

1 Like