Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Use M-Series cards with DAQmx in Matlab!

Hi everyone!Very helpful thread!

I'm new in using a NI USB-6009 card with Matlab.I want to know if it is possible to use an S-function (in C code) with Real Time Windows Target toolbox from Matlab?Has anybody tried this?Could you please give me some hints in doing this? I followed the instructions in the Matlab help but it didn't work at all with an implemented S-function.

Thank you very much

Christine

0 Kudos
Message 51 of 106
(5,399 Views)
Hi Christine!

As you probably know from the RTWT manual, you can only use C-code S-Functions. But beyond that, there are some other restrictions. For example, you cannot use any Win32 calls.
The USB boards are not supported by RTWT natively. So you have to write your own I/O S-Functions (the RTWT manual mentions this briefly). I neither know whether there are some underlying Win32 calls in the sample M-code nor do I know how this would be with a function written in C 😞
As the newer RTWT versions include support for USB Joysticks, there does not seem to be a problem in addressing the USB interface from the realtime kernel. So, your plan could work out, but I'm sorry for not being able to provide definitive help.

Cheers
Jens



0 Kudos
Message 52 of 106
(5,391 Views)
 Thank y Jens!
 Today I tried to use my USB 6009 card working with the Matlab functions dedicated for NIDAQmx driver and it worked out thanks to all who offered examples:)
 I found a paper where the authors used the Matlab/Simulink to connect to their USB 6008 card. The interface is made using C code S functions with dedicated MAtlab function for NI USB cards.I tried to build a C code S function but I get stuck from the beginning..I don't know what parameters have to receive that S function...It would be great if anybody could give me some hints in doing a C code S function for connecting to ni USB 6009 card
Thanks a lot
Christine
0 Kudos
Message 53 of 106
(5,367 Views)
Hi Christine!
I have extremely little experience with S-Functions. I'd suggest trying in the Matlab Central forums over at Mathworks, if noone else here has profound knowledge.
I know it is tedious to get something to work which so closely integrates two software architectures and I'm crossing my fingers that you can get it to work.

Good luck!
Jens


