Cvb++ Nodemap event callback challenges

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:

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?

Hi @cpj_ge

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


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

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.

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 .

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.

Hi @cpj_ge

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

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

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

1 Like

Hi cpi_ge,

thats great to hear, thank you for the feedback!

Cheers
Chris