alliedvision / VmbPy

Python API of the Vimba X SDK
BSD 2-Clause "Simplified" License
19 stars 7 forks source link

VmbCError(<VmbError.InternalFault: -1>) when entering a context manager with a Camera object #17

Closed SimonNCT closed 10 months ago

SimonNCT commented 10 months ago

Summary

The vmbpy package (Python Vimba X SDK) has an issue when entering a context with a Camera object. More specifically, a certain feature cannot be queried.

Configuration

Steps to reproduce

First confirm that you can actually see a proper image feed when using Vimba X Viewer. Then, copy their example file from here and execute it: https://github.com/alliedvision/VmbPy/blob/main/Examples/asynchronous_grab.py

It should fail at line 122: https://github.com/alliedvision/VmbPy/blob/main/Examples/asynchronous_grab.py#L122

It actually fails when entering the context manager. Change lines to:

    with VmbSystem.get_instance():
        cam: Camera = get_camera(cam_id)
        with cam:  # fails here!
            setup_camera(cam)

What is the current bug behavior?

An exception occurs when entering the context manager. The exception should look similar to this one:

C:\...\python.exe ...\asynchronous_grab.py 
///////////////////////////////////////
/// VmbPy Asynchronous Grab Example ///
///////////////////////////////////////

11-09-2023 12:10:40.786 [T] FeatureEnumRange GenICam::RuntimeException: Address not valid during read (address=-1342109900; length=4)
Traceback (most recent call last):
  File "C:\...\asynchronous_grab.py", line 144, in <module>
    main()
  File "C:\...\asynchronous_grab.py", line 125, in main
    with cam:
  File "...\venv_dev\Lib\site-packages\vmbpy\util\tracer.py", line 134, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "...\venv_dev\Lib\site-packages\vmbpy\camera.py", line 106, in __enter__
    self._open()
  File "...\venv_dev\Lib\site-packages\vmbpy\util\tracer.py", line 134, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "...\venv_dev\Lib\site-packages\vmbpy\util\context_decorator.py", line 44, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "...\venv_dev\Lib\site-packages\vmbpy\camera.py", line 517, in _open
    self._attach_feature_accessors()
  File "...\venv_dev\Lib\site-packages\vmbpy\util\tracer.py", line 134, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "...\venv_dev\Lib\site-packages\vmbpy\featurecontainer.py", line 64, in _attach_feature_accessors
    self._feats = discover_features(self._handle)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "...\venv_dev\Lib\site-packages\vmbpy\util\tracer.py", line 134, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "...\venv_dev\Lib\site-packages\vmbpy\feature.py", line 1211, in discover_features
    result.append(_build_feature(handle, info))
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "...\venv_dev\Lib\site-packages\vmbpy\feature.py", line 1176, in _build_feature
    feat = EnumFeature(handle, info)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "...\venv_dev\Lib\site-packages\vmbpy\util\tracer.py", line 134, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "...\venv_dev\Lib\site-packages\vmbpy\feature.py", line 489, in __init__
    self.__entries: EnumEntryTuple = _discover_enum_entries(self._handle, self._info.name)
                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "...\venv_dev\Lib\site-packages\vmbpy\util\tracer.py", line 134, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "...\venv_dev\Lib\site-packages\vmbpy\feature.py", line 595, in _discover_enum_entries
    call_vmb_c('VmbFeatureEnumRangeQuery', handle, feat_name, None, 0, byref(enums_count))
  File "...\venv_dev\Lib\site-packages\vmbpy\util\tracer.py", line 134, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "...\venv_dev\Lib\site-packages\vmbpy\c_binding\vmb_c.py", line 891, in call_vmb_c
    getattr(_lib_instance, func_name)(*args)
  File "...\venv_dev\Lib\site-packages\vmbpy\c_binding\vmb_c.py", line 815, in _eval_vmberror
    raise VmbCError(result)
vmbpy.c_binding.vmb_common.VmbCError: VmbCError(<VmbError.InternalFault: -1>)

