LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Use "Armed state" in DAQmx counter input

Hello,
 
I'm working on Real-Time application using DAQmx functions to access my PCI-6036E, however I have a timing problem with the DAQmx functions for the counter inputs:
 
My application (as is, in Real-Time) must run very fast (1KHz sampling rate approx.), at this speed should be able to read/write data and send it to my HOST machine through TCP/IP. The counter I need must read frequency or period (DAQmxCreateCIPeriodChan or DAQmxCreateCIFreqChan) in the signal. Since the sampling rate is fast, the TIMEOUT to read the sample should be very short (I'm trying 0.0001 seconds), but if my source signal is 100Hz, for example, the DAQmxREADCounter function times out and I get a TIMEOUT error because no period is detected, and the same happens if the source signal is not connected, obviously, for the same reason.
 
So, what would be useful is a function like GPCTR_Watch, where you ask if the counter is armed (there is no time constraint for this function), and if it is armed then you read the value and if not, you can assign a zero or the previous value. However, I could not find a function equivalent for DAQmx, I saw a solution proposed for LabView where if you get a timeout error, you ignore it and assign the value you want, but in my case I can NOT wait until this timeout finishes.
 
I would appreciate any help/
Thanks,
David.
 
0 Kudos
Message 1 of 2
(2,830 Views)
Hello David,

Your profile shows this is your first post, so welcome to the Forums! What seems to be happening is you are trying to read some number of samples and timing out before those samples are available.  The timeout setting for the read function is meant to show that for some reason samples you were expecting did not show up.  It appears, however, that you are trying to use it to control timing of your program. 

What I would recommend doing is to use the DAQmxGetReadAvailSampPerChan function to determine how many (or if any) samples are available to be read. This would then allow you to assign a value if there are no samples or call the read function if there are.  This would eliminate the need to set the timeout so small because you know that the samples are available.

Another option you have is to use a longer timeout time and set your samples to read to 1.  What this would do is wait at the read function until a sample is available and then read it.  If this does not happen in your timeout period, you would get that error again, so you would have to set the timeout to a value greater than the maximum length of time you expect between period measurements (i.e. 1 period of your slowest signal).

If you set your samples to read to -1, this means "read whatever is there".  That would allow you to read 0 samples if none are available without throwing an error.  The timeout is not really relevant in this case since it is not waiting for a specific number of samples. 

I don't think you want to ignore the error because if something happens to your signal,  it almost is always nice to know that something happened (timeout error) than just ignore it.  That is the true purpose of the timeout setting.  More often than not, the default value we use of 10 sec is adequate for most applications.

I hope this clears things up, please post back if you have any questions!
Neal M.
Applications Engineering       National Instruments        www.ni.com/support
0 Kudos
Message 2 of 2
(2,814 Views)