08-10-2006 11:42 AM - edited 08-10-2006 11:42 AM
Message Edited by -kb on 08-10-2006 11:47 AM
08-11-2006 01:49 PM
Hello -kb,
I see that you are using an NI-DAQCard 6024E with
Traditional DAQ 7.4.1 in Visual Studio C++. If you are just starting your
application (from your post seems to be the case), I would definitely
recommend using the NI-DAQmx driver. The driver you are currently using
only supports our older hardware, while the NI-DAQmx driver supports all new
hardware and most of the old hardware.
This means you could take the code you write for your
DAQCard 6024E and use it with a USB M series or a PCI-6251 without any
changes. Beyond the hardware compatibility it is far easier to
program. From your explanation you simple want to perform continuous
acquisition and read the data every 10ms. This is really easy to do in
DAQmx. You can find all DAQmx shipping examples here once DAQmx is
installed:
C:\Program Files\National Instruments\NI-DAQ\Examples\DAQmx
ANSI C
The continuous acquisition examples use an event to trigger
your data acquisition. This allows the DAQmx driver to create a thread
and only notify your application when a specific number of samples have been
acquired. You do not have to use the callback functions if you do not
want to. You could just as easily modify the finite sample examples and
perform your data acquisition in a loop.
If you use a callback function, and you
specify a sampling rate of 1000Hz, you would set the callback function to occur
every 10 samples. Inside this callback
function you could then read all the available data. Alternatively, you could in a loop perform
the data read (if you do not register a callback function) and specify to read
10 samples.
I would highly recommend moving to DAQmx if you are just
starting your application. If you do not have it installed, you can find
your device and the newest supported driver here.
Regards,
Jesse O.
Applications Engineering
National Instruments
08-11-2006 03:14 PM
Jesse,
Thank you very much for your response. Back in February, I think it was, when I was investigating using NI-DAQmx or Traditional NI-DAQ, I could not find any support documentation for using NI-DAQmx with Visual Studio C++. It also appeared that NI-DAQmx was compatible only with versions 7.0 and later of Measurement Studio, while my lab has verion 6.0. In any case, I am using VS C++ and you seem to indicate that this is compatible with NI-DAQmx. I imagine I would do the same thing in VS as with the Traditional NI-DAQ, where I include the nidaq and nidaqex libraries in the project and be sure to point to the appropriate include and lib folders? Also, if I install NI-DAQmx, will I still be able to use applications that use Traditional NI-DAQ? Thanks again.
-kb
08-11-2006 03:30 PM
Hello -kb,
You can use DAQmx in Visual C++. When you install DAQmx, there will be an
option to include the DAQmx C Support. When you install this you will get
the C API support, along with shipping examples (mentioned in my last post),
and a bunch of documentation.
The DAQmx C Reference Help is located under Start >> Programs >>
National Instruments >> NI-DAQmx >> NI-DAQ C Reference Help.
NI-DAQmx was first release with Traditional DAQ in version 7.0. Later Traditional
DAQ and DAQmx where split into two separate drivers. You can have both
DAQmx 8.3 and Traditional DAQ 7.4.1 installed on the same machine at
once. This allows you to use either DAQmx or Traditional DAQ on your
different cards. You can even use DAQmx or Traditional DAQ on the same card
(just not at the same time). For more information on programming in
different text based languages please see an online document found here.
Now you also mentioned Measurement Studio compatibility of DAQmx. It is true
that Measurement Studio 7.0+ take advantage of DAQmx in Visual Studio .NET, however you can still
have applications with Measurement Studio 6 and DAQmx 8.3 in Visual Studio C++ 6. Measurement
Studio 7.0 + has the ability to use the DAQ Assistant to allow you to point and
click program. From the wizard that appears you simply make you
selections and it codes that section in your program. In Measurement
Studio 6, this option is not available but you can still definitely use DAQmx
in your application for its other functionality (i.e. graph and mathematic
operations).
Regards,
Jesse O.
Applications Engineering
National Instruments
08-15-2006 04:31 PM
Hi,
I installed NI-DAQmx 8.3 and got some test programs running. Things still aren't working out so well.
My loop isn't as stable as I'd like it to be, so having an event occur every nth time as you suggested won't provide the timing that I need. Unless... let's say I have the sample rate set to 50 kS/s and every msec, or every time 50 samples are acquired, it writes the data to an input buffer, overwriting what was previously there. Then, when I use the input buffer, that data will be at most 1 msec old. I assume then I'd need something to check that the event is not writing to the buffer when my routine is reading from it, correct?
In the meantime though, I have been attempting to use the RelativeTo and Offset properties. Here, I set RelativeTo to DAQmx_Val_MostRecentSamp and Offset to -n samples to read. My understanding of the help files says that whenever I use the read function to read samples from the (continuous) task, NI-DAQmx will determine the index where data is being read into the buffer (End of Data) at that specific time and subtract n samples. That range of End of Data minus n to End of Data is what is returned. However, it does not appear to be working that way. Instead, the data that seems to be returned are Current Read Mark minus n to Current Read Mark, where Current Read Mark is the End of Data index from the previous read. Am I interpreting the help files incorrectly? Do you have any suggestions for determining the End of Data index?
Thanks again.
-kb
08-16-2006 12:52 PM
Hello -kb,
First, you do not have to worry about the DAQmx buffer overwriting data while
you are reading it. DAQmx uses a circular buffer, and you should be
reading from one end, when it fills in the other. When you perform a
DAQmx read, it will give you the oldest samples. If you look in the
shipping examples, you will see that the buffer size is not explicitly
set. Although you can set the buffer size, DAQmx computes what it thinks
is appropriate based on your sampling rate and number of samples to read.
If your application cannot keep up with the rate the DAQ card is filling the
buffer it will generate an overflow error and report that it has over written
samples.
Therefore, if your computer is fast enough, you should be able to create a loop
with a DAQmx read inside it. I have modified an example program and
attached the c file below. It has the DAQ card read data in at 10KHz and
has a loop acquire 100 samples as fast as it can. It displays to the
screen when it has read the 100 samples, and how many samples are still in the
buffer.
Therefore, if you first start your acquisition and you read in 100 samples and
there are 2 remaining, your loop took 102/10000 = 0.0102 seconds. The
next time you read from the buffer the two samples that were remaining before
are read in.
Please let me know if this helps you out. If you find that you are
reading in 100 samples and a lot are remaining it is because your software/PC
cannot keep up.
Regards,
Jesse O.
Applications Engineering
National Instruments
08-16-2006 03:59 PM
08-16-2006 06:13 PM
08-16-2006 06:54 PM
hi,
This is very weird. What system are you running on? What I showed before was the read results when i was between 0 and 600. Here is my output for i>9500 to be consistent with your output:
Acquired 100, Remaining in Buffer2 400 1051
Acquired 100, Remaining in Buffer2 300 1053
Acquired 100, Remaining in Buffer2 200 1055
Acquired 100, Remaining in Buffer2 100 1056
Acquired 100, Remaining in Buffer2 0 1059
where the last number is the time in msec since the task started. What does your data look like for i<600?
-kb
08-17-2006 11:03 AM
Hello -kb,
I believe the difference is because you used a DAQCard (pcmcia), and I was
using a PCI device. I have modified the original code I posted so that it
changes the data transfer request condition. Now you should see numbers
similar to mine. Please see the attached c file below.
Regards,
Jesse O.
Applications Engineering
National Instruments