Euresys::EGrabber Coaxlink Programmer's Guide
runScript("config.js");
enableEvent<CicData>();
reallocBuffers(3);
start();
}
private:
virtual void onCicEvent(const CicData &data) {
std::cout << "timestamp: " << std::dec << data.timestamp << " us, "
<< "numid: 0x" << std::hex << data.numid
<< " (" << getEventDescription(data.numid) << ")"
<< std::endl;
}
};
int main() {
try {
EGenTL gentl;
MyGrabber grabber(gentl);
while (true) { // 3
}
} catch (const std::exception &e) {
std::cout << "error: " << e.what() << std::endl;
}
}
There are very few differences between this program and the CallbackOnDemand version:
1. MyGrabber is derived from EGrabber<CallbackSingleThread> instead of
EGrabber<CallbackOnDemand>.
2. Consequently, MyGrabber's constructor initializes its base class by calling
EGrabber<CallbackSingleThread>'s constructor.
3. EGrabber creates a callback thread in which it calls processEvent, so we don't have to. Here, we simply enter
an infinite loop.
As you can see, moving from CallbackOnDemand to CallbackSingleThread is very simple. If
instead you want the CallbackMultiThread variant, simply change the base class of MyGrabber to
EGrabber<CallbackMultiThread> (and call the appropriate constructor).
New buffer callbacks
This program shows how to access information related to new buffer events. It uses CallbackMultiThread, but
it could use another callback method just as well.
#include <iostream>
#include <EGrabber.h>
using namespace Euresys;
class MyGrabber : public EGrabber<CallbackMultiThread> {
public:
MyGrabber(EGenTL &gentl) : EGrabber<CallbackMultiThread>(gentl) {
runScript("config.js");
enableEvent<NewBufferData>();
reallocBuffers(3);
start();
}
private:
virtual void onNewBufferEvent(const NewBufferData &data) {
ScopedBuffer buf(*this, data); // 1
uint64_t ts = buf.getInfo<uint64_t>(GenTL::BUFFER_INFO_TIMESTAMP); // 2
std::cout << "event timestamp: " << data.timestamp << " us, " // 3
<< "buffer timestamp: " << ts << " us" << std::endl;
} // 4
};
23