GigE Vision Events

@parsd,

the Linea GigE from TDalsa is able to send GigE Vision Events.

Event1

As soon one of the event parameters i activated there is also an “EventInfo” which outputs the last timestamp value where the specific event occured.

Event2

If I remember correctly we have two ways to register on this event with :cvb:. Either we register directly on the GigE Vision event or we register a callback which e.g. listen on changes of the node “Cust::EventLine5PulseStartTimestamp”.

Do we have some code snippets which explain how to achieve both ways and which would be the best choice?

regards,
Theo

Hi @Theo,

I will reply in two steps. In this post I describe the prefered way (GenApi). Use this if the camera supports it.

As per your example I assume you got the Cust::EventLine5PulseStartTimestamp node via the camera’s device node map (NMHGetNodeMap and then NMGetNode). First we need the call back function that is called every time the node changes (in this case when a new GEV Event arrived):

void __stdcall Line5PulseStart(NODE Node, void *pPrivate);

Then you can call this code to register this callback :

  NODE hLine5PulseStartTimestamp = /* get Cust::EventLine5PulseStartTimestamp node handle as described */;

  NODECALLBACK unregisterToken = NULL;
  cvbres_t result = NRegisterUpdate(hLine5PulseStartTimestamp, &Line5PulseStart, NULL, unregisterToken);
  if(result < 0)
    ; // error handling

Instead of the NULL in the register function, you can also give it a pointer to something that brings you back to your context (e.g. a class’ this pointer).

Important Note

The hLine5PulseStartTimestamp NODE object stores the Line5PulseStart callback function. If you release the hLine5PulseStartTimestamp via ReleaseObject, the also the callback is gone. Thus keep the hLine5PulseStartTimestamp object alive as long as you need the callback.

Why is this preferred?

The GenICam Standard Features Naming Convention only standardizes the names, not the numeric values. Thus the vendors are free to change the numeric event IDs as they see fit. This normaly only happens between vendors or device series, but we have also see them change due to firmware updates. Names are safer because of the standard.

2 Likes

The second way, if the camera’s GenApi node map does not support it, is the :cvb: INotify interface:

First we create this harness:

  IMG hCamera = NULL;
  if(const char *cvbDir = getenv("CVB"))
  {
    char genicamPath[_MAX_PATH] = { 0 };
    snprintf(genicamPath, _MAX_PATH, "%sDrivers\\GenICam.vin", cvbDir);
    hCamera = OpenDriverPort(genicamPath, 0);
  }

  // here we will put the code from below

  ReleaseObject(hCamera);

Using OpenDriverPort from here:

This code simply opens the first available configured camera and frees it.

If I call this function in the section marked by the comment above:

void ListINotifyEvents(IMG hCamera)
{
  assert(CanNotify(hCamera));

  size_t numEvents = 0;
  NOGetNumSupported(hCamera, numEvents);
  for(size_t eventIndex = 0; eventIndex < numEvents; ++eventIndex)
  {
    char descriptionBuffer[128] = { 0 }; // this should suffice
    size_t desciptionBufferSize = sizeof(descriptionBuffer);
    CVNotifyEvent_t eventId = -1;
    NOGetDescription(hCamera, eventIndex, descriptionBuffer, desciptionBufferSize, eventId);
    printf("- %s: %i\n", descriptionBuffer, eventId);
  }
}

I get the following output (:cvb: 2017/13.00.00x):

  • Disconnect: 2
  • Reconnect: 3
  • LinkLoss: 1000
  • CCPLoss: 1001
  • DevEvent: 1003
  • Test: 10000

What we want here is the DevEvent (device event) which then is the GEV event in our case. We also need a callback function:

void __stdcall CameraEvent(CVNotifyEvent_t eventID, void *pBuffer, size_t bufferSize, CVNotifyDatatype_t bufferDataType, void *pPrivate);

which we then register:

  intptr_t cameraEventToken = -1;
  cvbres_t result = NORegister(hCamera, 1003, &CameraEvent, NULL, cameraEventToken);
  if(result < 0)
    ; // error handling

The data delivered via CameraEvent is transport technology dependent. In case of a GigE Vision event data, the event ID can be found in the second WORD:

void __stdcall CameraEvent(CVNotifyEvent_t eventID, void *pBuffer, size_t bufferSize, CVNotifyDatatype_t bufferDataType, void *pPrivate)
{
  assert(bufferSize >= 4);
  const uint16_t *pWords = reinterpret_cast<const uint16_t *>(pBuffer);
  uint16_t eventId = pWords[1];

  // ...
}

So, this is how you can get the event id via INotify. I find this a) more complicated and b) it is transport technology dependent. Thus if you have a U3V device, the pBuffer interpretation is different.

1 Like

Hi @parsd,

thanks a lot. This should be very helpful for some applications. :footprints:

regards,
Theo