On demand callbacks
This program displays basic information about CIC events generated by a grabber:
#include <iostream>
#include <EGrabber.h>
using namespace Euresys; // 1
class MyGrabber : public EGrabber<CallbackOnDemand> { // 2
public:
MyGrabber(EGenTL &gentl) : EGrabber<CallbackOnDemand>(gentl) { // 3
runScript("config.js"); // 4
enableEvent<CicData>(); // 5
reallocBuffers(3);
start();
}
private:
virtual void onCicEvent(const CicData &data) {
std::cout << "timestamp: " << std::dec << data.timestamp << " us, " // 6
<< "numid: 0x" << std::hex << data.numid // 6
<< " (" << getEventDescription(data.numid) << ")"
<< std::endl;
}
};
int main() {
try {
EGenTL gentl;
MyGrabber grabber(gentl);
while (true) {
grabber.processEvent<CicData>(1000); // 7
}
} catch (const std::exception &e) {
std::cout << "error: " << e.what() << std::endl;
}
}
- This using directive allows writing
Xyz
instead ofEuresys::Xyz
. This helps keep lines relatively short. - Define a new class
MyGrabber
which is derived fromEGrabber<CallbackOnDemand>
. MyGrabber
's constructor initializes its base class by callingEGrabber<CallbackOnDemand>
's constructor.- Run a
config.js
script which should:- properly configure the camera and frame grabber;
- enable notifications for CIC events.
- Enable
onCicEvent
callbacks. - The
onCicEvent
callback function receives aconst CicData &
. This structure is defined ininclude/EGrabberTypes.h
. It contains a few pieces of information about the event that occurred. Here, we display thetimestamp
andnumid
of each event. Thenumid
indicates which CIC event occurred. - Call
processEvent<CicData>(1000)
:- the grabber starts waiting for a CIC event;
- if an event occurs within
1000
ms, the grabber executes theonCicEvent
callback function; - otherwise, a timeout exception will be thrown.
Example of program output:
timestamp: 1502091779 us, numid: 0x8041 (Start of camera trigger)
timestamp: 1502091784 us, numid: 0x8048 (Received acknowledgement for previous CXP trigger message)
timestamp: 1502091879 us, numid: 0x8043 (Start of light strobe)
timestamp: 1502092879 us, numid: 0x8044 (End of light strobe)
timestamp: 1502097279 us, numid: 0x8042 (End of camera trigger)
timestamp: 1502097284 us, numid: 0x8048 (Received acknowledgement for previous CXP trigger message)
timestamp: 1502191783 us, numid: 0x8041 (Start of camera trigger)
timestamp: 1502191783 us, numid: 0x8045 (CIC is ready for next camera cycle)
timestamp: 1502191788 us, numid: 0x8048 (Received acknowledgement for previous CXP trigger message)
timestamp: 1502191883 us, numid: 0x8043 (Start of light strobe)
timestamp: 1502192883 us, numid: 0x8044 (End of light strobe)
timestamp: 1502197283 us, numid: 0x8042 (End of camera trigger)
timestamp: 1502197288 us, numid: 0x8048 (Received acknowledgement for previous CXP trigger message)
timestamp: 1502291788 us, numid: 0x8041 (Start of camera trigger)
timestamp: 1502291788 us, numid: 0x8045 (CIC is ready for next camera cycle)
...