Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

PXI 6541 MATLAB

Hello,
My query is regarding the use of MATLAB with NI digital waveform generator/analyser. I've tried to research the subject as extensively, and found that wrappers are required for certain programs that can be used with the hardware, but for MATLAB versions from 6.5.1 onwards do not require the wrapper. Could someone confirm this for me and if anyone has any insight, on using NI-HSDIO and its hardware with MATLAB, could give me some advice?
Thanks in advice!
Regards,
ak123 
0 Kudos
Message 1 of 30
(5,271 Views)
Matlab has an Instrument Control Toolbox that allows creation of wrappers around IVI instrument drivers.  I believe this toolkit can create a Matlab wrapper for the NI-HSDIO driver.  Without creating a wrapper, I think you would be left with calling functions in the driver DLL directly from Matlab.  The Mathworks should be able to provide further assistance.  Using the NI-HSDIO driver in Matlab should be similar to using any other IVI-C driver in Matlab.
0 Kudos
Message 2 of 30
(5,261 Views)

Hey,

Thanks for the reply. I'm still trying to grasp how to use the functions and communicate to the card, but I've made a note of the pointers you've given so I can use it when I'm more proficient in using it. In the mean time I was having a play with MATLAB and the card but I keep getting a negative return value when trying to initiate the generation session. And I can't seem to input a device name as a parameter for that function (niHSDIO_InitGeneratioSession). I think it might be something to do with the visession as well? I've had a look into the include files and found variables like VI_NULL, VISESSION vi, but can't figure out how to use it. Do you have any idea about visession and the device id?

Thanks a heap again!

0 Kudos
Message 3 of 30
(5,256 Views)

To understand the programming flow for the HSDIO driver, I'd recommend utilizing the Programming section of the NI Digital Waveform Generator/Analyzer Help, located in the Start menu:

Start >> Programs >> National Instruments >> NI-HSDIO >> Documentation

 

niHSDIO_InitGeneratioSession takes a Device Name as an input parameter and ouputs a VISESSION. This VISESSION is then used by the other driver functions.  The device name can be found in the NI Measurement and Automation Explorer (MAX) tool found on your desktop.  Device Names are typically of the form Dev1.

It may be helpful for you to look at some examples that ship with the HSDIO driver.  While we do not ship Matlab examples, there are C example that may be helpful for you to understand how to program the device:

C:\Program Files\IVI\Drivers\niHSDIO\Examples\c\

 

Hope this helps.

0 Kudos
Message 4 of 30
(5,249 Views)
I've tried the help file you recommended that's where I found the functions available. The c examples shipped with the driver is quite helpful however MATLAB doesn't seem to like any device name. For example, i used the dynamic generation example and did the following:
>> loadlibrary('niHSDIO','niHSDIO')
>> calllib('niHSDIO','niHSDIO_InitGenerationSession','Dev1',1,0,0,1)
but it gives me an error of :
Array must be numeric or logical or a pointer to one.
 So i tried to be sneaky and changed the device name to "1" (via the MAX tool)
>> calllib('niHSDIO','niHSDIO_InitGenerationSession','1',1,0,0,1)
and got the same error, but if i do:
>> calllib('niHSDIO','niHSDIO_InitGenerationSession',1,1,0,0,1)
i get:
ans =
 -1.0738e+009
and after looking into the help file of niHSDIO, a negative return value means theres errors, so I tried to find out what the errors were by using niHSDIO_GetError and got:
ans =
 -1.0741e+009
so i then tried niHSDIO_ClearError and got:
ans =
 0
then tried to initiate it again and the process repeats again!
I can't seem to find any MATLAB examples online either, so I'm probably draining you of suggestions, but any more ideas?
Thanks
 
0 Kudos
Message 5 of 30
(5,242 Views)
You are on the right track. The -10738xxxx error is an actual error code.  You need to return the message string from the GetError function.  This will provide more details about the error, and ideally help you resolve it.  It would be helpul to expand the error number to see all digits.  You would also be able to search this site for more details if you had the full error code.
 
The Device Name is a string, so you need to pass this value to the DLL as a string.
 
Before getting too far, you should confirm the hardware functions properly in MAX, by performing a Self-Test and running the Test Panel.
0 Kudos
Message 6 of 30
(5,228 Views)
Hello!
Right I think I have found the problem, but I need a bit of expertise advise on it. Matlab has a problem with getting the visession handle cause it can't get the device name which you can get from MAX or NIHSDIO_WmInfo('nihsdio') (something like that). so to cut the long story short, matlab can't support the ivi com driver with the card. I've been on the matlab website and it doesn't list pci 6551 (we're using this card now) as one of its supported hw, but I'm going to try my luck anyway and search the matlab website for any tips on using ivi com drivers! So my question is, does this make sense and am I still on the right track?
Thanks!
p.s. did the self test and used the test panel all is fine there. and when i put in device id as 'Dev1' it throws an error asking for a scalar argument, and the Get error function throws back the same error code when I ask for a description.


Message Edited by ak123 on 12-12-2007 08:51 AM
0 Kudos
Message 7 of 30
(5,211 Views)

The NI-HSDIO driver is actually an IVI-C driver, not IVI-COM.  It seems that your issue is with sending string arguments to the DLL within MATLAB.  Perhaps, The Mathworks can assist you with this as I don't have much experience with that.

0 Kudos
Message 8 of 30
(5,207 Views)
Hello Jason,
Firstly thanks for that advice about the string, you were right, and I found out what the problem was. The static generation script works great! I'm working on the dynamic generation now, it refuses to write data or initiate it. but i'm still playing with it. 
will keep you informed if i run into any more problems. Thanks for all the help again.
 
0 Kudos
Message 9 of 30
(5,181 Views)
Hey,
I've tried to sort the writenamedwaveform function, but it's not having it. This is what i've written and get:

name =

'a';

name2 =

'';

name4 =

'';

b = [10101010,01010101'];

name5 =

'myWmf';

name6= 100;

clock = libpointer(

'int8Ptr',int8(51));

sampleClockRate =(double(10));

pname = libpointer(

'int8Ptr',int8(name));

pname2 = libpointer(

'int8Ptr',int8(name2));

pname3 = libpointer(

'uint32Ptr',0);

pname4 = libpointer(

'int8Ptr',int8(name4));

p = libpointer(
'int8Ptr',int8('t'));

waveformdata = libpointer(

'uint32Ptr',uint32(''));

[errgen pname pname2 pname3] = calllib(

'niHSDIO','niHSDIO_InitGenerationSession',pname,1,1,pname2,pname3)

[errass pname4] = calllib(

'niHSDIO','niHSDIO_AssignDynamicChannels',pname3,pname4)

[errcon clock] = calllib(

'niHSDIO','niHSDIO_ConfigureSampleClock',uint32(pname3),clock,sampleClockRate)

errmode = calllib(

'niHSDIO','niHSDIO_ConfigureGenerationMode',uint32(pname3),14)

calllib('niHSDIO','niHSDIO_WriteNamedWaveformU32',pname3,p,32,waveformdata)

errint = calllib('niHSDIO','niHSDIO_Initiate',pname3)

And the output throws an error for write and initiate:

ans =

 -1.0741e+009


errint =

 -1.0741e+009

im running out of ideas on what could be wrong.

Any suggestions?

0 Kudos
Message 10 of 30
(5,168 Views)