Miscellaneous‎ > ‎

OSX - NI USB - Matlab - calllib

One day Matlab will port the data acquisition toolbox to OSX and we will all be happy.  Until that time we are stuck with fiddly-farting around with the NI-DAQmx Base drivers.

My setup:
  • MacBook Pro 2.5 GHz - Core 2 Duo
  • National Instruments USB-6008
  • Macintosh OSX 10.5.8
  • Matlab 2009b (64-bit)
  • NI-DAQmx Base 3.2.0

Another possible method of using the NI drivers is to use the loadlibrary and calllib functions in Matlab.  I got a head-start in this direction by reading this for M-series cards.

There are a number of annoying caveats to getting this to work.  The first is that the libraries that I have don't have an extension.  This causes a problem because Matlab insists that they have a .dylib extension. Therefore, I copied the library "nidaqmxbase" from
 /Library/Frameworks/nidaqmxbase.framework/Versions/3/nidaqmxbase 
and renamed it to nidaqmxbase.dylib

I put this file and the header file
/Applications/National Instruments/NI-DAQmx Base/Includes/NIDAQmxBase.h
into a common directory.  Remember that this header file is your friend, you can look up the necessary error codes directly and get the appropriate values for the defined values.

Now you can load the library:

mx_LibraryName = 'nidaqmxbase';
if ~libisloaded(mx_LibraryName)
    loadlibrary(mx_LibraryName,'NIDAQmxBase.h');
end

And then painfully start creating functionality using the calllib function, e.g.

% DAQmxBaseCreateTask
mx_TaskName = h.TaskName;
mx_TaskHandle = [];
[mx_ErrorID,mx_TaskName,mx_TaskHandle] = calllib(mx_LibraryName,'DAQmxBaseCreateTask',mx_TaskName,mx_TaskHandle);

Attached to the end of this page are some very basic files that recreate the contAcquireNchan.c example.

ċ
contAcquireExample.m
(1k)
Jeff Bingham,
May 6, 2010, 9:58 PM
ċ
readDAQ.m
(1k)
Jeff Bingham,
May 6, 2010, 9:58 PM
ċ
setupDAQ.m
(2k)
Jeff Bingham,
May 6, 2010, 9:58 PM
ċ
shutdownDAQ.m
(1k)
Jeff Bingham,
May 6, 2010, 9:58 PM
Comments