Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime exception when receiving event (genapiMalformed message - wrong magic 0 (42 expected)) #481

Open
3 of 5 tasks
olofsjo1SICKAG opened this issue Nov 29, 2024 · 4 comments

Comments

@olofsjo1SICKAG
Copy link

Describe the Issue
I want to receive events from the camera, for example log events to be able to react on message from the camera.

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Sample Code
I can show a piece of code that demonstrates the reported phenomenon:

  • Yes
  • No

If yes, please provide a sample code:

h = Harvester()
h.add_file(cti_file)

h.update()
print(f"\n{h.device_info_list}\n")

with h.create(0, config=ParameterSet({ParameterKey.ENABLE_EVENT_MONITOR: True})) as ia:
    node_map = ia.remote_device.node_map

    ia.add_callback(event=ia.Events.ON_EVENT_DATA_UPDATED,
                    callback=event_callback)

    provoke_log_message(node_map)

// What to set to get a log message is camera dependent
def provoke_log_message(node_map):
    try:
        print("Provoking log message...")
        node_map.RegionSelector.value = "Scan3dExtraction1"
        node_map.ComponentSelector.value = "Range"
        node_map.PixelFormat.value = "Coord3D_C12p"
    except:
        pass
    print("Provoked log message")

If applicable, please paste the actual output (its whole traceback, etc) here:

