Add AI Reference
Add the AI Reference to your Project to connect with Bode 100
To be able to connect to your Bode 100 device you first have to add the Automation Interface reference to your project.
The Bode 100 Automation Interface uses the "OmicronLab.VectorNetworkAnalysis.AutomationInterface.dll" which can be found in the installation directory.
Note
You need to have the correct USB driver installed on your system. The simplest way to install the USB driver is to run our “Bode Analyzer Suite” installer available for download at OmicronLab
Instruction for adding references to various programming languages:
- Add Reference in C#
- Add Reference in MatLab
- Add Reference in Octave
- Add Reference in Python
- Add Reference in Excel
- Add Reference in Java
- Add Reference in Delphi
- Add Reference in Visual C++
- Add Reference in LabWindows CVI
Add Reference in C#
To access the OmicronLab.VectorNetworkAnalysis.AutomationInterface.dll in C# you need to add the reference to your project.
To install OmicronLab.VectorNetworkAnalysis.AutomationInterface NuGet package in Visual Studio 2012 or higher, run the following command in the Package Manager Console
PM> Install-Package OmicronLab.VectorNetworkAnalysis.AutomationInterface
After successfully adding the reference execute following code to gain access to the device and start a measurement.
//Include the usings
using OmicronLab.VectorNetworkAnalysis.AutomationInterface;
using OmicronLab.VectorNetworkAnalysis.AutomationInterface.Interfaces;
using OmicronLab.VectorNetworkAnalysis.AutomationInterface.Interfaces.Measurements;
using OmicronLab.VectorNetworkAnalysis.AutomationInterface.Enumerations;
using OmicronLab.VectorNetworkAnalysis.AutomationInterface.DataTypes;
//At first, create Bode100AutomationInterface object (this is a precondition for using Bode100 Automation Interface)
//Connect to bode, start measurement
BodeAutomationInterface auto = new BodeAutomation();
BodeDevice bode = auto.Connect();
//From the connected device you can now start with defining measurement type
S21Measurement s21Measurement = bode.Transmission.CreateS21Measurement();
//From the measurement type object you can now configure measurement sweep
s21Measurement.ConfigureSweep(100,100000,201,SweepMode.Linear);
//Execute the measurement
ExecutionState state = s21Measurement.ExecuteMeasurement();
//Control loop about the executed measurement
if(state != ExecutionState.Ok)
{
//Error
//Handle error
//shutdown Bode 100 if you abort the measurement.
//bode.Shutdown();
return;
}
//Get the results in a form of an e.g. array either as:
//Frequencies
double[] frequencies = s21Measurement.Results.MeasurementFrequencies;
//Db values or
double[] dbValues = s21Measurement.Results.Magnitude(MagnitudeUnit.dB);
//Phase values
double[] phase = s21Measurement.Results.Phase(AngleUnit.Degree);
//This is a very important part, always shut down the Bode100
bode.ShutDown();
Add Reference in MatLab
To add the Bode 100 reference in your MatLab project you have to perform the following steps:
automationInterface = actxserver('OmicronLab.VectorNetworkAnalysis.AutomationInterface');
bode = automationInterface.Connect();
s21 = bode.Transmission.CreateS21Measurement();
s21.ConfigureSweep(10,40000000, 201, 'SweepMode_Linear');
s21.ReceiverBandwidth = 'ReceiverBandwidth_kHz1';
state = s21.ExecuteMeasurement();
resultFrequency = s21.Results.MeasurementFrequencies;
resultMagnitude = s21.Results.Magnitude('MagnitudeUnit_dB');
resultPhase = s21.Results.Phase('AngleUnit_Degree');
figure
subplot(2,1,1)
plot(resultFrequency,resultMagnitude);
title('Gain')
xlabel('Frequency')
ylabel('Magnitude in dB')
subplot(2,1,2)
plot(resultFrequency, resultPhase);
xlabel('Frequency')
ylabel('Phase in degree')
% shut down
bode.ShutDown();
release(automationInterface);
Add Reference in Octave
Note
We focused some issues when using Octave's 'Clear' command (https://octave.sourceforge.io/octave/function/clear.html) in combination with COM. Therefore use the 'Clear' command with deliberation because it may lead to unexpected crashes.
To add the Bode 100 reference in your Octave project you have to perform the following steps:
%NOTE! Package required for COM support
pkg load windows;
automationInterface = actxserver('OmicronLab.VectorNetworkAnalysis.AutomationInterface');
bode = automationInterface.Connect();
%Constants
points = 201;
%NOTE! In Octave it is NOT possible to set Enums as their Name. We have to set them as numbers.
sweepMode_Linear = 0;
%NOTE! Custom Receiver Bandwidth values are in Milli Hz. -> Since we define a constat here this value has to be in Milli Hz [mHz]
receiverBandwidth_kHz1 = 1000000;
magnitudeUnit_dB = 0;
angleUnit_Degree = 1;
s21 = bode.Transmission.CreateS21Measurement();
s21.ConfigureSweep(10,40000000, points, sweepMode_Linear);
s21.ReceiverBandwidth = receiverBandwidth_kHz1;
state = s21.ExecuteMeasurement();
resultFrequency = zeros(1,points);
resultMagnitude = zeros(1,points);
resultPhase = zeros(1,points);
for j = 1:points
resultFrequency(j) = s21.Results.MeasurementFrequencyAt(j - 1);
resultMagnitude(j) = s21.Results.MagnitudeAt(j - 1, magnitudeUnit_dB);
resultPhase(j) = s21.Results.PhaseAt(j - 1, angleUnit_Degree);
end
figure
subplot(2,1,1)
plot(resultFrequency,resultMagnitude);
title('Gain')
xlabel('Frequency')
ylabel('Magnitude in dB')
subplot(2,1,2)
plot(resultFrequency, resultPhase);
xlabel('Frequency')
ylabel('Phase in degree')
% shut down
bode.ShutDown();
release(automationInterface);
Add Reference in Python
To add the Bode 100 reference in your Python project you have to perform the following steps:
import win32com.client
#Constants
#In Python it is not possible to set Enums as their Name. We have to set them as numbers.
SweepMode_Linear = 0
#NOTE! Custom Receiver Bandwidth values are in Milli Hz. -> Since we define a constat here this value has to be in Milli Hz [mHz]
ReceiverBandwidth_kHz1 = 1000000;
def Init():
automationInterface = win32com.client.Dispatch("OmicronLab.VectorNetworkAnalysis.AutomationInterface")
bode = automationInterface.Connect()
s21 = bode.Transmission.CreateS21Measurement()
s21.ConfigureSweep(10, 40000000, 201, SweepMode_Linear)
s21.ReceiverBandwidth = ReceiverBandwidth_kHz1
state = s21.ExecuteMeasurement()
if state == 0:
print ("Execution State is OK!")
else:
print ("An error happened!")
print ("\nResults:\n")
fequs = s21.Results.MeasurementFrequencies;
vals = s21.Results.ComplexValues();
for x in range(0, s21.Results.Count):
com = vals[x]
val = com.MagnitudeDB
phase = com.Phase
print ("Frequency: " + str(fequs[x]) + " Value: " + str(val) + " Phase: " + str(phase))
bode.ShutDown()
if __name__ == "__main__":
Init()
Add Reference in Excel
Note
To add the Bode 100 reference in your Excel project be sure that you Enabled Macros in Excel
Open the Visual Basic (for applications) Editor and navigate through the following pages:
Open reference dialogue
Select the AI Reference
Click OK.
After successfully adding the reference execute following code to gain access to the device.
Sub Init()
Dim ai As BodeAutomation
Set ai = New BodeAutomation
Dim bode As Bode100
Set bode = ai.Connect()
Dim meas As S21Measurement
Set meas = bode.Transmission.CreateS21Measurement()
meas.ConfigureSweep 10, 40000000, 201, SweepMode_Logarithmic
meas.ReceiverBandwidth = ReceiverBandwidth_kHz1
State = meas.ExecuteMeasurement
MsgBox "Status: " & State & " Count: " & meas.Results.Count
bode.ShutDown
End Sub
Add Reference in Java
To access the OmicronLab.VectorNetworkAnalysis.AutomationInterface.dll you need a Java COM Bridge like Com4j that allows
you to call COM Automation components from Java.
Generate Java definitions from a type library using tlbimp.jar (included in com4j-package). In the command line navigate to tlbimp.jar and execute the following command:
java -jar tlbimp.jar -o outputFolder -p namespace /pathToInstallationFolder/OmicronLab.VectorNetworkAnalysis.AutomationInterface.tlbParameter Description:
namespace ... the namespace of the generated definitions
outputFolder ... the folder where the generated definitions shall be saved
pathToInstallationFolder ... the path to the installation folder of the Bode 100 software- Copy the generated definitions to your project folder.
- Add the com4j.jar library to your project.
Then it is possible to connect to the Bode 100 as follows:
import omicronLab.VectorNetworkAnalysis;
import omicronLab.BodeAutomationInterface;
import omicronLab.ClassFactory;
import omicronLab.DoubleResults;
import omicronLab.ExecutionState;
import omicronLab.MagnitudeUnit;
import omicronLab.S21Measurement;
import omicronLab.SweepMode;
public class AutomationInterface {
public static void main(String[] args) {
BodeAutomationInterface ff = ClassFactory.createBodeAutomation();
BodeDevice bode = ff.connect();
S21Measurement mm = bode.transmission().createS21Measurement();
mm.configureSweep(1000, 100000, 201, SweepMode.SweepMode_Linear);
ExecutionState state = mm.executeMeasurement();
if (state != ExecutionState.ExecutionState_Ok) {
System.out.println("Error");
//Shutdown the Bode device if you abort the measurement.
//bode.shutDown();
return;
}
double[] res = mm.results().magnitude(MagnitudeUnit.MagnitudeUnit_dB);
double[] frequencies = mm.results().MeasurementFrequencies;
for (int i = 0; i < res.count(); i++) {
System.out.println(String.format("Value: %s , Frequency: %s", res[i], frequencies[i]));
}
bode.ShutDown();
}
}
Note
To access the result values and the frequency we use index based functions (valueAt(index) and frequncyAt(index)).
This is required due to an issue in COM4J. It is not possible to read the whole array back.
In the example above "omicronLab" is the namespace chosen in step 1.
Add Reference in Delphi
- Create new Delphi Project in Embarcadero RAD Studio 10.2.
Click on "Component" -> "Import Component"
Select "Import a Type Library"
Search and Select "Automation Interface for the OMICRON Lab Vector Network Analysis Devices"
Select Platte Page: ActiveX
Install the component to an existing or a new package or add the unit directly to the project.
After this you have successfully added the reference to your project.
Important
To be able to use the references you have to insert "OmicronLab_VectorNetworkAnalysis_AutomationInterface_TLB" (if not already done by the "Import Component" wizard) and "ActiveX" into the "uses" block at the beginning of your code.
program BodeAIExample;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
ActiveX,
OmicronLab_VectorNetworkAnalysis_AutomationInterface_TLB in '..\Imports\OmicronLab_VectorNetworkAnalysis_AutomationInterface_TLB.pas';
var
ai : BodeAutomationInterface;
bode : BodeDevice;
s21 : S21Measurement;
LB : integer;
UB : integer;
index : integer;
mag : double;
freq : double;
continue : string;
begin
try
ai := CoBodeAutomation.Create;
bode := ai.Connect();
s21 := bode.Transmission.CreateS21Measurement();
s21.ConfigureSweep(10,1000,201,SweepMode_Linear);
s21.ReceiverBandwidth := ReceiverBandwidth_kHz1;
s21.ExecuteMeasurement();
SafeArrayGetLBound(s21.Results.Magnitude(MagnitudeUnit_dB), 1, LB);
SafeArrayGetUBound(s21.Results.Magnitude(MagnitudeUnit_dB), 1, UB);
// Write results to console
for index := LB to UB do
begin
SafeArrayGetElement(s21.Results.Magnitude(MagnitudeUnit_dB), index, mag);
SafeArrayGetElement(s21.Results.MeasurementFrequencies, index, freq);
Writeln('Magnitude: ', mag, ' dB', ' @', freq, ' Hz' );
end;
bode.ShutDown();
WriteLn('Press ENTER to continue ...');
ReadLn(continue);
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.
Note
At the line "ai := CoBodeAutomation.Create;", pay attention to the "Co" in the beginning. This is a naming convention from Delphi and is mandatory to create an instance of the automation interface.
Add Reference in Visual C++
Note
The AutomationInterface is only comatible to Visual Studio 2012 or higher versions.
How to perform measurements in Visual C++:
- Create a new Visual C++ project in Visual Studio 2015 (2012 or higher). (Similar in other Versions)
In the Solution Explorer right click on the project and select Properties.
Navigate to "Configuration Properties" -> "C/C++" -> "General". Check if the "Common Language RunnTime Support" is set to "/clr". Next you may have to change some other settings, depending on your default settings. Visual Studio will tell you what to do when you try to build the project.
Now we have to change the .net Framework version. Since this is not possible in the settings we have to change it in the project configuration file. Therefore unload the project by right clicking on the project and select "Unload Project".
Now right click the unloaded project and select "Edit BodeExample.vcxproj" (BodeExample is the project name)
Locate the tag
<PropertyGroup Label="Globals">
there INSERT the tag:<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
Now save it (Ctrl + S) then again right click on the project and select "Reload Project".
- Add the OmiconLab.VectorNetworkAnalysis.AutomationInterface.dll reference to the project.
- Now you are ready to implement your measurement.
Note
In case of errors:
- First we’ll tell the C++ compiler that we want to use Clr: Project->Properties->Configuration Properties->C/C++->General->Common Language RunTime Support = “Common Language RunTime Support (/clr)”
- These are errors which can be fixed by changing the properties: cl : Command line error D8016: '/ZI' and '/clr' command-line options are incompatible
- Project->Properties->Configuration Properties->C/C++->General->Debug Information Format: Program Database (/Zi) cl : Command line error D8016: '/clr' and '/Gm' command-line options are incompatible
- Project->Properties->Configuration Properties->C/C++->Code Generation->Enable Minimal Rebuild: No cl : Command line error D8016: '/clr' and '/EHs' command-line options are incompatible
- Project->Properties->Configuration Properties->C/C++->Code Generation->Enable C++ Exceptions: Yes with SEH Exceptions (/EHa) cl : Command line error D8016: '/clr' and '/RTC1' command-line options are incompatible
- Project->Properties->Configuration Properties->C/C++->Code Generation->Basic Runtime Checks: Default
However, if the project file thinks this is not a CLR project, so the Framework assemblies don’t show in the Add ref dialog.
We can fix that: Right Click on the CppClr Project node in the Solution Explorer->Unload Project.
Then Right Click ->Edit CppClr.vcxproj
That opens the file in the editor.
Add the line <CLRSupport>true</CLRSupport>
to each configuration(Debug and Release) as shown below:
Source:
https://blogs.msdn.microsoft.com/calvin_hsia/2013/08/30/call-managed-code-from-your-c-code/
Performing a measurement:
#include "stdafx.h"
#include <iostream>
using namespace OmicronLab::VectorNetworkAnalysis::AutomationInterface;
using namespace OmicronLab::VectorNetworkAnalysis::AutomationInterface::Interfaces;
using namespace OmicronLab::VectorNetworkAnalysis::AutomationInterface::Interfaces::Measurements;
using namespace OmicronLab::VectorNetworkAnalysis::AutomationInterface::Enumerations;
using namespace OmicronLab::VectorNetworkAnalysis::AutomationInterface::DataTypes;
int _tmain(int argc, _TCHAR* argv[])
{
BodeAutomation ^ automation = gcnew BodeAutomation();
BodeDevice ^ bode = automation -> Connect();
S21Measurement ^ s21 = bode->Transmission->CreateS21Measurement();
s21->ConfigureSweep(10, 1000, 201, SweepMode::Linear);
s21->ReceiverBandwidth = ReceiverBandwidth::kHz1;
ExecutionState state = s21->ExecuteMeasurement();
for (int i = 0; i < s21->Results->Magnitude(MagnitudeUnit::dB)->Length; i++)
{
std::cout << s21->Results->Magnitude(MagnitudeUnit::dB)[i];
std::cout << "\n";
}
bode->ShutDown();
return 0;
}
Add Reference in LabWindows CVI
How to perform measurements in LabWindows CVI:
- Create a new Project in LabWindows/CVI 2013
Navigate to "Tools -> Create ActiveX Controller"
Click "Next". In the following windows select the AutomationInterface reference.
Again click Next. Select an "Instrument Prefix" in this case "OmicronAI" and Select a "Target .fp File" (Click Browse to create new file, in this example "AutomationInterface.fp").
Click "Next" until the window closes. Now LabWindows/CVI generates a "AutomationInterface.fp", "AutomationInterface.c" and "AutomationInterface.h" file.
Right click the project to add a new File.
Select "Source File", a "File name" and a "File folder".
Click ok. Now you are able to implement your measurement in the generated source file.
Implement a measurement with the following code:
// Title: AutomationInterfaceExample.c
// Include files
#include "AutomationInterface.h"
#include <ansi_c.h>
static CAObjHandle automationInterface = 0;
static OmicronAIObj_BodeDevice bodeHandle = 0;
static OmicronAIObj_Transmission transmissionHandle = 0;
static OmicronAIObj_S21Measurement s21Handle = 0;
static enum OmicronAIEnum_ExecutionState state = 0;
static OmicronAIObj_GainResults gainResultHandle = 0;
static ERRORINFO ErrorInfo;
int main(int argc, char *argv[])
{
HRESULT error = 0;
SAFEARRAY* magnitudes;
double *arrMagnitudes;
int i = 0;
int x = 0;
int count = 201;
error = OmicronAI_NewBodeAutomation_Object(NULL, 1, LOCALE_NEUTRAL, 0, &automationInterface);
error = OmicronAI_BodeAutomationInterfaceConnect(automationInterface, &ErrorInfo, &bodeHandle);
error = OmicronAI_BodeDeviceGetTransmission(bodeHandle, &ErrorInfo, &transmissionHandle);
error = OmicronAI_TransmissionCreateS21Measurement(transmissionHandle, &ErrorInfo, &s21Handle);
error = OmicronAI_S21MeasurementConfigureSweep(s21Handle, &ErrorInfo, 100, 10000, count, OmicronAIConst_SweepMode_Linear);
error = OmicronAI_S21MeasurementSetReceiverBandwidth(s21Handle, &ErrorInfo, OmicronAIConst_ReceiverBandwidth_kHz1);
error = OmicronAI_S21MeasurementExecuteMeasurement(s21Handle, &ErrorInfo, &state);
error = OmicronAI_S21MeasurementGetResults(s21Handle, &ErrorInfo, &gainResultHandle);
error = OmicronAI_GainResultsMagnitude(gainResultHandle, &ErrorInfo, OmicronAIConst_MagnitudeUnit_dB, &magnitudes);
arrMagnitudes = (double*)magnitudes->pvData;
for(i; i < count; i++)
{
printf("Magnitude Value: %f\n", arrMagnitudes[i]);
}
error = OmicronAI_BodeDeviceShutDown(bodeHandle, &ErrorInfo);
scanf("Press any key to close: %d",&x);
}
Note
OmicronAI_ is the selected Instrument Prefix.
Note
Principially it is also possible to create a .NET Controller instead of the previously explained ActiveX Controller. Following that approach one needs to consider:
- LabWindows/CVI 2013 is not supported. We tested the basic functionality with LabWindows/CVI 2017.
- The Bode Automation Interface assembly "OmicronLab.VectorNetworkAnalysis.AutomationInterface.dll" needs to be specified by path because it is not registered in the Global Assembly Cache.
- The function panels will not be generated for all items (because of too long CVI identifiers).
- Be sure that all Source-dlls from the Bode Automation Interface installation folder are copied to your CVI project folder.