This post discusses 2 problems:
1. Last value not held on certain devices
2. DAQmxGetWriteTotalSampPerChanGenerated() does not return correct number.
Truth is if #1 gets fixed I can live with #2.
For devices that do not support DAQmxSetAOIdleOutputBehavior() I expected that the device would hold the last value written.
This seems to be true for the PCI-6014 and USB-6211.
But with other devices like PCI-6251 and PCI-6711 I need to write 3 of the same value in order for the value to be held.
For example, with a sample rate of 1kHZ I write 1000 samples to channel 0 of the device.
If I write 999 samples of 0V followed by 1 sample of 2V I want to see 2V held on the scope.
With PCI-6014 and USB-6211 this is indeed the case. It just works as expected.
With PCI-6251 and PCI-6711 the 2V value is held ONLY when I write 3 2V samples.
So with PCI-6251 and PCI-6711 I write 997 samples of 0V followed by 3 samples of 2V and my scope will show the idle state of the device holding at 2V.
With just 1 or 2 2V samples the value is not held.
Note that I always write just 1000 samples, never more than that.
I really need to find out how to get the idle state of these devices to hold the last value without having to repeat it. This is my major problem.
A secondary problem is that I don't think that DAQmxGetWriteTotalSampPerChanGenerated() is working.
I suspected that not all the data from the buffer may be transmitted to the device, so I added a call to DAQmxGetWriteTotalSampPerChanGenerated() but this call never shows me that I really wrote all 1000 samples. For the USB-6211 it shows that I wrote 1002 samples! In all other cases it shows I wrote only 825 or so samples.
Again, I write 1000 samples in both cases. Never more, never less.
I am attaching a very pared down program that shows this issue.
It is based on C:\Program Files\National Instruments\NI-DAQ\Examples\DAQmx ANSI C\Analog Out\Generate Voltage\Volt Update
so you can compile it with those project files. I am using Visual Studio 2005.
Run it by specifying the device ID and number of 2V samples to write at the end.
Example:
VC_VoltUpdate.exe Dev4 1
will write 999 samples of 0V then 1 2V sample to Dev4.
If you have AO0 of Dev4 hooked up to your scope you'll see the 0V followed by the jump to 2V only for the USB-6211 and PCI-6014.
If you're using a PCI-6251, PCI-6711 and I suspect some others you will need to specify
VC_VoltUpdate.exe Dev2 3
to see the 2V held.
Here is output that shows that DAQmxGetWriteTotalSampPerChanGenerated() never shows us 1000 samples, even though that's all we wrote.
R:\NI Example Code\G425667_OutOfDataMode_Hold_Samples\Debug>VC_VoltUpdate.exe Dev4 1
Writing stream of 0V samples followed by 1 2V sample(s) to channel Dev4/ao0 (device PCI-6014) at sample rate 1000.00
Samples to write = 1000, Writing 64 samples
Samples to write = 936, Writing 64 samples
Samples to write = 872, Writing 64 samples
Samples to write = 808, Writing 64 samples
Samples to write = 744, Writing 64 samples
Samples to write = 680, Writing 64 samples
Samples to write = 616, Writing 64 samples
Samples to write = 552, Writing 64 samples
Samples to write = 488, Writing 64 samples
Samples to write = 424, Writing 64 samples
Samples to write = 360, Writing 64 samples
Samples to write = 296, Writing 64 samples
Samples to write = 232, Writing 64 samples
Samples to write = 168, Writing 64 samples
Samples to write = 104, Writing 64 samples
Samples to write = 40, Writing 40 samples
SamplesGenerated: 826
SamplesGenerated: 826
SamplesGenerated: 826
End of program, press Enter key to quit
R:\NI Example Code\G425667_OutOfDataMode_Hold_Samples\Debug>VC_VoltUpdate.exe Dev5 1
Writing stream of 0V samples followed by 1 2V sample(s) to channel Dev5/ao0 (device USB-6211) at sample rate 1000.00
Samples to write = 1000, Writing 64 samples
Samples to write = 936, Writing 64 samples
Samples to write = 872, Writing 64 samples
Samples to write = 808, Writing 64 samples
Samples to write = 744, Writing 64 samples
Samples to write = 680, Writing 64 samples
Samples to write = 616, Writing 64 samples
Samples to write = 552, Writing 64 samples
Samples to write = 488, Writing 64 samples
Samples to write = 424, Writing 64 samples
Samples to write = 360, Writing 64 samples
Samples to write = 296, Writing 64 samples
Samples to write = 232, Writing 64 samples
Samples to write = 168, Writing 64 samples
Samples to write = 104, Writing 64 samples
Samples to write = 40, Writing 40 samples
SamplesGenerated: 347
SamplesGenerated: 632
SamplesGenerated: 916
SamplesGenerated: 1002
SamplesGenerated: 1002
End of program, press Enter key to quit
R:\NI Example Code\G425667_OutOfDataMode_Hold_Samples\Debug>VC_VoltUpdate.exe Dev2 1
Writing stream of 0V samples followed by 1 2V sample(s) to channel Dev2/ao0 (device PCI-6251) at sample rate 1000.00
Samples to write = 1000, Writing 64 samples
Samples to write = 936, Writing 64 samples
Samples to write = 872, Writing 64 samples
Samples to write = 808, Writing 64 samples
Samples to write = 744, Writing 64 samples
Samples to write = 680, Writing 64 samples
Samples to write = 616, Writing 64 samples
Samples to write = 552, Writing 64 samples
Samples to write = 488, Writing 64 samples
Samples to write = 424, Writing 64 samples
Samples to write = 360, Writing 64 samples
Samples to write = 296, Writing 64 samples
Samples to write = 232, Writing 64 samples
Samples to write = 168, Writing 64 samples
Samples to write = 104, Writing 64 samples
Samples to write = 40, Writing 40 samples
SamplesGenerated: 825
SamplesGenerated: 825
SamplesGenerated: 825
End of program, press Enter key to quit
Sherryl Radbil
Data Acquisition Engineer
The MathWorks