Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

continuous 8 channel acquisition using win32 api and DAQ

Hi all,

I'm trying to acquire signals from multiple channels in my win32 API application using traditional DAQ and win32 callback procedure (the same I use to handle my GUI
events). The acquisition should use double buffering, write results to a file and stop only on a GUI event. Could
anybody give me any code that would be a starting point for that? (the important thing is that I'm not using CVI, etc., just DAQ). Even a short code showing how to implement acquisition's callback as a part of win32 callback procedure would be helpful.

Regards,
Simon
0 Kudos
Message 1 of 9
(5,097 Views)

Hi Simon-

What type of DAQ device are you using?  What you're trying to accomplish may be easier using NI-DAQmx. 

At any rate, a great double buffering example for Traditional NI-DAQ that installs with the driver is "DAQdoubleBuf.C" and can be found in ( C:\Program Files\National Instruments\NI-DAQ\Examples\VisualC\Ai ).  How exactly are you trying to implement the callback procedure (i.e. are you trying to only read from the backlog at specified acquisition intervals, etc)?

Thanks-

Tom W
National Instruments
0 Kudos
Message 2 of 9
(5,074 Views)

Tom,

Thank you for your reply. I'm trying to use NI 4472 for continuous multi-channel signals acquisition (double buffering) as a part of my masters dissertation. The callback function should only write data to file whenever the half-buffer is full.

I have found a "Using DAQ Event Messaging under Windows NT/95/3.1 - Application Note 086) document, which includes basic example of using windows callback function to handle acquisition process messages (attached to this post), but when I execute it, I get "Error code -10080 at SetupNIDAQEvents) message.

Could you please give me a hint what's wrong or where I should look for some code examples? Or maybe DAQmx code examples for Visual Studio C++ would suit my needs better?

Regards,
Simon

 

0 Kudos
Message 3 of 9
(5,053 Views)
 If you are using a DSA device, modify the iGain varialble to be in units of dB. Valid gain settings for DSA devices are -20, -10, 0, 10, 20, 30, 40, 50, and 60.
 
 
Most of the examples usually are set up for E series devices which have different  gain settings which would be invalid for a DSA board.
 
 
Buddy Curtis
Applications Engineer
Modular Intruments
Joji
Message 4 of 9
(4,988 Views)

Hi,

Thank you for your help. The gain setting was the answer! Now I'm trying to continuously acquire data from two analog channels using double buffering (as a starting point for 8 channel acquisition). My code seems to be working fine: the double buffer is being filled up with the right amount of data. But the acquired samples have strange values, eg.:

0   -190267 71522
2   -197805 -112550
4   -188074 -86492
6   -198216 -138331
8   -183551 -42830
10  -185196 26336
12  -187800 -88986
14  -190952 -32296
16  -182181 56830
18  -184373 12752
20  -183277 -74987
22  -185059 52672
24  -186292 40890
26  -179302 -28414
28  -179714 41167
30  -177658 -36177

/.../

There are some positive values at the second channel, which seems strange, as the values should be, as far as I know, in Db (so should be negative)?

Best regards and thank you for help,
Simon

Message Edited by electrobody on 01-23-2006 07:49 AM

0 Kudos
Message 5 of 9
(4,957 Views)
Please refer to the Traditional DAQ C Reference on the Scan_Start.  It specifically states that "For DSA devices only, buffer should be an array of i32. These devices return the data in a 32-bit format in which the data bits are in the most significant bits."
 
You are only using i16 (or 16-bit buffer), so you are getting strange data back.
 
P.S. You can find the C Reference from Start Menu >> All Programs>>National Instruments>>DAQ>>NI-DAQ
 
 
Joji
0 Kudos
Message 6 of 9
(4,939 Views)
Buddy,

Thank you for your reply. If you take a look at the code attached to my post:

static i32 ipBuffer[1999] = {0};
static i32 ipHalfBuffer[999] = {0};

and in scan_start the buffer being is casted to i16*

iErr = SCAN_Start(iDevice, (i16*)ipBuffer, 1000, 0, 0, 0, 1);

Isn't that enough? I still cannot sort out the strange scan results.

Another question I have is:
If I acquire data from 8 channels using double buffering, should I configure the event of scanning the right amount of samples for one half-buffer transfer operation just for one channel, or for all the channels?

eg.
iErr = Config_DAQ_Event_Message(iDevice,(i16) 1,"AI0" ...
or
iErr = Config_DAQ_Event_Message(iDevice,(i16) 1,"AI0:7" ...

Best regards,
Simon
0 Kudos
Message 7 of 9
(4,942 Views)
It still seems to me that it is the alignment of 16 bit to 32bit.
 
Can you take a look or even run this C code in the link below
<a href="http://digital.ni.com/public.nsf/websearch/B82DB701019383B18625673C006835AC?OpenDocument">PCI-6110E, PCI-6111E and DSA boards Return Corrupt Data on Analog Input when Transferring Data to an Unaligned 32-bit Buffer</a>
 
I also saw another way doing the same thing that you might want to try.
 
static i16 acqBufPtr[2 * NUMSAMPLES + 1]; // Allocate buffer to be at least one word larger than required

if((u32)acqBufPtr % 4) // If buffer is not aligned on 4-byte boundary, adjust pointer
acqBufPtr += 1;

iStatus = DAQ_Op(iDevice, iChan, iGain, acqBufPtr, ulCount, dSampRate); // Pass aligned buffer to acquisition function
Joji
0 Kudos
Message 8 of 9
(4,923 Views)
It still seems to me that it is the alignment of 16 bit to 32bit.
 
Can you take a look or even run this C code in the link below
PCI-6110E, PCI-6111E and DSA boards Return Corrupt Data on Analog Input when Transferring Data to an...DIV>
 
I also saw another way doing the same thing that you might want to try.
 
static i16 acqBufPtr[2 * NUMSAMPLES + 1]; // Allocate buffer to be at least one word larger than required if((u32)acqBufPtr % 4) // If buffer is not aligned on 4-byte boundary, adjust pointer acqBufPtr += 1; iStatus = DAQ_Op(iDevice, iChan, iGain, acqBufPtr, ulCount, dSampRate); // Pass aligned buffer to acquisition function

Buddy Curtis Applications Engineer National Instruments
Joji
0 Kudos
Message 9 of 9
(4,924 Views)