Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Measuring Agilent Power Meter using VC++

i am unable to connect to my Agilent Power Meter E4416A using a simple appication that is done in VC++...
i have downloaded the AgilentRFPowerMeter driver.. there are some sample application in it which is done in cpp.. that was in simulation mode...i have dome some changes so as to make it work with the equipment... the driver initialization part is as follows
.
.
.
IAgilentRFPowerMeterPtr spDrvr(__uuidof(AgilentRFPowerMeter));
spDrvr->Initialize("GPIB0::13::INSTR", VARIANT_TRUE, VARIANT_TRUE, "QueryInstrStatus=true");
.
.
.
Error : AgilentRFPowerMeter : Unknown Resource
 
Is there anything else that i need to do to make it work with the equipment... i am new to this...   Can somebody help me in this???
0 Kudos
Message 1 of 14
(5,859 Views)
Hello Devasena,

Thank you for contacting National Instruments. I see that you are communicating to your device through GPIB, however I want to ask how are you connecting Agilent Power Meter, in other words which National Instrument GPIB device are you using? Also, I wanted to know if you could communicate to the instrument at all, try doing just a simple query to see if you can.
Regards,

Roland A.
Applications Engineer
National Instruments

Check out VI Roadshow
0 Kudos
Message 2 of 14
(5,826 Views)
It seems like that is a resource (VISA address) problem.  What version of VISA library are you using? NI-VISA or Agilent IO Libraries Suite?  If uing NI-VISA, it is better to first check the instrument connectivity by using NI-MAX (NI Measurement & Explorer).  If using Agilent IO, a similar program named Agilent Connection Expert can do the same thing as well.  Unless your instrument is recognized by the NI-MAX or Connection Expert, IVI drivers will never work with real I/O connection.
0 Kudos
Message 3 of 14
(5,807 Views)

hi,

thanks for ur reply... my problem got solved. i was using RS232 n not GPIB... now i could work with my E4416A.... but i have one more doubt, Is there any other name that can be used as resource descriptor which is independed on GPIB/RS232???

I have read about using IVI session factory... in the online tutorial they have mentioned that the Logical name of the machine has to be used for initiating the driver.... what is this Logical name?... what is the logical name for E4416A?.... can we use the same name instead of the VISA Address if i am using IVI COM drivers for Agilent RF PowerMeter...

My aim is to write a VC++ MFC application which will measure the readings from any(currently agilent only, later planning to enhance to any)  power meter....  this can be done using IVI session factory right? can u help me in this? i am  new to this...

 

 

0 Kudos
Message 4 of 14
(5,785 Views)
> Is there any other name that can be used as resource descriptor which is independed on GPIB/RS232???
 
To simply assign an "alias" name for a specific VISA resource, you can create it.  From NI-MAX, open the menu --- Tools -> NI-VISA -> VISA Options, then select "Alias".  Once an alias created, you can pass it to viOpen() or any IVI driver's Initialize() function.
 
> what is this Logical name?...
> what is the logical name for E4416A?....
 
The logical name is what you must create for virtual instrument such as when using IVI session factory, or IVI-C class driver's Initialize function.  There is no default logical name for E4416A unless you create one.  To create a logical name, you must install not only NI-VISA but also NI IVI Compliance Package.  (I believe Agilent IO Libs Suite 14.x comes with similar tools named Connection Expert.)  From NI-MAX, you can create a logical name under the "IVI Drivers" hierarchy.  Mind that first you must create a Driver Session object assigning a correct IVI driver, after then create Logical Name. 
 
See the attached screen copy, which is my example assigning "NewLogicalName" to "MyDriverSession", which is in turn assigned to Agilent34401 IVI-COM driver.  Once you created a logical name, you can pass it to the IVI-COM Session Factory to indirectly create a driver instance, or you can pass it to directly to the specific driver's Initialize() method.
 
> this can be done using IVI session factory right? can u help me in this? i am  new to this...
 
Yes it is the right way. The only way to realize the interchangeability with IVI-COM is use the Session Factory, which only accepts logical names when it initializes.  (You can not pass any true VISA resource or any VISA alias to the session factory.) As for IVI-C, the interchangeability is realized by using a class driver instead of session factory.
 
0 Kudos
Message 5 of 14
(5,777 Views)

do  we need to add/ install any other drivers than IVI n AgilentRFPowerMeter COM to work with GPIB port ??(i am working with a COM port, its working for me... my friend is tried the same application with GPIB(only change is GPIB address right?).. its not working for him) y? i just said him to install IVI n AgilentRFPowerMeter COM driver.. isnt that enough???

how to set the baud rate of the interfaces(COM n GPIB) through the program?

 i didnt see any Communicate class under system class..

