- 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.
};
auto eventCookie = device->NotifyObservable(static_cast<int>(DeviceState::DeviceDisconnected))->RegisterEvent(onDisconnected);
device->NotifyObservable(static_cast<int>(DeviceState::DeviceDisconnected))->UnregisterEvent(eventCookie);
static std::vector< DiscoveryInformation > Discover()
static std::shared_ptr< T > Open(const String &provider, AcquisitionStack acquisitionStack=AcquisitionStack::PreferVin)
{
{
EventHandler<NotifyEventArgs> onDisconnected = (
object sender,
NotifyEventArgs e) =>
{
};
}
}
static Device Open(DiscoveryInformation info, AcquisitionStack acquisitionStack=AcquisitionStack.PreferVin)
static DiscoveryInformationList Discover()
const int DeviceDisconnected
Note: Error handling has been omitted from the above example.
- Devices are discovered and opened as usual.
- A callback function is defined. This can be a function, local method, lambda, function object or similar.
- The callback is registered as an event handler for the
Cvb::DeviceState::DeviceDisconnected
event. All available events can be found at Cvb::DeviceState
.
- 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).