Ivi Instrument Driver Programming Guide Labwindows/Cvi Edition
Ivi Instrument Driver Programming Guide Labwindows/Cvi Edition
Product names and company names that appear in this guide are the trademarks or registered
trademarks of their respective companies.
© 2020 Kikusui Electronics Corp.
Contents
Contents
Introduction............................................................................................................................. 4
Usable Interfaces........................................................................................................... 4
Building projects....................................................................................................11
Executing Programs..................................................................................................... 12
By executing a program....................................................................................... 12
Explanation of functions............................................................................................... 13
Starting sessions.................................................................................................. 13
Closing sessions.................................................................................................. 15
Handling errors............................................................................................................. 16
Building projects................................................................................................... 28
Executing Programs..................................................................................................... 29
By executing a program....................................................................................... 29
Explanation of functions............................................................................................... 30
Starting sessions.................................................................................................. 30
Closing sessions.................................................................................................. 32
Handling errors............................................................................................................. 33
Replacing instrument.................................................................................................... 34
Introduction
This guide shows examples of using a KikusuiPwr IVI Instrument Driver (KIKUSUI PWR-01
series DC power supply). IVI instrument driver made by other manufacturers and ones for
other models can be used in almost the same way.
This guide explains using the LabWindows/CVI 2019 referring to the case to create a 32-bit
(x86) program that runs on Windows 10 (x64) as an example.
This guide recommends the IVI-C instrument driver and explains referring to the procedure
of programming using the IVI-C instrument driver as an example.
Since LabWindows/CVI is a development environment assuming the use of C language, it
is easier to use a function-based C DLL than a COM DLL. Since the IVI-C instrument driver
is created by extending the architecture for the LabWindows/CVI instrument driver, it is
compatible with LabWindows/CVI.
Usable Interfaces
Memo
• The instrument class to which the instrument driver belongs can be checked from the
Windows start menu’s [Kikusui] > [KikusuiPwr IVI Driver 1.0.0 Documentation].
• In the case that the instrument driver does not belong to any instrument class, no
applications can be created that use interchangeability as the class interface is not
available.
Memo
In the case of a specific interface, the interchangeability function cannot be used. When
using the interchangeability function, be sure to use the class interface. (p.17)
1 Start LabWindows/CVI.
Welcome page is displayed.
5 Click [File] > [Save Untitled1.c As] to save the source file.
In this case, save it as “Ex01.c”.
Set the Initialize With Options function, declare the variables and insert them into the source
code.
This section explains taking the case in which the instrument is connected by the
LAN interface and the IP address is 192.168.1.5 as an example. As the parameters
of ResourceName and OptionString are character strings, enclose them in quotation
marks.
Parameters Value
ResourceName “TCPIP::192.168.1.5::INSTR”
IdQuery On (VI_TRUE in the function call description)
Reset On (VI_TRUE in the function call description)
OptionString “QueryInstrStatus=1”
Vi &vi
Status vs
Declaring variable
3 Check both the Execute declaration in Interactive Window and the Add
declaration to top of target file “Ex01.c”.
4 Click [OK].
Set the Close function in the same way as the Initialize With Options function, and insert
them into the source code.
By selecting [Ex01.c] tab, the source code will be displayed. By executing the steps in
pages 7 to 9, the source code will be as follows:
In order to make this source code an executable program, include the following content:
• Specify loading of the included file of the instrument driver.
• Enclose the recall to InitWithOptions and close in the “main” function.
• Between the recalls to InitWithOptions and close, add a recall code for the function set-
ting the voltage and current, and the function controlling the output ON/OFF. Besides the
method of inserting it using the function panel, there is also the method of entering the
source code directly with the editor as shown below.
Shown below is a sample that opens an instrument driver session, sets voltage, current,
and output, and closes immediately.
#include <kipwr.h>
static ViStatus vs;
static ViSession vi;
void main()
{
vs = kipwr_InitWithOptions (“TCPIP::192.168.1.5::INSTR”, VI_TRUE, VI_
TRUE, “QueryInstrStatus=1”, &vi);
vs = kipwr_ConfigureVoltageLevel (vi, “”, 20);
vs = kipwr_ConfigureCurrentLimit (vi, “”, KIPWR_VAL_CURRENT_REGULATE,
2.0);
vs = kipwr_ConfigureOutputEnabled (vi, “”, 1);
vs = kipwr_close (vi);
}
Memo
IVI instrument drivers for DC power supply units are usually structured in consider-
ation of multiple channels. Therefore, many of the device setting functions have the
ChannelName parameter.
Building projects
Executing Programs
This section introduces the breakpoints that are useful for debugging at the time of program
execution and explains how to run the program and the values stored in variables after
execution.
It is not clear how to execute the program of the sample on page 10 because it is not
interactive. Inserting a breakpoint in a recall line pauses the program before it is recalled so
that you can check the status of the program in progress.
1 Move the cursor to the row where you want to insert the breakpoint.
By executing a program
In the case of being able to open a session for an instrument driver, vi will store a session
handle (usually 0x00000001 or more as an IVI handle). The execution result (0x00000000
on success or a negative value on failure) will be stored in vs.
Explanation of functions
This section describes the functions comprising the program, including their contents and
setting values.
Memo
The IVI-C instrument driver and VXI Plug&Play instrument driver have the notation <pre-
fix> as a rule for function names. This notation represents the identification name of
each instrument driver.
For example, the notation “<prefix>_init()” is “kipwr_init()” in the kipwr instrument driver.
Starting sessions
Setting OptionString
In the case of power supplies and oscilloscopes, the IVI instrument drivers are designed
with the assumption that they are equipped with multiple channels. Therefore, many of the
driver functions that work on the instrument panel settings need to specify a channel for the
second parameter, as shown below:
In this example, a blank (“”) is specified as the channel name. If the number of channels is
one, a blank is fine, but if there are multiple channels, it needs to be specified explicitly.
The names of the channels that can be used depend on the instrument driver. For details,
see the help for each driver.
Closing sessions
vs = kipwr_close (vi);
Handling errors
Although no error correction has been done in the previous examples, the error_message
function can be used to convert a ViStatus-type return value into readable messages. The
error_message exceptionally accepts VI_NULL as ViSession. The receiving buffer size
should be 256 bytes or more.
char buf[256];
...
kipwr_error_message (VI_NULL, vs, buf);
Memo
• To utilize interchangeability, an IVI-C instrument driver of the same class of instru-
ment must be provided in response to both models before and after replacement.
Interchangeability between different classes of instrument is not available.
• In programming using the class interface, the machine-specific functions that are avail-
able are limited. To maximize the use of model-specific functions, program using the
specific interface (p.5).
Memo
To avoid loss of interchangeability function, do not include descriptions dependent on
specific IVI-C instrument drivers (e.g. direct calls to kipwr_init function) or specific VISA
addresses (resource names) (e.g. “TCPIP::192.168.1.5:: INSTR”) in the application
code.
In the IVI specifications, the interchangeability function is achieved by placing the IVI con-
figuration store outside the instrument drivers and applications. The application is not con-
trolled by using model-specific instrument drivers directly, but through a special instrument
driver, called the instrument class interface.
At the time of control, select the instrument driver DLLs according to the contents of the IVI
configuration store and access the instrument driver loaded indirectly through a model-inde-
pendent class interface function.
An XML file (C:/ProgramData/IVI Foundation/IVI/IviConfigurationStore.xml) will be used for
the IVI configuration store. Mainly IVI instrument drivers and some VISA/IVI configuration
tools access through the IVI Configuration Server DLL. Applications do not usually use it.
When using LabWindows/CVI, use the NI-MAX (NI Measurement and Automation Explorer)
software manufactured by National Instruments to configure the IVI driver.
This section describes the procedure of creating a virtual instrument using NI-MAX.
1 Launch NI-MAX and check the hierarchy under the [IVI Drivers] in the tree
display on the left of the screen.
In Hardware Asset, specify with what path the instruments to be used will be connected.
In the Software Module, the instrument driver module (DLL module) is set.
2 From the [Software Module] list, select the instrument driver module to be
used.
In this example, [kipwr] is selected.
With Virtual Name, a virtualized name is created for the channel name of the instrument
driver. This is because different instrument drivers have different valid channel names in the
case of instrument drivers requiring channel specification.
2 Click [Add] to add a virtual name and enter [Track_A] in [Virtual Name].
On the [Physical Name] list, the channel on which the instrument operates will be
displayed.
Memo
In some cases, not all channel names may be displayed, depending on the driver's
mounting conditions or the configuration of the multi-channel power supply unit. For
details on the names of the available channels for the driver, see the Readme doc-
ument for each driver or the online help.
A Logical Name refers to the name of a virtual instrument that is configured in NI-MAX.
1 Check the hierarchy under [IVI Drivers] in the tree display on the left side
of the screen.
5 Click [Save IVI Configuration] on the toolbar and save the settings.
1 Start LabWindows/CVI.
Welcome page is displayed.
5 Click [File] > [Save Untitled1.c As] to save the source file.
In this case, save it as “Ex02.c”.
Set the Initialize With Options function, declare the variables and insert them into the source
code.
As the parameters of Logical Name and OptionString are character strings, enclose
them in quotation marks.
Parameters Value
Logical Name “mySupply”
ID Query Yes (VI_TRUE in the function call description)
Reset Device Yes (VI_TRUE in the function call description)
Option String Leave as default.
Instrument Handle &vi
Status vs
Declaring variable
3 Check both the Execute declaration in Interactive Window and the Add
declaration to top of target file “Ex02.c”.
4 Click [OK].
Set the Close function in the same way as the Initialize With Options function, and insert
them into the source code.
By selecting [Ex02.c] tab, the source code will be displayed. By executing the steps in
pages 25 to 27, the source code will be as follows:
In order to make this source code an executable program, include the following content:
• Specify loading of the included file of the instrument driver.
• Set the initial values of the variables vi and vs at 0.
• Enclose the recall to InitWithOptions and close in the “main” function.
• Between the recalls to InitWithOptions and close, add a recall code for the function set-
ting the voltage and current, and the function controlling the output ON/OFF. Besides the
method of inserting it using the function panel, there is also the method of entering the
source code directly with the editor as shown below.
Shown below is a sample that opens an instrument driver session, sets voltage, current,
and output, and closes immediately.
#include <IviDCPwr.h>
static ViSession vi = 0;
static ViStatus vs = 0;
void main()
{
vs = IviDCPwr_InitWithOptions (“mySupply”, VI_TRUE, VI_TRUE,
“Simulate=0,RangeCheck=1,QueryInstrStatus=0,Cache=1”, &vi);
vs = IviDCPwr_ConfigureVoltageLevel (vi, “Track_A”, 20);
vs = IviDCPwr_ConfigureCurrentLimit (vi, “Track_A”, IVIDCPWR_VAL_CURRENT_
REGULATE, 2.0);
vs = IviDCPwr_ConfigureOutputEnabled (vi, “Track_A”, 1);
vs = IviDCPwr_close (vi);
}
Building projects
Executing Programs
This section introduces the breakpoints that are useful for debugging at the time of program
execution and explains how to run the program and the values stored in variables after
execution.
It is not clear how to execute the program of the sample on page 28 because it is not
interactive. Inserting a breakpoint in a recall line pauses the program before it is recalled so
that you can check the status of the program in progress.
1 Move the cursor to the row where you want to insert the breakpoint.
By executing a program
In the case of being able to open a session for an instrument driver, vi will store a session
handle (usually 0x00000001 or more as an IVI handle). The execution result (0x00000000
on success or a negative value on failure) will be stored in vs.
Explanation of functions
Functions that comprise the program are described with a case in which the IviDCPwr class
driver is used as an example. The prefix “IviDCPwr” attached to the VI (function) is unique
to the IviDCPwr class driver.
Starting sessions
Parameters Description
Logical Name Specify the logical name of the virtual instrument created with NI-MAX.
The class driver locates the appropriate instrument driver DLL (Software
Module) or VISA address (Hardware Asset) from the logical name and
recalls kipwr_InitWithOption indirectly at the end. The class driver can-
not provide a VISA address directly to the IviDCPwr_InitWithOptions
function.
ID Query In the case that VI_TRUE is specified, an ID query such as “*IDN?”
is issued in response to the instrument to make queries for model
information.
Reset Device In the case that VI_TRUE is specified, the “*RST” command is issued to
reset the settings of the instrument.
Option String The settings of the IVI definition can be changed. (p.13)
Vi Receive an instrument session (pointers passed).
Setting OptionString
In the case of power supplies and oscilloscopes, the IVI instrument drivers are designed
with the assumption that they are equipped with multiple channels. Therefore, many of the
driver functions that work on the instrument panel settings need to specify a channel for the
second parameter, as shown below:
In this example, “Track_A” is specified as the channel name. Track_A is the virtual name
that was set in IVI Configuration (p.17). By specifying a virtual name, programming can
be done independently of the instrument driver of a particular model.
In the IVI configuration, the virtual name “Track_A” has been configured so that it can be
converted to the channel name that can be used only by a specific instrument driver (in this
case, the kipwr driver) called “OutputChannel1”. Therefore, if the instrument is replaced, its
operation can be continued by simply changing the IVI configuration settings without having
to rewrite the program (p.34).
Instruments can be controlled by directly specifying channel names that are dependent on
the instrument driver, but interchangeability will be lost. For example, since the valid chan-
nel name for the AgN57xx instrument driver is “Output1”, if the channel name is specified as
“OutputChannel1”, the program must be rewritten in order to replace the instrument with the
AgN57xx.
Memo
• Do not manually edit the XML file (IviConfigurationStore.xml) in which the IVI configura-
tion information is saved.
• The IVI configuration will be shared by all 32-bit/64-bit measurement applications and
all logged-on users in the same PC.
Closing sessions
vs = IviDCPwr_close (vi);
Handling errors
Replacing instrument
When replacing the instrument, the operation can be continued by simply changing the
Driver Session of the virtual instrument (IVI configuration). There is no need to change the
application itself.
There are three Driver Session settings to be changed.
Item Settings
[Hardware] tab > [Hardware Assets] > VISA address to which the instrument is
[Resource Descriptor] connected
[Virtual Names] tab > [Physical Names] The physical name to which the virtual
channel name is mapped
If properly configured for the replaced instrument, the application can be operated without
having to recompile and link it again.
In the examples in this guide, if the instrument is replaced from a Kikusui PWR-01 series
DC power supply (instrument hosted by the kipwr instrument driver) to an Agilent N5700
series DC power supply (instrument hosted by the AgN57xx driver), the [mySupply] settings
should be changed as follows:
[Hardware] tab > [Hardware Assets] > VISA address to which the Kikusui
[Resource Descriptor] PWR-01 series DC power supply is
connected
=> VISA address to which Agilent N5700
series DC power supply is connected
Memo
The interchangeability function using IVI class drivers does not guarantee the operation
before and after replacement of the instrument. Be sure to fully verify that the replaced
system is functioning properly before operating it.