[{'access_status': 1, 'display_name': 'SICK AG Ranger3-60 (SICKGigEVisionTL_DEV_0006770113a0)', 'id_': 'SICKGigEVisionTL_DEV_0006770113a0', 'model': 'Ranger3-60', 'parent': <genicam.gentl.Interface; proxy of <Swig Object of type 'std::shared_ptr< GenTLCpp::TLInterface 
> *' at 0x000001B49BA61020> >, 'serial_number': '16480056', 'thisown': True, 'tl_type': 'GEV', 'user_defined_name': 'ZPM03', 'vendor': 'SICK AG', 'version': '1.0'}, {'access_status': 1, 'display_name': 'SICK AG Ranger3-60 (SICKGigEVisionTL_DEV_0006770113a0)', 'id_': 'SICKGigEVisionTL_DEV_0006770113a0', 'model': 'Ranger3-60', 'parent': <genicam.gentl.Interface; proxy of <Swig Object of type 'std::shared_ptr< GenTLCpp::TLInterface > *' at 0x000001B4AC3CE9A0> >, 'serial_number': '16480056', 'thisown': True, 'tl_type': 'GEV', 'user_defined_name': 'ZPM03', 'vendor': 'SICK AG', 'version': '1.0'}]

Provoking log message...
Provoked log messagegoint to deliver an event: <genicam.gentl.EventManagerRemoteDevice; proxy of <Swig Object of type 'std::shared_ptr< GenTLCpp::EventManagerRemoteDevice > *' at 0x000001B4AC3CF660> >goint to deliver an event: <genicam.gentl.EventManagerRemoteDevice; proxy of <Swig Object of type 'std::shared_ptr< GenTLCpp::EventManagerRemoteDevice > *' at 0x000001B4AC3CF660> >
goint to deliver an event: <genicam.gentl.EventManagerRemoteDevice; proxy of <Swig Object of type 'std::shared_ptr< GenTLCpp::EventManagerRemoteDevice > *' at 0x000001B4AC3CF660> >

Exception in thread Thread-4:
Traceback (most recent call last):
  File "C:\Program Files\Python311\Lib\threading.py", line 1045, in _bootstrap_inner
Exception in thread
Thread-3:
Exception in thread Thread-5:
Traceback (most recent call last):
  File "C:\Program Files\Python311\Lib\threading.py", line 1045, in _bootstrap_inner
  File "C:\Program Files\Python311\Lib\threading.py", line 1045, in _bootstrap_inner
    self.run()
  File "C:\Projects\ruler3xxx\Production\Calibration\Scripts\.ruler_scripts\Lib\site-packages\harvesters\core.py", line 809, in run
        self.run()
    self._worker()
self.run()
  File "C:\Projects\ruler3xxx\Production\Calibration\Scripts\.ruler_scripts\Lib\site-packages\harvesters\core.py", line 2298, in _worker_module_event
  File "C:\Projects\ruler3xxx\Production\Calibration\Scripts\.ruler_scripts\Lib\site-packages\harvesters\core.py", line 809, in run
  File "C:\Projects\ruler3xxx\Production\Calibration\Scripts\.ruler_scripts\Lib\site-packages\harvesters\core.py", line 809, in run
    self._event_adapter.deliver_message(monitor.optional_data)
    self._worker()  File "C:\Projects\ruler3xxx\Production\Calibration\Scripts\.ruler_scripts\Lib\site-packages\genicam\genapi.py", line 3039, in deliver_message
    self._worker()

  File "C:\Projects\ruler3xxx\Production\Calibration\Scripts\.ruler_scripts\Lib\site-packages\harvesters\core.py", line 2298, in _worker_module_event
  File "C:\Projects\ruler3xxx\Production\Calibration\Scripts\.ruler_scripts\Lib\site-packages\harvesters\core.py", line 2298, in _worker_module_event
    return _genapi.EventAdapterGEV_deliver_message(self, msg)
           self._event_adapter.deliver_message(monitor.optional_data)self._event_adapter.deliver_message(monitor.optional_data)

   File "C:\Projects\ruler3xxx\Production\Calibration\Scripts\.ruler_scripts\Lib\site-packages\genicam\genapi.py", line 3039, in deliver_message
  File "C:\Projects\ruler3xxx\Production\Calibration\Scripts\.ruler_scripts\Lib\site-packages\genicam\genapi.py", line 3039, in deliver_message
     ^^^^^^^^    ^^return _genapi.EventAdapterGEV_deliver_message(self, msg)
^      ^ return _genapi.EventAdapterGEV_deliver_message(self, msg)
   ^  ^  ^  ^^^  ^  ^^^ ^^ ^^^^ ^^ ^^^  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^_genapi^^.^^RuntimeException^^: ^^^^^^^^Malformed message - wrong magic 0 (42 expected) : RuntimeException thrown (file 'EventAdapterGEV.cpp', line 69)^^
^^^^^^^^^^^^
^_genapi.^RuntimeException
: _genapiMalformed message - wrong magic 0 (42 expected) : RuntimeException thrown (file 'EventAdapterGEV.cpp', line 69).
RuntimeException: Malformed message - wrong magic 0 (42 expected) : RuntimeException thrown (file 'EventAdapterGEV.cpp', line 69)

Expected Behavior
I was expecting to get a callback and be able to react on that.

Configuration

  • OS: Windows 10 22H2
  • Python: 3.11.9
  • Harvester: 1.4.3
  • GenTL Producer: SICKGigEVisionTL
  • Camera: SICK Ranger3 V3DR3-60NE31111

Reproducibility

This phenomenon can be stably reproduced:

  • Yes
  • No.

If applicable, please provide your observation about the reproducibility.

Actions You Have Taken
I have added some debug prints inside Harvesters, printing the data used @ core.py", line 2298 gives:

<genicam.gentl.EventManagerRemoteDevice; proxy of <Swig Object of type 'std::shared_ptr< GenTLCpp::EventManagerRemoteDevice > *' at 0x000001E9F929B660> >

Printing the data @ genicam\genapi.py", line 3040, in deliver_message gives a buffer that can be read:

b'\x00\x00\x90\x00\xff\xff\x00\x00\x00\x00\x04\xe03\xe1]P\x00\x00\x00\x02The value 832 (0x340) is outside allowed range (12 to 256) for Height (Region2) at address 0xac7c.\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'

Here I got a clue, it looks like the header is missing, so I went to wireshark and inspected the message from the camera:
image

And it looks like the header contains the correct magic number, but somewhere on the way the header is stripped.

So is this a bug in Harvester that the header is stripped or am I doing something wrong?

@olofsjo1SICKAG olofsjo1SICKAG changed the title Runtime exception when receiving event Runtime exception when receiving event (genapiMalformed message - wrong magic 0 (42 expected)) Dec 2, 2024
@olofsjo1SICKAG
Copy link
Author

olofsjo1SICKAG commented Dec 3, 2024

By locally modifying my genapi.py and add some header information I can get the event handling to work. But this is not a long term solution and not a nice solution. To solve the problem one would need to understand where the header is stripped and avoid stripping it:

genapi.py#3038

    def deliver_message(self, msg):
        if msg[0] != b"\x42":
            msg = b"\x42\x01\x00\xc2\x02\x1c\x00\x01" + msg
        return _genapi.EventAdapterGEV_deliver_message(self, msg)

My guess is that this is somewhere in GenAPI/ Python wrapping when the data is read, that instead of reading all data including the header only the payload is read.

@stengoes
Copy link

stengoes commented Jan 9, 2025

I am experiencing the exact same problem:

Configuration:
OS: Linux 5.15.136-tegra
Python: 3.10.12
Harvester: 1.4.3
Genicam: 1.4.0
GenTL Producer: libmvGenTLProducer.so.3.3.0
Camera: MATRIX VISION mvBlueCOUGAR-X102fC-POEI

Traceback (most recent call last):
  File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "/usr/local/lib/python3.10/dist-packages/harvesters/core.py", line 809, in run
    self._worker()
  File "/usr/local/lib/python3.10/dist-packages/harvesters/core.py", line 2297, in _worker_module_event
    self._event_adapter.deliver_message(monitor.optional_data)
  File "/usr/local/lib/python3.10/dist-packages/genicam/genapi.py", line 3559, in deliver_message
    return _genapi.EventAdapterGEV_deliver_message(self, msg)
_genapi.RuntimeException: Malformed message - wrong magic 0 (42 expected) : RuntimeException thrown (file 'EventAdapterGEV.cpp', line 69)

And I can use more or less the same workaround/hack to fix it:

genapi.py#3558

    def deliver_message(self, msg):
        #print(msg)
        if msg[0] != b"\x42":
            msg = b"\x42\x10\x00\xc0" + msg

@stengoes
Copy link

I believe switching from GEV to Generic EventAdapter in the code below is a more generic solution, than prepending a hardcoded header.

core.py#1825

    @staticmethod
    def _get_event_adapter(*, tl_type: str, node_map: NodeMap):
        if tl_type == 'U3V':
            return EventAdapterU3V(node_map.pointer)
        elif tl_type == 'GEV':
            #return EventAdapterGEV(node_map.pointer) 
            return EventAdapterGeneric(node_map.pointer)
        else:
            return EventAdapterGeneric(node_map.pointer)

@olofsjo1SICKAG
Copy link
Author

Changing that does move past the event capturing point but the event data is not filled in correctly, at least not for me. So it results in an error later when trying to access the node_map of the remote device to access the event data (see log at bottom of the message).

I think the error is already in the call to update_event_data, at #2289, here the base class is used instead of implementing a RemoteDevice specific function that keeps the header as expected by EventAdapterGEV.deliver_message.

Exception in thread Exception in thread Exception in thread Thread-4Thread-5Thread-3:
Traceback (most recent call last):
  File "C:\Program Files\Python311\Lib\threading.py", line 1045, in _bootstrap_inner
:
Traceback (most recent call last):
  File "C:\Program Files\Python311\Lib\threading.py", line 1045, in _bootstrap_inner
:
Traceback (most recent call last):
  File "C:\Program Files\Python311\Lib\threading.py", line 1045, in _bootstrap_inner
            self.run()self.run()self.run()


  File "C:\Projects\ruler3xxx\Production\Calibration\Scripts\.ruler_scripts_new\Lib\site-packages\harvesters\core.py", line 809, in run
  File "C:\Projects\ruler3xxx\Production\Calibration\Scripts\.ruler_scripts_new\Lib\site-packages\harvesters\core.py", line 809, in run
  File "C:\Projects\ruler3xxx\Production\Calibration\Scripts\.ruler_scripts_new\Lib\site-packages\harvesters\core.py", line 809, in run
    self._worker()
      File "C:\Projects\ruler3xxx\Production\Calibration\Scripts\.ruler_scripts_new\Lib\site-packages\harvesters\core.py", line 2301, in _worker_module_event
self._worker()
self._worker()  File "C:\Projects\ruler3xxx\Production\Calibration\Scripts\.ruler_scripts_new\Lib\site-packages\harvesters\core.py", line 2301, in _worker_module_event

  File "C:\Projects\ruler3xxx\Production\Calibration\Scripts\.ruler_scripts_new\Lib\site-packages\harvesters\core.py", line 2301, in _worker_module_event
    self._emit_callbacks(self.Events.ON_EVENT_DATA_UPDATED)
  File "C:\Projects\ruler3xxx\Production\Calibration\Scripts\.ruler_scripts_new\Lib\site-packages\harvesters\core.py", line 1778, in _emit_callbacks
    self._emit_callbacks(self.Events.ON_EVENT_DATA_UPDATED)
  File "C:\Projects\ruler3xxx\Production\Calibration\Scripts\.ruler_scripts_new\Lib\site-packages\harvesters\core.py", line 1778, in _emit_callbacks
    self._emit_callbacks(self.Events.ON_EVENT_DATA_UPDATED)
  File "C:\Projects\ruler3xxx\Production\Calibration\Scripts\.ruler_scripts_new\Lib\site-packages\harvesters\core.py", line 1778, in _emit_callbacks
    self._emit_callback(callback)
  File "C:\Projects\ruler3xxx\Production\Calibration\Scripts\.ruler_scripts_new\Lib\site-packages\harvesters\core.py", line 1786, in _emit_callback
    self._emit_callback(callback)
  File "C:\Projects\ruler3xxx\Production\Calibration\Scripts\.ruler_scripts_new\Lib\site-packages\harvesters\core.py", line 1786, in _emit_callback
    self._emit_callback(callback)
  File "C:\Projects\ruler3xxx\Production\Calibration\Scripts\.ruler_scripts_new\Lib\site-packages\harvesters\core.py", line 1786, in _emit_callback
    callback.emit(context=self)
      File "c:\Projects\ruler3xxx\Production\Calibration\Scripts\ranger3_event_example.py", line 15, in emit
callback.emit(context=self)
  File "c:\Projects\ruler3xxx\Production\Calibration\Scripts\ranger3_event_example.py", line 15, in emit
    callback.emit(context=self)
      File "c:\Projects\ruler3xxx\Production\Calibration\Scripts\ranger3_event_example.py", line 15, in emit
print(f"{node_map.LogMessageLevel.value}:  {node_map.LogMessageText.value}")
     print(f"{node_map.LogMessageLevel.value}:  {node_map.LogMessageText.value}")
         print(f"{node_map.LogMessageLevel.value}:  {node_map.LogMessageText.value}")
                          ^  ^  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^  File "C:\Projects\ruler3xxx\Production\Calibration\Scripts\.ruler_scripts_new\Lib\site-packages\genicam\genapi.py", line 2187, in _get_value
^
^
  File "C:\Projects\ruler3xxx\Production\Calibration\Scripts\.ruler_scripts_new\Lib\site-packages\genicam\genapi.py", line 2187, in _get_value
  File "C:\Projects\ruler3xxx\Production\Calibration\Scripts\.ruler_scripts_new\Lib\site-packages\genicam\genapi.py", line 2187, in _get_value
        return self._primary_get_value()return self._primary_get_value()

       return self._primary_get_value()
                         ^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^
  File "C:\Projects\ruler3xxx\Production\Calibration\Scripts\.ruler_scripts_new\Lib\site-packages\genicam\genapi.py", line 2109, in _primary_get_value

  File "C:\Projects\ruler3xxx\Production\Calibration\Scripts\.ruler_scripts_new\Lib\site-packages\genicam\genapi.py", line 2109, in _primary_get_value
  File "C:\Projects\ruler3xxx\Production\Calibration\Scripts\.ruler_scripts_new\Lib\site-packages\genicam\genapi.py", line 2109, in _primary_get_value
    return _genapi.IInteger__primary_get_value(self, Verify, IgnoreCache)
          return _genapi.IInteger__primary_get_value(self, Verify, IgnoreCache)
return _genapi.IInteger__primary_get_value(self, Verify, IgnoreCache)
                        ^    ^^ ^^ ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^
_genapi^_genapi.^^AccessException.AccessException: ^^Node is not readable. : AccessException thrown in node 'LogMessageLevel' while calling 'LogMessageLevel.GetValue()' (file 'IntegerT.h', line 152): ^
Node is not readable. : AccessException thrown in node 'LogMessageLevel' while calling 'LogMessageLevel.GetValue()' (file 'IntegerT.h', line 152)^
^^^^
_genapi.AccessException: Node is not readable. : AccessException thrown in node 'LogMessageLevel' while calling 'LogMessageLevel.GetValue()' (file 'IntegerT.h', line 152)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants