Hi everyone! Happy
Labor Day to all you readers in the US!
Every month I struggle with what I am going to write and
wind up waiting till the end of the month to do my posting (and I am
keeping that streak alive). In
order to combat that, I came up with a series of topics on programming
instruments, focusing on our power supplies.
Let’s say that this is the first in a series of three (or maybe four I
am not sure). Please note that anything
that I state here is my opinion and not Agilent policy. Today I am going to focus on the how to send
commands to your instrument. In other words, what sort of IO library do you use to send
the commands?
All of my suggestions will be based on the Agilent IO
Libraries as that is the environment that I am most familiar with. There are two major options: direct IO where
you use the SCPI from the instrument and drivers where there are functions that
you call.
First let’s talk about direct IO. I learned how to program instrument using
HPBASIC as my programming language so this is where it all began with me. Agilent has two modern
standards for doing this. The first and the
older standard is the VISA library. VISA
works very well when you are programming an instrument in the C programming
language. Here is a snippet of C code from a N6700
example with VISA (I have intentionally not provided comments to show the
program in its purest form):
VISAstatus=viOpenDefaultRM(&defrm);
VISAstatus=viOpen(defrm,”GPIB0::5”,VI_NULL,VI_NULL,&session);
viPrintf(session,"VOLT 5,(@1) \n");
viPrintf(session, "OUTP ON, (@1) \n");
viPrintf(session, "MEAS:VOLT? (@1) \n");
viScanf(session,"%s",&voltmeasurement);
viClose(session);
viClose(defrm);
It works pretty well and makes sense once you know
it. The viPrintf and viScanf functions
are very similar to some basic C functions so if you are a C programmer, this
is really the way to go.
There is also a newer option that works pretty nicely in
languages that support COM. This option
is called Agilent VISA COM. VISA COM works
well in Visual Basic and C#. Here is the
same program to the above written in VB:
Set ioMgr = New AgilentRMLib.SRMCls
Set Instrument = New VisaComLib.FormattedIO488
Set Instrument.IO = ioMgr.Open("GPIB0::5")
Instrument.WriteString " VOLT 5,(@1)"
Instrument.WriteString " OUTP ON, (@1)”
Instrument.WriteString "MEAS:VOLT? (@1)”
Result = Instrument.Readstring
Instrument.IO.Close
In my opinion, this is easier to read than VISA. When I have to write a program now, I tend to
stick with using VISA COM and Visual Basic.
The other option is to use a driver. We presently offer two different driver types
for our instruments: VXI Plug and Play and IVI COM. VXI Plug and Play drivers are obsolete now
though so I will not reference them further today. Here is an example of our program using the
IVI driver (in C#):
driver = new Agilent.AgilentN67xx.Interop.AgilentN67xx();
IAgilentN67xxProtection2
protectionPtr;
IAgilentN67xxMeasurement
measurementPtr;
IAgilentN67xxOutput3
outputPtr;
int channel
driver.Initialize(“GPIB0::5”,
idquery, reset, initOptions);
outputPtr =
driver.Outputs.get_Item(driver.Outputs.get_Name(channel));
protectionPtr =
driver.Protections.get_Item(driver.Protections.get_Name(channel));
measurementPtr =
driver.Measurements.get_Item(driver.Measurements.get_Name(channel));
outputPtr.VoltageLevel(3.0,
3.0);
outputPtr.Enabled = true;
mVolt = measurementPtr.Measure(AgilentN67xxMeasurementTypeEnum.AgilentN67xxMeasurementVoltage);
driver.Close();
As you can see, the
driver is much more complex than the direct IO examples. There are a few
reasons to use a driver though. The
first and most common reason is that your system itself it designed to use
drivers. Another good reason is
portability. There are instrument
classes in the IVI driver that should work for any DC power supply that is compatible. One of the main downfall of our IVI drivers
is that the functions almost always map 1 to 1 with SCPI so there are not many
functions that work at a higher level and you don’t save any time programming
there.
My main approach is to
use VISA COM in Visual Basic. I find it
to be the easiest for me to program and it is what works for me. Of course no opinion is wrong though and we
are happy that our readers are out there buying and programming our
instruments. Thanks!