From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

High-Speed Digitizers

cancel
Showing results for 
Search instead for 
Did you mean: 

Stop function "niScope_Read" instantaneously in C++

Solved!
Go to solution

I‘'m using function "niScope_Read" in C++ for my 5112 card:

 

in a "for" loop:

      niScope_Read(vi,"0,1",60,MaxSample,wfmPtr,&wfmInfo);

 

So the card can output any waveform that matches my trigger setting. But, I do not konw how to stop the "Read" status instantaneously. I cannot always wait for 60 seconds to stop the loop.

 

Does anybody know how to stop reading when 5112 is waiting for trigger? I tried "ni_Abort" but it does not work.

 

Thanks in advance.

0 Kudos
Message 1 of 3
(5,060 Views)
Solution
Accepted by topic author wsxxdzlj

niScope_read and niScope_fetch are blocking functions.  They put a lock on the niScope session, so other functions like abort won't work.  It will either wait until the trigger occurs, or the timeout expires.  These are the only two options.  In order to be able to exit your loop instantaniously, you will need more control logic.  For example, this is what I would reccomend:

 

 

.....
niScope configure functions
bool  terminate_loop=false;
...
for{
   niScope_InitiateAcquisition
   while( niScope_AcquisitionStatus != "NISCOPE_VAL_ACQ_COMPLETE" && !terminate_loop);
   If(termnate_loop)
       break;
   else
       niScope_fetch
}

 

 

The main idea behind the code above is to not call niScope_fetch until you know a trigger has been recieved and the acquisition is complete.  If an acquisition is complete, then the read and fetch functions will not timeout, but return immediately, because the data is already available.  

 

Also, note that I'm using fetch instead of read.  Read is a single function that initiates the acquisition, waits for it to complete, and retrieves the data.  With my code exerpt, we do all these tasks separately ourselves, so we can be more in control of "wait for it to complete".  

 

I hope this helps!

Nathan

Systems Engineer
SISU
0 Kudos
Message 2 of 3
(5,044 Views)
Solution
Accepted by topic author wsxxdzlj

Thanks, Nathan. It helps a lot.

0 Kudos
Message 3 of 3
(4,828 Views)