0 Kudos
Message 54 of 106
(5,322 Views)
The advice here has been very useful to me, I have the loadlibrary('nicaiu.dll','nidaqmx.h','alias','myni') command working in Matlab R14sp2 (which required manual patching of loadlibrary.m to correct a bug involving file paths containing spaces <http://www.ids-spa.it/page.php?f=108&id_div=7>). I wonder whether my latest Matlab-DAQmx problem has a solution?

Thinking I was over the worst, I installed Matlab R2007a and tried the code which contains the loadlibrary() command on the NI-DAQmx 8.1 dll header file. The result was a slew of "uninitialized variable" errors from Matlab's prototypes.pl, which is called from loadlibrary, and unknown type "..." errrors from the nidaqmx.h file.

Has anyone successfully loaded the DAQmx dll in Matlab R2007a? If so, what's the trick?

TIA,
jwq

0 Kudos
Message 55 of 106
(5,292 Views)
Hi jwq!

Motivated by your problem, I tried to run the proven code in 2006b and failed. It works nicely in 2006a, though.
There might be something different about my two installations, apart form the version difference.
Perhaps we could create a broader statistic on what works where, maybe this would help us to track down the problem.
All one needs to do is copy nicaiu.dll and nidaqmx.h into the current Matlab working directory and execute the loadlibrary('nicaiu.dll','nidaqmx.h','alias','myni') command.
Interestingly, I only get a brief error message whereas you seem to get several:
??? There was an error loading the library "D:\MATLABR2006b\work\nicaiu.dll"
Error using ==> loaddefinedlibrary
Das angegebene Modul wurde nicht gefunden.
(The specified module was not found.)


Cheers
Jens



0 Kudos
Message 56 of 106
(5,284 Views)
Hi Jens,

 Thanks for the quick reply. I'm not sure what's going on with your R2006b error, but I have some more details about the R2007a warnings and a potential workaround.

The exact error messages I see are
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 277

Use of uninitialized value at C:\Program Files\MATLAB\R2007a\toolbox\matlab\general\private\prototypes.pl line 420, <INFILE> chunk 1574.
Use of uninitialized value at C:\Program Files\MATLAB\R2007a\toolbox\matlab\general\private\prototypes.pl line 443, <INFILE> chunk 1574.
Use of uninitialized value at C:\Program Files\MATLAB\R2007a\toolbox\matlab\general\private\prototypes.pl line 420, <INFILE> chunk 1649.
Use of uninitialized value at C:\Program Files\MATLAB\R2007a\toolbox\matlab\general\private\prototypes.pl line 443, <INFILE> chunk 1649.
[...]

Failed to parse type '...' original input ' ...'

Found on line 1574 of input from line 1576 of file C:\Program Files\National Instruments\NI-DAQ\DAQmx ANSI C Dev\include\nidaqmx.h

Failed to parse type '...' original input ' ...'

Found on line 1649 of input from line 1651 of file C:\Program Files\National Instruments\NI-DAQ\DAQmx ANSI C Dev\include\nidaqmx.h

[...]
I've isolated the problem to prototypes.pl version 1.1.6.20.4.1, included with R2007a. If I replace this version with prototypes.pl 1.1.6.10 from R14sp2 then the loadlibrary command completes without warnings on R2007a. I've submitted a support request to Mathworks about the warnings generated by prototypes.pl 1.1.6.20.4.1. Replacing version 1.1.6.20.4.1 with version 1.1.6.10 is thus a potential workaround for what appears to be a bug in Matlab's prototypes.pl code in the R2007a release.

I write "potential workaround" because I haven't been able to test calls to the NI-DAQmx routines, because my code needs some modification to make it work with anything greater than Matlab 6.5, but I assume that if the dll loads then the routines will function as expected. If someone else is running R2007a and could test this quicker than I will be able, I'd be interested to hear the results.

I hope this helps, if only in a small way,
jwq.

0 Kudos
Message 57 of 106
(5,270 Views)

You can use the Data Acquisition Toolbox blocks in Simulink that were added in R2006b.  They support NI-DAQmx devices like these.  However, It's only supported in host mode, not any of the real time targets.

-Rob

-----
Rob Purser
Manager, Test and Measurement
MathWorks
rob.purser@mathworks.com
0 Kudos
Message 58 of 106
(5,256 Views)

Hello all,

I've been following your thread. Here is my scenerio: I built an application that uses the two general purpose counters on a PCI-6035E board for two seperate purposes:

1) Counting TTL events.

2) Creating a pulse train.

The application ran fine on Windows 98, Matlab 6.5.1, and used the 16 bit generic driver nidaq.dll. The application ran on a realtime target.

For several reasons we built our new system using the PCI-6221 DAQ, Windows XP, and Matlab 2007a. The following respective problems arose:

1) Simulink will no longer read the counter value using the counter input block, claiming that the PCI-6221 does not have a counter input (????).

2) As Rob points out, we can't access the NI-DAQmx through the real-time targets.

 

I was able to access the counters using the DAQmx library from the command line in a fashion similar to that proposed here. I do get the slew of warning messages with the current dll, but am still able to operate.

My questions are:

- Does anybody have an idea how to control the counters from a real-time target. It is weird to me that this functionality would be lost.

- Any reason why the counters are no longer supported in current versions?

- Rob, do you know Matlab plans to improve it's support of NI-DAQ features in the near future?

 

Thanks to all of you for the help so far.

0 Kudos
Message 59 of 106
(5,182 Views)
Rob, the response to my bug report was that I should ignore the warnings if the DAQmx calls appear to work and that "since there's only a warning issued when the library is loaded, it's technically not a bug in the file [prototypes.pl] that needs to be fixed; hence there won't be a 'bug-fixed' version of the file." Given what I observe, this makes no sense to me. That aside, does Mathworks' Data Acquisition Toolbox simply ignore the uninitialised value errors on 2007a? Will this bug ever be fixed?

Ran, I'm sorry that I can't help with your problems other than to confirm that the DAQmx calls appear to function correctly despite the large number of warnings.

0 Kudos
Message 60 of 106
(5,040 Views)