Create a Custom Power Meter Driver


This topic requires that you have a working knowledge of Visual Basic.

This topic will help you create your own power meter driver for use with Source Power Calibration on the PNA. If you are using an Agilent Power Meter to perform a Source Power Calibration, you do NOT need to create your own driver.

Your Power Meter driver will be created from a template written in Visual Basic using VISA over the GPIB bus.

Note: This procedure applies to Visual Basic 6.0.  Applicability to Visual Basic .NET has not yet been investigated.

Other SCPI Example Programs

Prepare Template Files

  1. Copy all the files from the PNA hard drive C:/Program Files/Agilent/Network Analyzer/Automation/Power Meter Driver Template folder, to a folder on your development PC.

  2. In Visual Basic click File, then Open Project…, find MyPowerMeter.vbp (a file you copied from the PNA). Click Open. This is a VB ActiveX EXE template, which you will fill in to become your driver.

  3. Click Project, then MyPowerMeter Properties. Click the General tab.

  4. Overwrite the Project Name with a name of your own choosing. This will be the name of your driver’s type library (also the default name of your exe).

Note If the name of your exe does not match the VB Project Name with which it was compiled, registration of the exe on the PNA will not succeed.

  1.  Set the Project Description. After building your driver if you wish to test it using VB, this is the string that will show up in the VB References list of your test project, and also in the lower pane of the VB Object Browser.

  2. Set the Thread Pool size to 1 thread.

  3. Click OK to close the project properties dialog.

  4. From the VB Project menu, click References…  Ensure that Agilent PNA Power Meter 1.0 Type Library and VISA Library are checked. Click OK.

Note:  Agilent's implementation of VISA is installed as part of the Agilent I/O Libraries on the PNA.  For help on VISA, go to the Windows Start button on your PNA, select Programs, Agilent IO Libraries, VISA Help.


Modify Template Files

From Visual Basic View menu click Project Explorer. Expand the Modules and Class Modules folders. Ensure there is one module (WinAPI) and one class module (PowerMeter).

Let's look at the WinAPI module first.

  1. In the Project Explorer window, click WinAPI.

  2. From the View menu click Code.

There is only one line of code you should need to modify in this module: the value of the string constant named sIDSEARCH.  The comments preceding the declaration of that string describe how to change it.  The rest of this module contains functions which will use the Microsoft Windows API to insure proper registration of your driver on the PNA.  If you know of other Windows API functions you feel might be helpful to call from within your PowerMeter class module (to help in formatting data, for example), this module would be the place to declare them.

Now let's look at the class module.

  1. In the Project Explorer window, click PowerMeter.

  2. From the View menu click Properties Window. The Instancing property must be set to MultiUse. This allows other applications to create objects from this class, such that one instance of your driver EXE can supply more than one such object at a time.

  3. From the View menu click Code.

Do NOT modify the Interfaces to IPowerMeter subroutines and functions. PNA source power cal expects to find these interfaces as they are currently defined.

The only members that you need to supply code to are those containing “Your code here” comments.

In addition, comments have been provided at the beginning of each member to describe the information that member needs to be read from or written to the power meter.

To get an idea of how communicate with the power meter using the VISA functions viWrite and viRead, examine the code which has been implemented for you in IPowerMeter_Connect, IPowerMeter_QueryMeter, and IPowerMeter_WriteMeter.


Compile, Copy, and Register Your New Driver

When your driver is ready to run, you will first need to compile it into an EXE.

From the File menu select Make exe.

After compiling, the following will instruct VB to use the same ID (GUID) every time you re-compile your project.

  1. From the Project menu, click PowerMeter Properties.

  2. On the Component tab, select Binary Compatibility and click  ...  

  3. Browse to and select your project EXE. Click Open.

  4. Click OK to close Project Properties.

  5. Save your project.

  6. Copy your driver EXE file to a folder on your PNA (do NOT use C:/Program Files/Agilent/Network Analyzer/Automation/Power Meter Driver Template folder).

  7. Run the EXE file.  A message box will pop up reporting whether or not registration was successful. If not successful, it will make a suggestion on what to fix.

When your driver is properly registered, PNA Source Power Cal should be able to associate it with the ID string of your power meter.


Test Your Power Meter Driver

We have also provided a Visual Basic project to test your new Power Meter driver. This project individually calls every IPowerMeter method and property in your driver to verify that it performs  correctly. Before running the test your PC and PNA must be configured to communicate using DCOM.

  1. Connect your PC and the PNA to LAN.

  2. Add your PC logon to the PNA. Both logons and password must match to communicate using DCOM. See Additional PNA users.

  3. Configure your driver using DCOM Config on the PNA. This will give you permission to launch and access the driver.  See Configure for COM-DCOM Programming.

Modify the Test Project

  1. In Visual Basic click File, then Open Project…, find MyPowerMeterTest.vbp (a file you copied from the PNA). Click Open.

  2. From the Project menu, click References…  From the list, find and check your new Power Meter Driver. (It should have been registered on your PC when you successfully made your driver EXE.) Click OK.

  3. From the View menu click Code.

  4. Modify the CreateObject line as follows:
    Replace MyPowerMeter with the Project Name that you chose for your driver
    Replace MyPNA with the Computer Name of your PNA.  
    For example:

Set PowerMeterObj = CreateObject("AcmeBrand.PowerMeter", "AGILENT-PNA123")

(This assumes that you kept PowerMeter as class module name in your driver.)

Run the Test Project

Ensure your power meter is connected to the PNA with a GPIB cable.

Put the PNA in system controller mode:

  1. From the PNA System menu point to Configure then click SICL/GPIB.

  2. In the GPIB box click System Controller.

Run the test project. If there are no errors, the driver is created successfully. If there are errors, try to figure out what went wrong and fix it. Then re-compile, re-copy the .exe to the PNA, and re-run the test. You should not need to re-register the driver or re-modify the test program.