Camera connection state changed event usage

Hello,

I am developing a program in Ubuntu by using Python.

I try to use register_connection_state_changed_event like below

     interface_flags = cvb.DiscoverFlags.UpToLevelInterface | cvb.DiscoverFlags.IgnoreGevFD
        all_interfaces = cvb.DeviceFactory.discover_from_root(interface_flags)
        broadcast_flags = cvb.DiscoverFlags.IgnoreVins | cvb.DiscoverFlags.IncludeInaccessible | cvb.DiscoverFlags.IgnoreGevFD

        all_devices = []

        for interface in all_interfaces:
            cvb.DiscoveryInformation.set_genapi_feature(interface, "TLInterface", "DisableSubnetMatch", "1")
            cvb.DiscoveryInformation.set_genapi_feature(interface, "TLInterface", "AllowBroadcastDiscoveryResponse", "1")

            found_devices = cvb.DeviceFactory.discover_from_level(interface.access_token, broadcast_flags)

            for dev in found_devices:
                all_devices.append(dev)

        ids = cvb.DeviceFactory.discover_from_root(cvb.DiscoverFlags.IgnoreVins)

        self.camera = cvb.DeviceFactory.open(all_devices[0].access_token)
        try:
            self.camera.register_connection_state_changed_event(self.call_back())
        except Exception as e:
            print(f"ex :{str(e)}")

By running this I get this exception : std::exception but I reach the call back code once.

Could you please help me with usage of register_connection_state_changed_event ?

PS : Tried the code below but I do not know which node name I should use to get the node and pass it to call back:

            self.camera.register_connection_state_changed_event(self.camera.node_maps["Device"].nodes.try_get_node("????"))

Thank you in advance

Hi @Fatemeh

Sorry for the late response due to the vacation season. The Following code block shows how to do connection monitoring in Python:

import os 
import time 
import cvb 
 
def connection_changed(dev: cvb.Device): 
    print("Connection state changed: ") 

device = cvb.DeviceFactory.open(os.path.join(cvb.install_path(), "drivers", "GenICam.vin"), port=0) 
device.register_connection_state_changed_event(connection_changed) 

while True: 
    time.sleep(1)

1 Like