LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I stop a DQAmx read VI?

Solved!
Go to solution

In the answer to the question "wait for and trigger on first incoming digital edge " it was said that I can enter -1 to the DAQmx read in order to read the channel for indefinite time. (JPG added)

if I do that the VI is "stuck" until I get a signal on the channel.

my question is how do I stop this run if I get a stop signal (the stop signal is in software)?

 

thank you

0 Kudos
Message 1 of 9
(3,354 Views)

If you pass -1 as "samples to read" to the DAQmx Read, you will get all samples currently in the buffer. So you will not wait for a certain amount of samples.

I think your problem lies elsewhere:

Either you entered -1 also to the samples to read at the timing VI (which probably can create issues, but not sure about this) or you never gave the starttrigger. If the starttrigger does not occur within the timeout (10s in your screenshot), you will a) have to wait for this and b) will receive an error after the timeout occurred.

 

hope this helps,

Norbert 

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 2 of 9
(3,351 Views)

My problem is this

I have to wait for a frequency (period test) on a counter channel (on pcie-6353 card)

The channel has no other input until I receive this frequency.

The frequency can arrive at any time between 0s-12 min

I need to listen to this line until I get that frequency OR until I get a stop signal from the software.

 

As I understand if I need to listen for a long period of time I have to insert -1 (or the time I need to wait in seconds) as "samples to read".

But the problem is I can't stop the VI until the time is over (which means if I insert -1 I can never stop the VI)

 

Do you know if such thing is possible?

0 Kudos
Message 3 of 9
(3,332 Views)

Hm, reading your postings show me one thing: you are not used to the NI DAQ terminology.

Therefore i will try to repeat what i understand from your words:

You use an 6353 device to measure a period from a digital signal.  The signal is a single pulse which can occur any time up to 12 minutes after you started the acquisition.

Is that correct?

 

Connecting -1 to the "samples to read" will never wait in the DAQmx Read. You are most probably talking about the timeout, where -1 defines an infinite waiting time. While DAQmx Read is waiting on samples, you cannot terminate the application. If an timeout occurs (e.g you set the timeout to 10s), the task has to be restartet. This can take up to several ms. During this time, the input is "blind regarding your signal" ...

 

The only possible way to solve this gracefully is either always wait on the pulse/timeout (12 mins) or to switch to FPGA hardware, which can do this by polling....

 

Norbert 

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 4 of 9
(3,326 Views)

Sorry for my bad terminology but you understand me correct.

the problem is I use a 6353 card and can't change to an FPGA card and also I can't wait 12 min every test (some tests should be over in few seconds.

as I understand from you I can't do that with the 6353 card?

 

if I use software trigger will it work correct?

for example listen to the same line with a digital input and start the counter read (with a case) only after I receive the digital pulse?

 

is there a better way than that to read the period with the counter?

 

thank you

0 Kudos
Message 5 of 9
(3,301 Views)

If you don't want to wait for a timeout, you will have to poll. Polling means that you acquire continuously data and transfer it into your application repeatedly. In your software, you can choose in every cycle of your polling to

a) terminate acquisition because user wants to terminate

b) terminate acquisition because the situation you are looking for has occurred

b) proceed acquisition since the situation did not yet occur

 

So you will have some kind of softwaretrigger in your application, true.

Counters are dedicated devices for measurements of digital signals. There is no better hardware by default (also you can implement algorithms on FPGAs which enable the FPGA device to act like an counter even if it only supports digital IO).

 

hope this helps,
Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 6 of 9
(3,297 Views)
Solution
Accepted by topic author jackedi

Hey guys,

 

So you are on the right track, and Norbert you are correct that an FPGA is the ideal method for performing the task, but one thing you can do is add a timeout to the DAQmx Read VI and then ignore the timeout from the error cluster each iteration of the loop.  This will allow you to read the "Stop" button from your front panel, and stop the while loop if pressed, while also looping back around and waiting for the trigger again if the stop button has not been pressed.  The timeout error is -200284 so what you would want to do is unbundle the "Code" value from the error cluster and check to see if it is equal to -200284.  You can then use a case structure to reset the error cluster if it is equal, or pass the error cluster through if it isn't (this allows you to catch any other errors that may have occured).  Take a look at the attached screenshot to see how to implement this method.

 

Also, one thing I noticed is that you are not clearing the task at the end of your code, or handling your errors.  Be sure to place a DAQmx clear task and a Simple Error Handler VI at the end of your code, outside the loop.  If you do not clear the task you are leaving the reference open and you will receive a resources reserved error the next time you try to run your code.  Please let me know if you have any questions.

0 Kudos
Message 7 of 9
(3,278 Views)

I think you can take advantage of the Event structure in LabVIEW.  You can register a DAQmx Event into the event structure and then perform your read after the event structure is triggered by the DAQmx event.

 

 

DAQmx Event Structure Example.png
Message Edited by rpursley8 on 12-16-2009 01:18 PM
Message Edited by rpursley8 on 12-16-2009 01:19 PM
Randall Pursley
Message 8 of 9
(3,264 Views)

Thank you all for your help, it helped me a lot for my NI cards and labview learning.

0 Kudos
Message 9 of 9
(3,223 Views)