in the programmers guide it is said that SYSTem:COMMunicate:SERial:[:RECeive/TRANsmit]:BAUD

Then the system class needs a communication class which has all these options right?... what else class has this option?

0 Kudos
Message 6 of 14
(5,735 Views)
> isnt that enough???
 
Not enough!  To use GPIB interface, the target machine must also install GPIB driver software that supports the specific GPIB card. If using NI's GPIB card, the device driver comes with NI-488.2M Software For Windows VER2.x (the latest is VER2.4).  If you are using Agilent GPIB (HP-IB) card with Agilent VISA, the Agilent IO Libraries Suite 14.x already contains Agilent's GPIB device driver.
 
> how to set the baud rate of the interfaces(COM n GPIB) through the program?
 
If you use GPIB card hardware, no need to set baudrate.  GPIB has no such baudrate values.  (GPIB bus handshake speed will be automatically managed by the GPIB LSI chip.)
 
> in the programmers guide it is said that SYSTem:COMMunicate:SERial:[:RECeive/TRANsmit]:BAUD
 
You don't have to send this command when using GPIB.  Although the Agilent IVI-COM driver may use this command inside the driver implementation, the driver will skip this command if your app passes GPIB0::x::INSTR address to the driver's Initialize() function. 
0 Kudos
Message 7 of 14
(5,732 Views)

thanks for ur reply..

what if i need to set the baud rate of the COM port??

which VC++ COM driver class has that option?

 

 

0 Kudos
Message 8 of 14
(5,727 Views)

Setting comm baudrate may have two cases -- 1)set baudrate at PC side, 2)set baudrate at instrument side. 

1)PC baudrate

You can use viSetAttribute() function (if using VISA32.DLL API) or ISerial::Baudrate property (if using VISA-COM API).  VC++ also has SetCommState() API function but it has no meaning if using VISA.

VISA-C (VISA32.DLL) API style is:
vs = viSetAttribute( vi, VI_ATTR_ASRL_BAUD, 9600);

VISA-COM API style is:
ISerialPtr spSerial = spYourVisaSession;
spSerial->BaudRate = 19200;

But when using an IVI driver, there are two cases regarding PC's baudrate --  a)The driver is built with hard-coded baudrate (normaly coding the instrument's available max baud), b)The driver opens VISA with utilizing configuared baudrate such as by NI-MAX.  The case a) you don't have to change the PC baudrate manually and the instrument baudrate must only be the same with it.  The case b) you can use any baudrate you want as long as the NI-MAX configuration and instrument baudate are matched.  (But normally no meaning to use 4800 or slower baudrate with your Pentium4 PC, if the instrument is supporting faster baudrates.)

2)Instrument baudrate:

Normally instrument baudrate shall be set by the instrument front panel BEFORE running the app.  But if the app wants to change it through the online, you will use SYSTem:COMMunicate:SERial:BAUDrate command. However, to use this command, your app has already established a serial communication with a known baudrate.  If the app is unable to communicate with the instrument due to unknown baudrate, it is also imposiible to send SYSTem:COMMunicate:SERial:BAUDrate. 

 

0 Kudos
Message 9 of 14
(5,722 Views)

thank you very much for ur reply....

i understood the concept now... i have tried the same...  please see the code below... is it the right way to implement ?... sorry for all these silly doubts.. i am really blank in this area... just trying to learn... :)... i am able to do the measuring without the baud rate setting lines... an exception is thrown when i included the baudrate.....

#import "GlobMgr.dll" no_namespace // Visa-Com Functionality

#import "IviDriverTypeLib.dll" no_namespace

#import "IviPwrMeterTypeLib.dll" no_namespace

#import "AgRFPowerMeter.dll" no_namespace

main()

{

HRESULT hr = CoInitialize(NULL);

 if(SUCCEEDED(hr))
 {
  // Create an instance of the driver
  IAgilentRFPowerMeterPtr spDrvr(__uuidof(AgilentRFPowerMeter));

  try
  {
   // Edit resouce descriptor and options for your system
   _bstr_t resourceDescriptor = "ASRL1::INSTR";
   _bstr_t driverSetupOptions = "QueryInstrStatus=true";//Simulate=true,

 ISerialPtr spSerial = spDrvr;
 spSerial->BaudRate = 19200;     

 // Initialize the driver
   
   spDrvr->Initialize(resourceDescriptor, VARIANT_TRUE, VARIANT_TRUE, driverSetupOptions);
   
  
   spDrvr->System->TimeoutMilliseconds = 20000;

........

 

 

0 Kudos
Message 10 of 14
(5,686 Views)