PXI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to format/send VISA messages in 'C' for PXI

How do I format/send VISA commands to a PXI Switch device such as

- niSwitch_InitWithTopology(instr, topology, VI_FALSE, VI_TRUE, &switchSession); using ANSI C ?  How do I query the result ? 

I am able to use VISA commands to Open, Find Resources etc., but I would like to use VISA (message based) commands to perform various functions such as Self-Test, MakeConnection etc.  I am using ANSI C under VC++.  I am new to PXI and VISA and I tried to make this work using the following snippet, but get nonsensical results.

viPrintf (instr, "niSwitch_InitWithTopology(instr, topology, VI_FALSE, VI_TRUE, &switchSession)\n");

viPrintf (instr,"niSwitch_self_test (instr, &SelfTestResult, testMessage)\n");

viScanf (instr, "%s", testMessage);

Thanks in advance for any help.

0 Kudos
Message 1 of 3
(3,392 Views)

Hi pxi_user,

A function with a C Function Prototype such as:

ViStatus niSwitch_InitWithTopology (ViRsrc resourceName, ViConstString topology, ViBoolean simulate, ViBoolean resetDevice, ViSession* vi);

returns whether or not the function was successful.  This is stored in a ViStatus variable.  This, I am guessing, is what you are interested in.

Please check out some C Examples to see how we perform error handling.  Normally, in our example VIs, we will use the method outlined in niSwitchErrorHandler.  Please view this program and then another that shows its use.  I would recommend the C programs located in the following folders:

C:\Program Files\IVI\Drivers\niSwitch\Examples\CVI\niSwitchErrorHandler
C:\Program Files\IVI\Drivers\niSwitch\Examples\CVI\niSwitchControllingAnIndividualRelay

In the end, the function will look something like below:

niSwitchCheckErr(niSwitch_InitWithTopology(resourceName, topology, VI_FALSE, VI_TRUE, &switchSession));

If this does not assist you, please let me know what the results you are currently getting look like.  Thanks!

Chad AE
Applications Engineer

 

Message 2 of 3
(3,379 Views)
Chad,
    Thanks for the info.  I did end up using some of those calls.  As a newbie to this, I thought the niSwitch_InitWithTopology(..) type calls were at the NI-Switch level which I thought was a layer below the VISA layer.  I also thought all VISA calls were going to be viOpenDefaultRM (..), viGetAttribute(..) etc. (In effect I thought using niSwitchXYZ(..) calls with viABC calls was mixing code across layers and although it would work, would not be recommended).   I believe the examples you've pointed out have/will help me out alot.
 
Thanks.
0 Kudos
Message 3 of 3
(3,370 Views)