Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use CNiVisaJobId? Have a example code?

Hi...
How can I use a Asynchronous I/O operation?
I found a CNiVisaJobId Object use a Asynchronous I/O operation but can't find a example or how to ues...
I need your assistance...
and sorry my english is so poor... ^^...
0 Kudos
Message 1 of 3
(3,472 Views)
Tae Sun,

Unfortunately there isn't an example for asynchronous VISA in Measurement Studio C++. However, it isn't too difficult.

For example, to do an asynchronous read or write you first install an event handler for the VisaEventIoComplete event using CNiVisaSession::InstallEventHandler. Next, enable the VisaEventIoComplete event by calling CNiVisaSession::EventEnable. Then, create a CNiVisaJobId object, and pass it to one of the CNiVisaSession::Read or CNiVisaSession::Write functions that take a CNiVisaJobId& parameter. Your event handler will be called when the operation is complete. You can find the CNiVisaJobId of the operation that was completed in your event handler by casting the CNiVisaEvent passed t
o your event handler to a CNiVisaIoCompletionEvent and calling GetJobId on it. It all will look something like this:

CNiVisaJobId myJobId;
ViStatus __cdecl MyEventHandler (CNiVisaEvent& event)
{
if (event.GetType() == VisaEventIoComplete)
{
if ((CNiVisaIoCompletionEvent)event.GetJobId() == myJobId)
...your processing here...
}
}

void DoStuff ()
{
CNiVisaSession mySession("ASRL1::INSTR");
mySession.InstallEventHandler(VisaEventIoComplete, MyEventHandler);
mySession.EnableEvent(VisaEventIoComplete, VisaHandler);
mySession.Write(...your data here..., myJobId);
}

Alternatively, if you don't want to use an event handler and just want to start an asynchronous operation and wait for it to complete later on, you can use the WaitOnEvent method of CNiVisaSession.

Hope that helps.

TonyH
Measurement Studio
Message 2 of 3
(3,472 Views)
Thanks for your help...
Have a good time... ^^...
0 Kudos
Message 3 of 3
(3,472 Views)