(line numbers may vary slightly)

More specifically, in vmbpy/feature.py at line 594 (call_vmb_c('VmbFeatureEnumRangeQuery', handle, feat_name, None, 0, byref(enums_count))), you get an error when the feat_name=SequencerTriggerSource.

What is the expected correct behavior?

The context manager should be entered normally and acquiring frames should be possible.

Possible fixes

Not a fix but this issue can be mitigated by replacing line 594 of the above mentioned vmbpy/feature.py by:

if feat_name != b'SequencerTriggerSource':
    call_vmb_c('VmbFeatureEnumRangeQuery', handle, feat_name, None, 0, byref(enums_count))

In other words, do not call vmb_c if this specific feature name is queried. All other feature names succeed. Some have longer names (the failing one has 22 bytes, there exist some with 26 bytes though).

Can you please take a look into this? In Vimba X Viewer the mentioned property is displayed and is set to "Off".

NiklasKroeger-AlliedVision commented 10 months ago

This is a great bug report! Thank you very much for all the details and especially the already found workaround! I will forward all this information internally to see why this particular camera feature is causing issues.

In the meantime could you please check which firmware version your camera reports. Using the Vimba X Viewer, open the camera and navigate in the All feature tab to Camera -> DeviceControl -> Device Firmware Version. This might help us narrow down the issue.

You could also try upgrading your firmware version by downloading the newest released version from our website here: https://www.alliedvision.com/en/support/firmware-downloads/ You can then use the Vimba X Firmware Updater to install the downloaded firmware to the camera.

NiklasKroeger-AlliedVision commented 10 months ago

It appears that this issue should be fixed with a firmware update. As far as I can tell the issue is only present in firmware version 10. Our latest released firmware version as of writing this is version 12. Could you let us know if a firmware update fixes the issue for you?

SimonNCT commented 10 months ago

Thanks for the quick reply!

Previous device firmware version: 10.0.6C9062B1 New device firmware version: 12.0.00611A22 (note: had to try 4-5 times before the upgrade succeeded)

It works now!

Teresa-AlliedVision commented 10 months ago

If the update fails a lot of times, it might be necessary to check your hardware connection (cable, switch, port etc.), since the updates only fail when the connection has been disrupted or the camera looses power during the update. A good way to check the stability of the connection is to stream images in Vimba Viewer with a DeviceLinkThroughputLimit of 450 000 000 and see if the frame rate is stable (i.e. no lost or incomplete frames). If not, lower it until the stream is stable. If you need to reduce the bandwidth to 200 000 000 or below, switch out hardware components one by one.

SimonNCT commented 10 months ago

I thought I had the camera connected directly to my laptop via USB3 - cannot guarantee this though.

I set the DeviceLinkThroughputLimit to 450'000'000 and the received frame rate was pretty much identical to the AcquisitionFrameRate that was set to 69.7796 (+- 0.2 I guess). I could not find a lost frame counter though.

I updated the camera again with the newer firmware but was not able to reproduce this error.

Anyway, the main issue has been resolved/circumvented, thanks again!

Teresa-AlliedVision commented 10 months ago

The camera can do 130FPS, at 200MByte/s, after that it is limited by the sensor read out, which still wouldn't completely stress the connection, just a bit more. USB3 is the base requirement, but the bandwidth can still be limited due to what the USB controller can process and the quality/age of the cable and the connectors. One reason for a failed firmware update on a customer site was for example a USB connector that had been damaged by dirt getting into the connector and worsening one of the contacts. The failed firmware updates are just an indication of the transmission being suboptimal, so nothing critical, but just to keep in mind if you need to update it again. Worst case scenario, a failed firmware update can brick the camera, especially when the failure happens in the last 15% of the data ransfer or the device restart during the end of the update. So I would recommend not trying to reproduce the failed firmware updates.

SimonNCT commented 10 months ago

Thanks for the additional information, will keep that in mind!