Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Continuous Analog Input Measurement

Hello
How Set Continuous Analog Input Measurement for NI PCI 6259 by using NI-DAQmx C Functions and buffered acquisition, which mean that data is moved from the DAQ device's onboard FIFO memory to a PC buffer using DMA ?
0 Kudos
Message 1 of 12
(4,600 Views)
Hi,

Your best option would be to look at some of the example code that is installed with NI-DAQ. You can find them on your computer under:

C:\Program Files\National Instruments\NI-DAQ\Examples\DAQmx ANSI C\Analog In\Measure Voltage

This folder contains the analog input example programs. You will find more example programs in that directory.

You can also find out more about the DAQmx C functions by looking in the NI-DAQmx C Function Reference help located under your Start Menu >> Programs >> National Instruments >> NI-DAQ

In general, when dealing with NI-DAQmx you do not have to worry about setting buffer sizes, FIFOs, and using DMAs. This is all taken care of automatically by the DAQmx driver. All you have to do is: configure the task, start the task, perform the read, stop the task.

Please let me know if you have any further questions.

-Sal
0 Kudos
Message 2 of 12
(4,577 Views)
Hello
Yes everything what you are wrote is true.
But the problem is that when you set the task connect with Timing Analog Input Buffor by using function
[int32 DAQmxCfgSampClkTiming (TaskHandle taskHandle, const char source[], float64 rate, int32 activeEdge, int32 sampleMode, uInt64 sampsPerChanToAcquire);],with the flag [sampleMode=DAQmx_Val_ContSamps //Acquire or generate samples until you stop the task.] the Analog Input Bufer will be fill only once and then the task is stoped automatically. Whay the Analog Input Buffer will not be fill continuous without involve CPU?
And there are no good examples for continuous acquisition signal from Analog Input Channels by using "C" function from NI-DAQmx library. Whay?
Best Regards.
0 Kudos
Message 3 of 12
(4,576 Views)
Hi,

You are correct in saying that by default, DAQmx will stop a task before data in its buffer get's over-written by new data. The idea is that you should be calling read on the task and reading data from that buffer as data is being written in, such that the buffer never actually fills up. You can change this behavior, and allow the data in the buffer to be overwritten (DAQmxSetReadOverWrite function should do this). However in most cases I have seen, the desired behavior is not to overwrite the buffer, as most commonly all data points are to be read.

If you are looking for an example of a continuous acquisition, you may want to see if the following example got installed on your machine:
Cont Acq-Int Clk-Anlg Start
(C:\Program Files\National Instruments\NI-DAQ\Examples\DAQmx ANSI C\Analog In\Measure Voltage\Cont Acq-Int Clk-Anlg Start on my machine).

I hope this helps,
Dan
0 Kudos
Message 4 of 12
(4,564 Views)
Hello
DAQmxSetReadOverWrite ??? This is something new for me.
Whay this function is not described in NI-DAQmx C Reference Help ???
Where this function is described ???
Best Reagards.
0 Kudos
Message 5 of 12
(4,559 Views)
Hello again
I saw this examples;
First: There are no use DAQmxSetReadOverWrite functions in this examples?
Second: In this example to measure continual Analog Input channel you involv CPU when you call DAQmxReadAnalogF64 function each time. See below
////////////////////////////////////////////////////////////////////////////////////////////////
.
.
while( !_kbhit() ) {
DAQmxErrChk (Read_ContAcqIntClkAnlgStart(taskHandle,1000,data,1000,&read));
if( read>0 ) {
totalRead += read;
printf("Acquired %d samples. Total %d\r",read,totalRead);
}
}
.
.
////////////////////////////////////////////////////////////////////////////////////////////////
I would like to fill Analog Input Buffer and set it in PC memeory and then fill it again? Without involv CPU.
After 128 times I would like to stop measurement. It is possible something like this ???
Then you can do something other in you computer during measurement.
Best Regards.
0 Kudos
Message 6 of 12
(4,556 Views)
Hi,

I went to the search tab in DAQmx C Reference help, and searched for overwite. This brouht up the topic of Get/Set/Reset Read_Overwrite, where the function is described as follows:

Data Type: int32
Description: Specifies whether to overwrite samples in the buffer that you have not yet read.



Valid valuesDAQmx_Val_OverwriteUnreadSamps 10252 When an acquisition encounters unread data in the buffer, the acquisition continues and overwrites the unread samples with new ones. You can read these samples by setting RelativeTo to DAQmx_Val_MostRecentSamp and setting Offset to the appropriate number of samples.
DAQmx_Val_DoNotOverwriteUnreadSamps 10159 The acquisition stops when it encounters a sample in the buffer that you have not read.





You can get/set/reset this property using:

DAQmxGetReadOverWrite

DAQmxSetReadOverWrite

DAQmxResetReadOverWrite


So basically if you don't care about the data that is presently in the buffer, you can allow that to be overwritten with new data. However if you do care about the data in the buffer, then you will want to keep the current behavior of not allowing overwrites. If this is the case, then you will start the task, then repeatedly call read on the task to move data out of the buffer until you are ready to stop the task.

I hope this helps,
Dan
0 Kudos
Message 7 of 12
(4,554 Views)
Hi,

From your description, it sounds to me like you do not want to allow overwrites, which is the current behavior. As such it seems like your code should look like this

// Conifigure task

// Start task

while(number of reads < 128)
{
DAQmxReadAnalogF64(.....) // choose appropriate read flavor
// handle data acauired from read - this will involve the CPU
}

// Stop task

With this setup, the device will write to PCI memory without CPU intervention, however to read data out of that buffer the CPU will be involved. I don't believe that there is any way around that.

Hope this helps,
Dan
0 Kudos
Message 8 of 12
(4,549 Views)
Hello
I just think that mayby it is posible to fill buffer 128 times without "while" loop
Array X=128:
------------------|0
------------------|1
------------------|2
.
.
.
.
------------------|127
0................127
FOR FUNCTION
DAQmxReadAnalogF64 (TaskHandle taskHandle, int32 numSampsPerChan, float64 timeout, bool32 fillMode, float64 readArray[], uInt32 arraySizeInSamps, int32 *sampsPerChanRead, bool32 *reserved);
WHERE:
numSampsPerChan=X
sampsPerChanRead=X
fillMode=DAQmx_Val_GroupByScanNumber
arraySizeInSamps==X*X !!!
AND CLOCK SETINGS:
DAQmxCfgSampClkTiming (TaskHandle taskHandle, const char source[], float64 rate, int32 activeEdge, int32 sampleMode, uInt64 sampsPerChanToAcquire);
WHERE:
sampleMode=DAQmx_Val_ContSamps !!!
sampsPerChanToAcquire=X;
But I don't know it is possible ?
Best Regards.
0 Kudos
Message 9 of 12
(4,546 Views)
It is certainly possible to read all of the data that you want in a single call to read. However, as you mentioned, then you will need to read into a buffer of size X*X. The numSampsPerChan parameter of DAQmxReadAnalogF64 will tell DAQmxReadAnalogF64 how many samples to transfer from the aquisition buffer to the buffer passed into read. In your case, if you pass X in for numSampsPerChan, then the read function should transfer that many points to the array you passed in, reguardless of the size of this array, and the mode of the acquisition. If you wish to read all of the data with a single read call, then you will need to specify numSampsPerChan as X*X, and pass read an array large enough for this amount of data. The end result would be the same as if you had called read X times, specifing numSampsPerChan as X, passing pointer into an array of size X*X which was incremented by X every time read was called. I hope that makes sense!

If you already know how big X is, it seems to me like it would make more sense to program a finite acquisition of size X*X, and perform a single read to retrieve the data. Is there a particular reason that this would not be an acceptable approach for your application? Because it seems to me that you are essentially going to be simulating this behavior by trying to read all data at once anyway.

Hope this helps,
Dan
0 Kudos
Message 10 of 12
(4,541 Views)