File Exchange

image thumbnail

DAQmx examples

version 1.0 (41.2 KB) by

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



View License

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

Comments and Ratings (6)

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?



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 ?

Nathan Tomlin

No, I've never used simulink.

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


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);


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

MATLAB Release
MATLAB 7.8 (R2009a)

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

» Watch video

Win prizes and improve your MATLAB skills

Play today