alliedvision / VimbaPython

Old Allied Vision Vimba Python API. The successor to this API is VmbPy
BSD 2-Clause "Simplified" License
93 stars 40 forks source link

I can't find a way to connect (physically) and detect Cameras after vimba instance was created #6

Closed ttamttam closed 3 years ago

ttamttam commented 4 years ago

Hello,

if I start my program with one GigE camera alive and connected, everythings goes OK: I can detect disconnections and reconnections.

In the case where the camera is not connected when the vimba object is created, subsequent calls to vimba.get_camera_by_id(cameraid) or vimba.get_all_cameras() do not return any Camera.

Is this expected? Is there a way around this?

Best regards

NiklasKroeger-AlliedVision commented 4 years ago

Hi,

sorry for the long wait for a response!

I can reproduce the issue. While the Vimba.get_instance() context manager is opened, newly connected GigE cameras are not added to the camera list correctly. It also appears, that disconnected cameras are not removed from the list. Thank you for bringing this to our attention.

The best way to deal with this right now would be to only have the Vimba.get_instance() singleton open if absolutely necessary. Opening it is not super expensive in processing time and should guarantee, that the list of available cameras is up to date. I will however investigate why connect and disconnect events are not handled as expected and update here if I have further information.

ttamttam commented 4 years ago

OK. I'll try to find a reasonable workaround for my first deliveries.

Thanks.

NiklasKroeger-AlliedVision commented 3 years ago

I do not know if this issue is still relevant for you but I stumbled over a similar issue recently and noticed, that in VimbaPython by default GigE Cameras are only actively searched for once during startup (relevant code line). After this initial discovery during startup the camera list is kept up to date by handling CameraEvent.Detected and CameraEvent.Missing events and updating the camera list accordingly. Unfortunately, for GigE cameras this does not seem to be the best way to go about it.

In order to detect newly plugged in cameras, a broadcast of a certain GigE-Vision command is necessary. Vimba does support performing these broadcasts periodically to reliably discover new and unplugged GigE cameras, but this behaviour is turned off by default. I assume this is done to not unnecessarily spew out broadcast packets unless the user really does need them.

In order to activate the updating of plugged in/out GigE cameras, the feature GeVDiscoveryAllAuto has to be executed. You can find documentation on that feature (and others used in the example below) in the Vimba Manual that is provided with your installation in section 10.2. The Manual is located in your Vimba installation directory under "Documentation/Vimba Manual.pdf".

Code example to enable automatic detection of GigE cameras with VimbaPython:

import vimba

def activate_gige_discovery():
    with vimba.Vimba.get_instance() as vmb:
        if vmb.GeVTLIsPresent.get():
            vmb.GeVDiscoveryAllDuration.set(250)
            vmb.GeVDiscoveryAllAuto.run()
ttamttam commented 3 years ago

I thank you for those information. I’m quoting them into the TODO file of my project repository, and will take them into account if/when I’ll have to re-open it because my customer would request for modifications.

Best regards

NiklasKroeger-AlliedVision commented 3 years ago

I will go ahead and close this issue as in my experiments I am able to now discover the plug-in and unplug events of GigE cameras correctly and i would consider the original question answered. Feel free to reopen the issue if it does not work for you!