Common Vision Blox 15.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Friends Modules Pages
Acquisition and Streaming - Event Callbacks

Attention
Event Callbacks are not supported in the Python API.

The INotify interface enables notification of application for asynchronous driver events. It allows for the registration of user defined callbacks for asynchronous driver events. All currently supported events can be found at Cvb::DeviceState.

When using it the following rules apply:

  • The thread context from which the callback is issued might vary between events and is not necessarily the main application process. It is driver (implementation) dependent whether callbacks are fired in parallel from multiple threads or sequentially from within the same thread context. Even though it is likely that a single callback registered on a single EventID on a single device is not called from multiple threads in parallel, it still valid. Therefore it is the caller's responsibility to ensure that the execution context of the registered notification is correct.
  • Multiple callbacks can be registered to a single event. They will be executed in a random order.
  • The callbacks are called from the thread context issuing the event. The execution time spent in the callback will possibly (depending on the event) affect image acquisition timing or driver behavior in general. It is recommended to return from a notification as quickly as possible.
  • In order to avoid deadlocks it is not recommended to call driver functions from within a callback.

using namespace Cvb;
auto devices = DeviceFactory::Discover(DiscoverFlags::IgnoreVins);
auto device = DeviceFactory::Open<GenICamDevice>(devices[0].AccessToken(), AcquisitionStack::GenTL); // (1)
auto onDisconnected = [](NotifyArgs args){ // (2)
// Handle device disconnected event
};
auto eventCookie = device->NotifyObservable(static_cast<int>(DeviceState::DeviceDisconnected))->RegisterEvent(onDisconnected); // (3)
// ...
device->NotifyObservable(static_cast<int>(DeviceState::DeviceDisconnected))->UnregisterEvent(eventCookie); // (4)
static std::vector< DiscoveryInformation > Discover()
static std::shared_ptr< T > Open(const String &provider, AcquisitionStack acquisitionStack=AcquisitionStack::PreferVin)

using (var devices = DeviceFactory.Discover(DiscoverFlags.IgnoreVins))
{
using (var device = (GenICamDevice)DeviceFactory.Open(devices[0], AcquisitionStack.GenTL)) // (1)
{
EventHandler<NotifyEventArgs> onDisconnected = (object sender, NotifyEventArgs e) => // (2)
{
// Handle device disconnected event
};
device.Notify[NotifyDictionary.DeviceDisconnected].Event += onDisconnected; // (3)
// ...
device.Notify[NotifyDictionary.DeviceDisconnected].Event -= onDisconnected; // (4)
}
}
static Device Open(DiscoveryInformation info, AcquisitionStack acquisitionStack=AcquisitionStack.PreferVin)
static DiscoveryInformationList Discover()

Note: Error handling has been omitted from the above example.

  1. Devices are discovered and opened as usual.
  2. A callback function is defined. This can be a function, local method, lambda, function object or similar.
  3. The callback is registered as an event handler for the Cvb::DeviceState::DeviceDisconnected event. All available events can be found at Cvb::DeviceState.
  4. The callback is deregistered. In C++, this occurs throught the use of a unique Cvb::EventCookie that is received at registration. In C#, this occurs through the normal event interface (see C# Programming Guide).