Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

How does one write NI-DAQ data from buffer to stdout in ANSI C?

Solved!
Go to solution

I am totally new to NIDAQ. I have searched this forum and not found a solution to my problem - everyone works with LabView, not in ANSI C. I use NIDAQmx with ANSI C on WinXP. It is easy to capture data using the ANSI C API provided with the NIDAQ. Data is automatically stored in a buffer, provided by the API. Question: How does one get the information out of the buffer? For instance, if one wanted to sample 1000 samples (let's, say, an analog input channel as well as a digital input channel). At the end of the data collection I wish to print the data that have been logged, e.g. to the stdout device. Just a tiny pointer in the right direction would be immensely helpful! None of the example C files (supplied with the NIDAQ) do file output of the data that have been logged. One needs to know the format in which data are stored in the buffer, as well as the structure of the buffer in order to access the elements of the buffer.

0 Kudos
Message 1 of 11
(3,949 Views)

Hello,

 

The data you want to print should be in the data[] variable.  Also, are you trying to write to a file or just display data on the screen?

Michael B.
Applications Engineer
0 Kudos
Message 2 of 11
(3,928 Views)

Thank you so much for your reply.  I need to explain more fully. Your explanation is 100% accurate if one uses the DAQmxReadAnalogF64 function or similar. However, when reading both digital and analog inputs, it looks like a different method is used to obtain data from digital as well as analog inputs. I am looking at the demo program 'ContAI-ReadDigChan.c' that is included with the NI 6008. There the setup is a bit different. The reason why I am looking at this demo program is because I need to monitor 4 differential analog inputs as well as one of the digital ports, all simultaneously measured at a rate of 2 samples per sec. 

 

I attach some extracts from the code of that demo. If I understand the code correctly, the data declarations do not create global variables that are visible in the main thread of the program because they are located in a callback function that (I suspect) runs in a different thread. Is this correct at all? Therefore it is a problem to get hold of the information in the main function.

 

A different problem that is preventing me to actually execute the above demo program, is an execution error that takes place when running the unmodified code that I copied from the CD supplied with the 6008. My debugging tool indicates that the error is in the second call to DAQmxCfgSampClkTiming.  I have taken the liberty of indicating the error message in the attached code snippet. I have not found a solution to this execution error.

 

I would really appreciate some pointers here as I am pretty clueless about how to solve the execution error and to test the demo software.

Kind regards , WillemF

 

 

0 Kudos
Message 3 of 11
(3,918 Views)

That is a common error and a search should have given you the answer. The digital I/O on the 6008 is software timed o you cannot use that function.

0 Kudos
Message 4 of 11
(3,915 Views)

Dennis, thank you for your comment. The function that I refer to does, as far as I am aware, exactly that - set up a software timer (I do not use hardware timing). The NI demo software that does only digital input works perfect using that mechanism. The problem arises when both analog and digital input are performed. This necessitates to separate tasks, since analog and digital inputs can apparently not coexist within the same task. I have doen quite a bit of searching for a solution on the fora and have, to date, not been successful. Kind regards, wf

0 Kudos
Message 5 of 11
(3,906 Views)

Maybe you will believe the help file if you think that functions sets up software timing.

 

DAQmxCfgSampClkTiming

int32 DAQmxCfgSampClkTiming (TaskHandle taskHandle, const char source[], float64 rate, int32 activeEdge, int32 sampleMode, uInt64 sampsPerChanToAcquire);

Purpose

Sets the source of the Sample Clock, the rate of the Sample Clock, and the number of samples to acquire or generate.

0 Kudos
Message 6 of 11
(3,899 Views)

Dennis, Thank you for your bold (!) reply. I then assume that the hardware timer of the 8255 is used. Thank you very much for indicating this, even though it took two messages. Would you be prepared at all to peruse the attached two demo code files from NI, where they invoke DAQmxCfgSamClkTiming for a digital channel?

1) Is this a coding error?

2) If so, what is the appropriate type of action to take if one needs to synchronise this software clock (triggering digital input) with the sampling of analog input channels on the 6008?

 

I have checked quite extensively on this forum as well as wider on the Internet, have not found any clear solution. If you can point me vaguely in the right direction, I would appreciate it immensely. Kind regards, willemF

Download All
0 Kudos
Message 7 of 11
(3,895 Views)

Of course the example code is correct when you have better hardware.  With software timed (On Demand) I/O of your inexpensive DAQ device, there is no hardware sync. All you can do is a digital DAQmx Write with timing left to the whims of the OS. That means doing an analog read, analyzing the returned data for your trigger condition, and then outputting the digital based on that.

0 Kudos
Message 8 of 11
(3,892 Views)

Michael, I think two issues have emerged in the discussion so far. 1) As far as synchronisation between digital and analog channels are concerned, the discussion in this thread by Dennis Knutsen indicates that we are dealing with undocumented limitations of the NI6008. Could this be correct? If so, is it perhaps possible at all to supply documentation that explains these limitations in excruciating detail, especially as far ar the achievement of synchronisation is concerned? This is more or less what would be required in order to do sensible programming with the device. Does this sound reasonable at all?

2) For the callback system implemented in DAQmx, do they communicate between separate threads? It seems logical I have no idea what the API does behind the scenes.

Kind regards, willemf

0 Kudos
Message 9 of 11
(3,882 Views)

Hi Willemf,

 

Page 23 of the 6008 manual mentions that it is static digital i/o, and all digital writes and reads are software timed. This means that there is not a digital sample clock in the device, which is why you were getting errors when you were trying to configure it. Especially with lower cost hardware, there are many DAQmx functions that don't apply or are incompatible with the device. You can't for example use the analog input functions on a device that only has digital i/o. It would be impractical to list every function and feature that a device doesn't have.

 

If you are trying to synchronize the analog read with the digital read, I would suggest setting sampling rate of the analog inputs as high as is reasonable, then build a while loop. You will want to read one sample from each analog channel, then read one sample from each digital channel. You would then want to wait for the next multiple of your desired time interval, and repeat.

 

I hope this helps,

 

Regards,

Luke B.

0 Kudos
Message 10 of 11
(3,852 Views)