Documente Academic
Documente Profesional
Documente Cultură
The IVI Configuration Store holds information about IVI drivers installed on the
computer and configuration information for an instrument system. If you installed
the IVI Shared Components in the default location, you can find the configuration
information in a file named IviConfigurationStore.xml in C:\Program Files\IVI\Data.
Recent versions of Microsoft Internet Explorer can display xml files. If you double-
click on the file, a copy of Internet Explorer should start and show the contents of
the file.
You can use IVI drivers successfully, accessing their capabilities, without ever using
the Configuration Store. If, however, you want to use the IVI Session Factory or use
a Logical Name instead of a Resource Descriptor you must make some entries into
the Configuration Store. A HardwareAsset allows you to assign a name to a resource
descriptor. A DriverSession collects a specific driver, through a SoftwareModule, a
HardwareAsset, and initialization information all under one name. If you have
installed one or more IVI drivers, their information appears in the SoftwareModules.
A LogicalName allows a further abstraction for a Session with its own name. By
adding these three elements to a Configuration Store you can create and reference
an IVI driver using the names in the Configuration Store.
One of the COM servers supplied with the IVI Shared Components is the IVI
Configuration Server. It provides a safe, reliable means to modify the contents of the
Configuration Store. While you could edit the xml contents in a number of editors,
accessing the file with the Configuration Server guarantees that the contents are
valid xml, adhere to the schema in IviConfigurationStore.xsd, and comply with
other IVI rules.
The following instructions were validated for Visual Basic in Visual Studio 2005.
Adding a Reference
Before using any COM server in Visual Basic, you must add a reference to it. Under
the Project menu, select Add References. Select the COM tab. In the list of “Available
References,” scroll down to “Ivi Configuration Server 1.0 Type Library”. Select to
highlight it and hit OK.
IVI Configuration Store White Paper November 2006
The MasterLocation property contains the complete path to the master file. The
Deserialize method reads the file into memory while validating its contents. If
something is wrong with the contents, the Configuration Server throws an error. You
can trap the error with code like:
On Error GoTo DeserializeError
cs.Deserialize (cs.MasterLocation)
On Error GoTo 0
. . .
Adding a HardwareAsset
One of the objects you can add is a HardwareAsset. It contains address information
about an actual instrument in the system. This code creates the object and sets its
properties:
The next step is to add this object to the Configuration Store loaded into memory.
2 of 11
IVI Configuration Store White Paper November 2006
Since HardwareAsset names must be unique, the Configuration Server will throw an
error if you try to add one with the same name as one already in the HardwareAssets
collection. If the Add method succeeds, this HardwareAsset would appear in the xml
as:
<HardwareAssets>
<IviHardwareAsset id="p28">
<Name>Agilent34401</Name>
<Description>Multimeter connected to the switch</Description>
<DataComponents />
<IOResourceDescriptor>GPIB::22::INSTR</IOResourceDescriptor>
</IviHardwareAsset>
</HardwareAssets>
Adding a DriverSession
Another object you can add is a DriverSession. It contains information used by the
IVI Session Factory to create an instance of an IVI-COM driver. Data in a
DriverSession object is also used by the Initialize function. You could create an
instance and set its properties using:
' Create the Session and fill in the DriverSession object properties
Dim ds As New Ivi.ConfigServer.Interop.IviDriverSession
ds.Name = “Agilent34401”
ds.Description = “DriverSession for the system multimeter”
ds.Cache = True
ds.InterchangeCheck = False
ds.QueryInstrStatus = False
ds.RangeCheck = True
ds.RecordCoercions = False
ds.Simulate = False
ds.DriverSetup = “”
3 of 11
IVI Configuration Store White Paper November 2006
The next step is to add this object to the Configuration Store loaded into memory.
<DriverSessions>
<IviDriverSession id="p30">
<Name>Agilent34401</Name>
<Description>DriverSession for the system multimeter</Description>
<DataComponents />
<IviHardwareAsset idref="p28" />
<IviSoftwareModuleRef idref="p8" />
<VirtualNames />
<SoftwareModuleName>Agilent34401</SoftwareModuleName>
<Cache>1</Cache>
<DriverSetup />
<InterchangeCheck>0</InterchangeCheck>
<QueryInstrStatus>0</QueryInstrStatus>
<RangeCheck>1</RangeCheck>
<RecordCoercions>0</RecordCoercions>
<Simulate>0</Simulate>
</IviDriverSession>
</DriverSession>
4 of 11
IVI Configuration Store White Paper November 2006
Adding a LogicalName
The final object we’ll add is a LogicalName. It allows an additional level of abstraction
from an actual instrument. While a DriverSession must contain information about a
specific instrument in the system, a LogicalName does not. A LogicalName can be
easily re-configured to reference a different DriverSession and thus a different
physical instrument.
The Name and Description properties are again similar to those in a HardwareAsset
or DriverSession. The Name must be unique among all the LogicalNames.
If the Add succeeds, the LogicalName entry would appear in the xml as:
<LogicalNames>
<IviLogicalName id="p32">
<Name>DMM</Name>
<Description>The name used in the test program</Description>
<IviDriverSession idref="p29" />
</IviLogicalName>
</LogicalNames>
5 of 11
IVI Configuration Store White Paper November 2006
This code writes to the path contained in the MasterLocation property and thus
overwrites the file we read earlier. As with any write operation to a file, something
can go wrong which causes the Configuration Server to throw an error. You can
handle the error with code like:
Removing Objects
Sometime you will need to remove an object. The objects we added can be deleted
by using the Remove method on the various collections. To remove the LogicalName
added by this example you could use:
If you attempt to remove an object which does not exist, the Configuration Server
will throw an error. A HardwareAsset or DriverSession can be removed using similar
code.
Complete Program
The various code snippets can be combined into a complete subroutine. A more
elegant program would not hard code the values for the properties, but extract them
from user entered data.
' Create the Session and fill in the DriverSession object properties
Dim ds As New Ivi.ConfigServer.Interop.IviDriverSession
6 of 11
IVI Configuration Store White Paper November 2006
ds.Name = "Agilent34401"
ds.Description = "DriverSession for the system multimeter"
ds.Cache = True
ds.InterchangeCheck = False
ds.QueryInstrStatus = False
ds.RangeCheck = True
ds.RecordCoercions = False
ds.Simulate = False
ds.DriverSetup = ""
Exit Sub
7 of 11
IVI Configuration Store White Paper November 2006
To use the Session Factory in Visual Basic you add a reference to “IviSessionFactory
1.0 Type Library” as we added a reference to the Configuration Server. You also
need a reference to any IVI Instrument Class used in the program. In this example,
we need a reference to “IviDmm 3.0 Type Library”. Assuming the Configuration
Store contains the information from this example, we can use the Session Factory
with this code:
The CreateDriver method looks up the name “DMM” in the LogicalNames collection.
If it finds one, it uses the DriverSession referenced by the LogicalName. If the name
does not exist in LogicalNames, it next searches the DriverSessions collection for the
name. If the name is found, that DriverSession is used. If the name is not found in
either collection, the Session Factory throws an error. The SoftwareModule,
referenced by the DriverSession contains a property, ProgID, which the Session
Factory uses to create an instance of the Agilent34401 IVI-COM driver.
The same name is passed as a parameter to the Initialize method. The driver is
required to also look up “DMM” in the Configuration Store to retrieve information for
8 of 11
IVI Configuration Store White Paper November 2006
this particular instance of the driver. It uses the referenced HardwareAsset to get an
address for the instrument.
Notice that “Agilent34401” does not appear anywhere in the code. All the information
needed to create and initialize the driver is contained in the Configuration Store.
Additional Considerations
The Configuration Store and Server have additional capabilities beyond those
illustrated in these examples. Those capabilities include:
4. Using a Configuration Store other than the one in the Master Location.
While these topics are beyond the scope of this paper, you can consult the IVI
specification, “IVI-3.5: Configuration Server Specification,” available from
http://www.ivifoundation.org/Downloads/Specifications.htm for more details.
#include "stdafx.h"
#import "IviConfigServer.dll"
using namespace IVICONFIGSERVERLib;
9 of 11
IVI Configuration Store White Paper November 2006
cs->HardwareAssets->Add(ha);
} catch (_com_error e) {
printf("Add HardwareAsset failed.\n");
printf("Error description is: %s\n",(char*)e.Description());
}
try{
// Create an empty DriverSession
IIviDriverSessionPtr ds(__uuidof(IviDriverSession));
// Set its properties
ds->Name = _bstr_t("Agilent34401");
ds->Description = _bstr_t("DriverSession for the system multimeter");
ds->Cache = true;
ds->InterchangeCheck = false;
ds->QueryInstrStatus = false;
ds->RangeCheck = true;
ds->RecordCoercions = false;
ds->Simulate = false;
ds->DriverSetup = _bstr_t("");
// Add the HardwareAsset reference to the Session
ds->HardwareAsset = cs->HardwareAssets->Item["Agilent34401"];
// Add the SoftwareModule reference to the Session.
ds->SoftwareModule = cs->SoftwareModules->Item["Agilent34401"];
// Add it to the global driver session collection
cs->DriverSessions->Add(ds);
} catch (_com_error e) {
printf("Add DriverSession failed.\n");
printf("Error description is: %s\n",(char*)e.Description());
}
try{
// Create the Logical Name
IIviLogicalNamePtr ln(__uuidof(IviLogicalName));
// Set its properties
ln->Name = _bstr_t("DMM");
ln->Description = _bstr_t("The name used in the test program");
ln->Session = cs->Sessions->Item["Agilent34401"];
// Add it to the global logical name collection
cs->LogicalNames->Add(ln);
} catch (_com_error e) {
printf("Add LogicalName failed.\n");
printf("Error description is: %s\n",(char*)e.Description());
}
// Overwrite the master with the modified configuration store
try{
cs->Serialize(cs->MasterLocation);
} catch (_com_error e) {
printf("Serialize failed.\n");
printf("Error description is: %s\n",(char*)e.Description());
}
} catch (_com_error e) {
printf("Deserialize failed.\n");
printf("Error description is: %s\n",(char*)e.Description());
}
}
CoUninitialize();
return 0;
}
10 of 11
IVI Configuration Store White Paper November 2006
#if !defined(AFX_STDAFX_H__BA321FE9_D24E_4427_9B74_648FCE4FD9DF__INCLUDED_)
#define AFX_STDAFX_H__BA321FE9_D24E_4427_9B74_648FCE4FD9DF__INCLUDED_
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0400
#endif
#include <stdio.h>
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before
the previous line.
#endif //
!defined(AFX_STDAFX_H__BA321FE9_D24E_4427_9B74_648FCE4FD9DF__INCLUDED_)
Product and company names mentioned herein are trademarks or trade names of their respective
companies.
Microsoft, Internet Explorer, Visual Basic, and Visual C++ are either registered trademarks or trademarks
of Microsoft Corporation in the United States and/or other countries.
11 of 11