# GigE Vision Events

**URL:** <https://forum.commonvisionblox.com/t/gige-vision-events/190>\
**Category:** C-style API\
**Tags:** acquisition, genicam, gigevision, c\
**Created:** [August 4, 2017, 8:24am UTC](https://forum.commonvisionblox.com/t/gige-vision-events/190 "2017-08-04T08:24:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Theo](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/theo/32/482_2.png) [@Theo](https://forum.commonvisionblox.com/u/Theo)\
**Post date:** [August 4, 2017, 8:24am UTC](https://forum.commonvisionblox.com/t/gige-vision-events/190/1 "2017-08-04T08:24:52Z")

</div>

@parsd,

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

![Event1](https://canada1.discourse-cdn.com/flex027/uploads/commonvisionblox/original/1X/c24a5e926efe1d9a7a0514906d547e9e662803f2.PNG)

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](https://canada1.discourse-cdn.com/flex027/uploads/commonvisionblox/original/1X/b8f317e678a432ad4bee25c972ede27f9fcb10ba.PNG)

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

---

<div class="post-metadata">

**Author:** ![parsd](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/parsd/32/7_2.png) [@parsd](https://forum.commonvisionblox.com/u/parsd)\
**Post date:** [August 7, 2017, 8:13am UTC](https://forum.commonvisionblox.com/t/gige-vision-events/190/2 "2017-08-07T08:13:41Z")

</div>

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):

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

```

Then you can call this code to register this callback :

```auto
  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.

---

<div class="post-metadata">

**Author:** ![parsd](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/parsd/32/7_2.png) [@parsd](https://forum.commonvisionblox.com/u/parsd)\
**Post date:** [August 7, 2017, 9:17am UTC](https://forum.commonvisionblox.com/t/gige-vision-events/190/3 "2017-08-07T09:17:13Z")

</div>

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

First we create this harness:

```auto
  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:

[https://forum.commonvisionblox.com/t/old-image-broken-after-setting-new-camport/66/5?u=parsd](https://forum.commonvisionblox.com/t/old-image-broken-after-setting-new-camport/66/5)

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:

```auto
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:

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

```

which we then register:

```auto
  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`:

```auto
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.

---

<div class="post-metadata">

**Author:** ![Theo](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/theo/32/482_2.png) [@Theo](https://forum.commonvisionblox.com/u/Theo)\
**Post date:** [August 7, 2017, 11:50am UTC](https://forum.commonvisionblox.com/t/gige-vision-events/190/4 "2017-08-07T11:50:52Z")

</div>

Hi @parsd,

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

regards,  
Theo
