01-09-2006 01:07 PM
uInt32(*function)(SESSION_ID sid, IMG_ERR
err, uInt32 signal, void* userdata)
How do I go about specifying
the value to use for userdata? I would have thought in
imgSessionAcquire() I can pass in an additional argument, specifically
the value of the (void *)data, but I checked the function prototype in
<niimaq.h> and I don't see any additional parameters there.
For more background, I'm
using C++ and object-oriented programming, so I need to pass the "this"
pointer in the user data portion in order to access the instance.
Thanks.
01-10-2006 02:36 PM
Hi Harold,
First, the bad news... The callback on imgSessionAcquire() does not let you pass user data to the callback.
Now the good news.. You can get the same behavior with imgSessionWaitSignalAsync(). Here's some example code.
//--------------------------------------
#include "niimaq.h"
class Foo {
public:
uInt32 DoSomething(SESSION_ID id, IMG_ERR err, uInt32 signal);
};
uInt32 __cdecl Callback(SESSION_ID id, IMG_ERR err, uInt32 signal, void* data) {
Foo* myObj = reinterpret_cast<Foo*>(data);
return myObj->DoSomething(id, err, signal);
}
main() {
Foo* myObj = new Foo;
SESSION_ID id;
//... Setup grab, do other stuff, then
imgSessionAcquire(id, true, NULL);
//If you want to get a callback after each image
imgSessionWaitSignalAsync(id, IMG_BUF_COMPLETE, IMG_SIGNAL_STATE_RISING, Callback, static_cast<void*>(myObj));
//If you want to get a callback when the acquisition is complete
imgSessionWaitSignalAsync(id, IMG_AQ_DONE, IMG_SIGNAL_STATE_HIGH, Callback, static_cast<void*>(myObj));
//... Eventually clean up, etc.
return 0;
}
//----------------
Good luck
01-10-2006 04:29 PM