How to create a IVI driver object with logical name in Python?

39 views Asked by At

I'm using Python comtypes to get measurement device readings with IVI. We know that for the C-Sharp, there is funtion to create driver with logical name as following:

// Create an instance of the session factory
IIviSessionFactory factory = new IviSessionFactoryClass();
// Ask the session factory to create an instance of
// the appropriate driver based on a logical name
IIviScope iviscope = (IIviScope)factory.CreateDriver("MyLogicalName");

However, for Python comtypes, it seems we have to create a driver with the program ID directly. Also, we need to initialize the device with the resource name such as 'GPIB0::3::INSTR', so there will be no logical name involved in the case. Every time there should be two inputs for the users to fill in.

import comtypes
from comtypes.client import GetModule, CreateObject
from comtypes.gen import IviDmmLib
import pythonnet

GetModule("IviDmmTypeLib.dll")
ivi_dmm = IviDmmLib.IIviDmm.CreateDriver("AgDmm")

my_dmm = CreateObject("Agilent34410.Agilent34410", interface=IviDmmLib.IIviDmm)
# my_dmm = CreateObject("KeithleyDMM7510.KeithleyDMM7510", interface=IviDmmLib.IIviDmm)
# my_dmm = CreateObject("Ag3446x.Ag3446x", interface=IviDmmLib.IIviDmm)

my_dmm.Initialize('GPIB::3::INSTR',False,False,'Simulate=True')
print("Supported instrument models: '%s'" % my_dmm.Identity.SupportedInstrumentModels)
print("Vendor: '%s'" % my_dmm.Identity.Vendor)

my_dmm.configure(Function=IviDmmLib.IviDmmFunctionDCVolts, Range=1.0, Resolution=0.0001)

measured_value = my_dmm.measurement.read(1000)
print(measured_value)

So,

  1. Does anyone have a solution on this?
  2. Since the C-Sharp supports this, could we call the C-Sharp classes with 'pythonnet' package to implement this in python?

I tried to call .NET functions in python but didn't secceed. Does anyone have experience?

0

There are 0 answers