Add Reference in Python
To add the Bode 100 reference in your Python project you have to perform the following steps:
import pythoncom
import win32com.client
import pywintypes
#Constants
#In Python it is not possible to set Enums as their Name. We have to set them as numbers.
#For Linear Sweep use '0'
SweepMode_Linear = 0
#For Logarithmic Sweep use '1'
SweepMode_Log = 1
#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():
automationInterfaceUnk = pythoncom.CoCreateInstance(pywintypes.IID('OmicronLab.VectorNetworkAnalysis.AutomationInterface'), None, pythoncom.CLSCTX_ALL, pythoncom.IID_IUnknown)
automationInterface = win32com.client.Dispatch(automationInterfaceUnk.QueryInterface(pythoncom.IID_IDispatch))
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()
Important
Accessing the Bode Automation Interface from Python has slightly changed. Using 'Dispatch' directly on the 'ProgId' no longer works. The reason for this is that, the way COM wrappers work in .NET 6 has changed. Instead 'CoCreateInstance' has to be used first and then 'Dispatch' can be used as seen in the code above. Using COM is not recommended for new developments. We recommend using the SCPI interface.