NI Home
Cart Cart | Help
Hello Events Academic NI Developer Zone Support Solutions Products & Services Contact NI MyNI
You are here: 
NI Home > NI Developer Zone > NI Discussion Forums


Reply
Member
DonM2
Posts: 1
0 Kudos

How to stop a continuous task only at the end of a buffer

I am outputting digital outputs continuously using DAQmxCfgSampClkTiming and the DAQmx_Val_ContSamps parameter. This works, it cycles repeatedly through a single buffer I supply. But when I call DAQmxStopTask, the task is stopped immediately, in the middle of the buffer. I would like to have the system only stop when it is at the end of the buffer. Is there any way to accomplish this?

 

Alternatively, is there any way to know exactly where it was in the buffer when it stopped?

 

I am using a NI6353 board and the NI-DAQmx C API.

 

Thanks for your help. If there is a better forum for posting this question, please let me know. I could not find a software forum for the NI_DAQmx C API.

 

Don

 

Active Participant
alcava.cr
Posts: 234
0 Kudos

Re: How to stop a continuous task only at the end of a buffer

There is. I would start with DAQmx_Read_AvailSampPerChan &DAQmx_Read_CurrReadPos. More information at the NI-DAQmx C Reference Help.

Alejandro | Applications Engineer | National Instruments
Member
DonM3
Posts: 4
0 Kudos

Re: How to stop a continuous task only at the end of a buffer

I am writing (outputting) digital values, not reading. So I think you mean DAQmxGetWriteCurrWritePos().

 

That looked good, but doesn't seem to work. If I call DAQmxGetWriteCurrWritePos after calling DAQmxStopTask, it always returns a value equal to the buffer size. If I call it before I call DAQmxStopTask, I get various values, but they are all larger than the buffer size. I would expect the value to range from 0 to the buffer size.

 

Is there an examle that does this, or can you provide any more guidance?

 

Thanks,

 

Active Participant
alcava.cr
Posts: 234
0 Kudos

Re: How to stop a continuous task only at the end of a buffer

The same options are available for writing operations, take a look at the picture. I could not find the examples but this options should give you a starting point.

Capture.PNG

Alejandro | Applications Engineer | National Instruments
Active Participant
Kevin_Price
Posts: 1,906

Re: How to stop a continuous task only at the end of a buffer

I'm not aware of a way to force a continuous task to end at a specific point (such as the end) in the output buffer at a precise hardware-timed level.  Here's the kind of thing I'd try to do as a workaround:

 

1. When you're ready to stop after the completion of this particular cycle through the buffer, make 2 consecutive write calls which each write 1/2 buffer of data.  The data should simply be the last desired digital state duplicated for 1/2 buffer size.

 

2.  If you only originally wrote your pattern once to the buffer before starting to regenerate, the new write should circle back to the beginning of the buffer to start overwriting the old pattern.  However, DAQmx should manage the timing & negotiations for you so that this new data won't overwrite the old data until it's "safe." 

 

3. By the time you return from writing both 1/2 buffers, the task will necessarily be outputting that final digital state.   You should be able to stop the task at any time.

 

4.  Even if you can't react and stop right away, the task should happily regenerate the same final digital state forever until you stop the task. 

 

-Kevin P

 

-- looking to hire? PM me...
By using this web site, you accept the Terms of Use for this web site. Please read these Terms of Use carefully before using any part of this site. Please go here for information on ni.com's copyright infringement policy.
My Profile | Privacy | Legal | Contact NI © 2011 National Instruments Corporation. All rights reserved.    |    E-Mail this Page E-Mail this Page