Code covered by the BSD License  

Highlights from
DAQmx examples

4.0

4.0 | 1 rating Rate this file 20 Downloads (last 30 days) File Size: 41.23 KB File ID: #27609

DAQmx examples

by Nathan Tomlin

 

14 May 2010

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

| Watch this File

File Information
Description

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

MATLAB release MATLAB 7.8 (R2009a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (4)
01 Jun 2010 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);

07 Jun 2010 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);

27 Jul 2010 Daniel Arellano

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

27 Jul 2010 Nathan Tomlin

No, I've never used simulink.

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
national instruments Nathan Tomlin 14 May 2010 09:31:06
nidaq Nathan Tomlin 14 May 2010 09:31:06
daqmx Nathan Tomlin 14 May 2010 09:31:06
daq Nathan Tomlin 14 May 2010 09:31:06
data acquisition Nathan Tomlin 14 May 2010 09:31:06
nidaqmxh Nathan Tomlin 14 May 2010 09:31:06
nicaiudll Nathan Tomlin 14 May 2010 09:31:06
national instruments Mark Dalton 11 Nov 2010 06:35:00
daq Nasrin 06 May 2012 04:18:32

Contact us at files@mathworks.com