File Exchange

image thumbnail

DAQmx examples

version 1.0.0.0 (41.2 KB) by Nathan Tomlin
Examples of talking to a National Instruments (NI) DAQ card without the data acquisition toolbox.

2 Downloads

Updated 14 May 2010

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:
http://www.jr-worldwi.de/work/matlab/index.html
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

Cite As

Nathan Tomlin (2020). DAQmx examples (https://www.mathworks.com/matlabcentral/fileexchange/27609-daqmx-examples), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (7)

Josh

Works with an NI-6008 USB on 2018b with minor modifications.

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:
[notfound,warnings]=loadlibrary(...)
> 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?

thanks

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 ?

No, I've never used simulink.

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

Dustin

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

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

Dustin

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
DAQmxCheckError(lib,err);

MATLAB Release Compatibility
Created with R2009a
Compatible with any release
Platform Compatibility
Windows macOS Linux