# Cvb++ Nodemap event callback challenges

**URL:** <https://forum.commonvisionblox.com/t/cvb-nodemap-event-callback-challenges/2195>\
**Category:** C++ API\
**Created:** [July 15, 2024, 9:34am UTC](https://forum.commonvisionblox.com/t/cvb-nodemap-event-callback-challenges/2195 "2024-07-15T09:34:08Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![cpj\_ge](https://avatars.discourse-cdn.com/v4/letter/c/e19b73/32.png) [@cpj\_ge](https://forum.commonvisionblox.com/u/cpj_ge)\
**Post date:** [July 15, 2024, 9:34am UTC](https://forum.commonvisionblox.com/t/cvb-nodemap-event-callback-challenges/2195/1 "2024-07-15T09:34:08Z")

</div>

Hi  
I am using Cvb++ (14.1) and am in the process of registering callback functions for all possible events.  
So far I have succesfully retrieved all the relevant `IntegerNodePtr`’s from the device nodemap (for example Std::EventAcquisitionStart).  
Then I try to attach the callback by using the `RegisterEventUpdated` function on each node:

```c++
for (auto const &[nodename, node] : nodesForCallback)
{
   node->RegisterEventUpdated([&](Cvb::Node &)
     { spdlog::info("Got event: [{}, Value={}]", nodename, node->Value()); });
}

```

It does not seem to work… Any ideas?

---

<div class="post-metadata">

**Author:** ![Chris](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/chris/32/1154_2.png) [@Chris](https://forum.commonvisionblox.com/u/Chris)\
**Post date:** [July 16, 2024, 12:45pm UTC](https://forum.commonvisionblox.com/t/cvb-nodemap-event-callback-challenges/2195/2 "2024-07-16T12:45:31Z")

</div>

Hi @cpj_ge

I have some code snipped that should be from cvb 12 or 13:

```cpp

struct GevEventData 
{ 
  GevEventData() 
    : reserved_(0) 
    , id_(0) 
    , timestamp_(0) 
  { 
  } 
  uint16_t reserved_; 
  uint16_t id_; 
  uint64_t timestamp_; 
}; 

void INotify1003_Triggered(Cvb::Driver::NotifyArgs args) 
{ 
  GevEventData* data = reinterpret_cast<GevEventData*>(args.Data());   
  auto id = _byteswap_ushort(data->id_); // little to big endian (intrin.h) 
  std::cout << id << std::endl; 
}  

int main(int argc, char* argv[]) 
{ 
  auto path = Cvb::InstallPath(); 
  path += CVB_LIT("Drivers/GenICam.vin"); 
  path = Cvb::ExpandPath(path);   
  auto device = Cvb::DeviceFactory::Open(path);   
  auto nodeMap = device->NodeMap("Device");   
  auto eventSelectorNode = nodeMap->Node<Cvb::EnumerationNode>("EventSelector"); 
  auto notificationNode = nodeMap->Node<Cvb::EnumerationNode>("EventNotification"); 
  eventSelectorNode->SetValue("ExposureStart"); 
  notificationNode->SetValue("On"); 

  device->NotifyObservable(1003)->RegisterEvent(INotify1003_Triggered);  

  // Do stuff.. 

} 

```

Maybe you could give this a go (I cant test this bevore tomorrow) but dont waste too much time if this also does not work.

@s-woe @Andreas maybe you could give us some input here as well

---

<div class="post-metadata">

**Author:** ![Andreas](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/andreas/32/75_2.png) [@Andreas](https://forum.commonvisionblox.com/u/Andreas)\
**Post date:** [July 16, 2024, 1:21pm UTC](https://forum.commonvisionblox.com/t/cvb-nodemap-event-callback-challenges/2195/3 "2024-07-16T13:21:01Z")

</div>

Hi @Chris, @cpj_ge

please be aware that there are two differnt kinds of events to consider for any GenTL based technology like GEV or U3V. Device events that delivered from the device (on the wire) and handed to the GenApi to appear on nodes of the node map. And events that are created by the GenTL implmentation itself and do not involve data sent over the wire (like disconnected event) these events cannot be delivered the same way as the device is already gone. NotifyObservable should only be used for the second event type.

> [@cpj\_ge](#):
>
> It does not seem to work… Any ideas?

What exactly does not work? The registration or do you never see it triggered? If the later, be aware that a camera usually does not send event data for every node change. Events may need to be enabled first. See the post from @Chris .

---

<div class="post-metadata">

**Author:** ![cpj\_ge](https://avatars.discourse-cdn.com/v4/letter/c/e19b73/32.png) [@cpj\_ge](https://forum.commonvisionblox.com/u/cpj_ge)\
**Post date:** [July 17, 2024, 8:13am UTC](https://forum.commonvisionblox.com/t/cvb-nodemap-event-callback-challenges/2195/4 "2024-07-17T08:13:20Z")

</div>

Hi @Andreas,  
Thanks for your reply.

It did not work as I never saw the event triggered. I found out that it was due to the firmware of the camera being too old. When I updated the camera to the newest firmware - it worked.

What kind of informaiton is retrieveable from the nodemap events? So far, I have only been able to extract the EventID, but any other information, i.e. timestamp would be very nice to have.

---

<div class="post-metadata">

**Author:** ![Chris](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/chris/32/1154_2.png) [@Chris](https://forum.commonvisionblox.com/u/Chris)\
**Post date:** [July 17, 2024, 9:22am UTC](https://forum.commonvisionblox.com/t/cvb-nodemap-event-callback-challenges/2195/5 "2024-07-17T09:22:30Z")

</div>

Hi @cpj_ge

```cpp
auto devices = DeviceFactory::Discover(DiscoverFlags::IgnoreVins);
auto device = DeviceFactory::Open<GenICamDevice>(devices[0].AccessToken(), AcquisitionStack::GenTL);
auto stream = device->Stream<CompositeStream>(); // default: index = 0 (1)
stream->Start(); // (2)

for (int i = 0; i < 10; ++i)
{
CompositePtr composite;
WaitStatus status;
NodeMapEnumerator nodeMaps;
std::tie(composite, status, nodeMaps) = stream->Wait(); // C++14 (3)
auto [composite, status, nodeMaps] = stream->Wait(); // C++17 (3)
}
stream->Abort(); // (4)

```

Information like FrameID and Timestamp can be easily accessed from the nodemap that is returned from your Wait() call.  
Maybe you want to have a look if this is already all you need.

Cheers  
Chris

---

<div class="post-metadata">

**Author:** ![Andreas](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/andreas/32/75_2.png) [@Andreas](https://forum.commonvisionblox.com/u/Andreas)\
**Post date:** [July 17, 2024, 1:52pm UTC](https://forum.commonvisionblox.com/t/cvb-nodemap-event-callback-challenges/2195/6 "2024-07-17T13:52:19Z")

</div>

Hi @Chris , hi @cpj_ge,

for completeness let me add some things. Event data for GEV and U3V contains a dedicated device timestamp. However, GenTL does not offer an interface for that so only the raw event buffer would be available. See the `GevEventData` @Chris posted. Please also note, that this layout is only valid for GEV 1.x. If you have a more recent GEV device it is most likly GEV 2.x

---

<div class="post-metadata">

**Author:** ![cpj\_ge](https://avatars.discourse-cdn.com/v4/letter/c/e19b73/32.png) [@cpj\_ge](https://forum.commonvisionblox.com/u/cpj_ge)\
**Post date:** [July 25, 2024, 10:14am UTC](https://forum.commonvisionblox.com/t/cvb-nodemap-event-callback-challenges/2195/7 "2024-07-25T10:14:44Z")

</div>

Thanks for you feedback. I have managed to retrieve timestamp information from the `stream->Wait()` nodemap.

---

<div class="post-metadata">

**Author:** ![Chris](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/chris/32/1154_2.png) [@Chris](https://forum.commonvisionblox.com/u/Chris)\
**Post date:** [July 25, 2024, 12:20pm UTC](https://forum.commonvisionblox.com/t/cvb-nodemap-event-callback-challenges/2195/8 "2024-07-25T12:20:55Z")

</div>

Hi cpi\_ge,

thats great to hear, thank you for the feedback!

Cheers  
Chris
