View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
DAQmx examples

4.0 | 1 rating Rate this file 9 Downloads (last 30 days) File Size: 41.2 KB File ID: #27609 Version: 1.0

DAQmx examples



Examples of talking to a National Instruments (NI) DAQ card without the data acquisition toolbox.

| Watch this File

File Information

Examples of using matlab to talk to a National Instruments (NI)
DAQ card _without_ the 'data acquisition toolbox'

I have mainly used code and examples from Jens Roesner here:
However, I had to make a few slight tweaks to get it to work for me. I have only tested this on Matlab 7.8.0 (R2009a) on WinXP with a NI PCI 6220 board, so no guarantees.

Using Jens' code, I got an error -200088 whenever I tried to create a channel. To get it working, I had to change the initial task handles to uint32([]) which then returned a pointer for taskhandle

I also had trouble with creating tasks, then losing the taskhandle, and not being able to create the same task because of a name conflict. The solution is to not name any of the tasks - names don't seem to be useful anyway. So all my functions pass an empty string as a name.

Other changes are just cosmetic -
made functions for common tasks to simplify my main code
put all task handles in structure so easy to clear

MATLAB release MATLAB 7.8 (R2009a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (6)
21 Aug 2012 Alan Armstrong

I've tried to use your code but every time I try to load the library I get:

Warning: Warnings messages were produced while parsing. Check the functions you intend to use for correctness. Warning text can be
viewed using:
> In loadlibrary at 344
In TestDAQCard_1 at 11
Error using loadlibrary (line 419)
There was an error loading the library "C:\Documents and Settings\Administrator\My Documents\PhD\MATLAB\Experiment_2\nicaiu.dll"
A dynamic link library (DLL) initialization routine failed.

Error in TestDAQCard_1 (line 11)
loadlibrary('nicaiu.dll', 'NIDAQmx.h', 'mfilename', 'b') % The lib and h files are both in the matlab path so no need for the
above line(s)

Caused by:
Error using loaddefinedlibrary
A dynamic link library (DLL) initialization routine failed.

I use 'loadlibrary('nicaiu.dll','NIDAQmx.h', 'mfilename', 'b')' since I've added niaiu.dll and NIDAQmx.h to my matlab folder.

can you help?


Comment only
26 Jun 2012 nico974

Hello, I have to acquire some analog samples over 30 seconds (1 sample every 0.01s). How can I do using a for loop in Matlab ?

Comment only
27 Jul 2010 Nathan Tomlin

No, I've never used simulink.

Comment only
27 Jul 2010 Daniel Arellano

Are you by chance using this code as S- Function? If so how did you implement it

Comment only
07 Jun 2010 Dustin

Dustin (view profile)

Found a fix for R2009b:
taskh = libpointer('voidPtrPtr',0);
muxHandle = taskh;

[result, ~, muxHandle] = calllib('nidaqmx','DAQmxCreateTask','',muxHandle);
[result, a, b] = calllib('nidaqmx','DAQmxGetTaskName',muxHandle,charBuffer,length(charBuffer));
[result,~,~,~] = calllib('nidaqmx','DAQmxCreateDOChan',muxHandle,'/Moo/port0/line0:3','MUXlines',0);

Comment only
01 Jun 2010 Dustin

Dustin (view profile)

Does not seem to work for R2009b (32-bit) on Windows 7 (32-bit) w/ NI-DAQmx 9.1.0.

??? Error using ==> DAQmxCheckError at 24
DAQmx error - NULL pointer was passed for a required parameter.

Error in ==> DAQmxCreateDOChan at 28

Contact us