Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

PXI-VISA-MATLAB

Solved!
Go to solution

Running the following Matlab code:

Visa6541Address = 'PXI17::14::INSTR';

vv=visa('ni',Visa6541Address)
fopen(vv)

reg1 = memread(vv,0,'uint16','PXICFG',3)

fclose(vv)

 

Results in reg1 = 4243, 28887,6

Where is there a reference to tell me what these number mean please?

 Thanks for any suggestions you can offer!

0 Kudos
Message 1 of 3
(2,919 Views)

Hi! Can you give more information on what you are doing? The code alone doesn't tell much.

 

0 Kudos
Message 2 of 3
(2,888 Views)
Solution
Accepted by topic author jmreylan

Hello,  Sorry it took me so long to reply.    The code I posted seems too low level to be of much use (unless you happen to be the PXI-6541 designer).   I spent a lot of time trying to control the PXI-6541 through the Matlab Instrument Control Toolbox.  I have concluded that ICT is useless for the PXI-6541 (not generalizing about all NI PXI instruments).  The only way to control the PXI-6541 through Matlab is to write a *.mex file that calls the niHSDIO driver functions.  NI has lots of examples of 'C' programs that do this so all you have to do is convert them to *.mex.   Than you will have a Matlab function that you can call from a *.m file.    You also need Microsoft Visual C installed.

 

Here is an example of how to compile and link:  mex SPIcontrol.c '-LC:\Program Files (x86)\IVI Foundation\IVI\Lib_x64\msc' -lniHSDIO.lib.  SPIcontrol.c has a mex structure, a little different but well documented at Mathworks.com.  For example, instead of a "main" there is :

 

/* The gateway function must look like this, don't change names*/
void mexFunction( int nlhs, mxArray *plhs[],
                              int nrhs, mxArray *prhs[])
{

ViRsrc deviceID = "Dev1"; // NI-MAX assigned this

ViSession generationViSession = VI_NULL; // Not sure why this is called NULL
stat[0] = (double) niHSDIO_InitGenerationSession(deviceID, VI_FALSE, VI_FALSE, VI_NULL, &generationViSession);

and so on....

Finally in your Matlab .m file you have something like:

Emat = SPIcontrol(hex2dec('1234')) % 6541 transmits 1234 on 15 parallel channels out the front panel and returns errors

Maybe this will save some of your readers some time.

0 Kudos
Message 3 of 3
(2,870 Views)