[IronPython] IronPython and COM object useage

Wim De Kimpe wim at 3win.be
Mon Mar 16 10:17:12 CET 2009

Hi all


Not sure if this is the right forum, but I ask my question anyway.


I would like to use IronPython for creating a hardware testing environment,
consisting of a "Device Under Test"  and some

measurement equipment like  a lab power supply and voltage meter and things
like that.

These instruments come with a library which enables communication  via USB
or GPIB.  I have been using them in 

VBA for Excel, C# and VB.Net.  Now when I try to do the same in IronPython,
I do not seem to get it to work.


I have copied the Interop assembly dll's from my example C# program into a
separate directory, and then try to do the same 

steps as I do in the example.  Here's the C# example :


using System;

using Agilent.AgilentU2741A.Interop;


namespace Example1


      /// <summary>

      /// Agilent IVI-COM Driver Example Program


      /// Creates a driver object, reads a few Identity interface

      /// properties, and checks the instrument error queue.

      /// May include additional instrument specific functionality.


      /// Runs in simulation mode without an instrument.


      /// Requires a COM reference to the driver's type library.


      /// </summary>

      public class App



            public static void Main(string[] args) 


                  Agilent.AgilentU2741A.Interop.AgilentU2741A driver = null;




                        // Create driver instance

                        driver = new


                        // Setup VISA resource descriptor.  Ignored if

                        string resourceDesc =

                        // Setup IVI-defined initialization options

                        string standardInitOptions = 

                              "QueryInstrStatus=true, Simulate=true";

                        // Setup driver-specific initialization options

                        string driverSetupOptions = 

                              "DriverSetup= Model=, Trace=false";


                        driver.Initialize(resourceDesc, false, true,
standardInitOptions + "," + driverSetupOptions);

                        Console.WriteLine("  Driver Initialized");


                        // IIviDriverIdentity properties - Initialize

                        string instModel = driver.Identity.InstrumentModel;

                        Console.WriteLine("InstrumentModel: {0}",


                        string instFirmwareRevision =

                        Console.WriteLine("InstrumentFirmwareRevision: {0}",


                        string instManufacturer =

                        Console.WriteLine("InstrumentManufacturer: {0}\n",



                        // TODO: Exercise driver methods and properties



                        // Check instrument for errors

                        int errorNum = -1;

                        string errorMsg = null;


                        while (errorNum != 0)


                              driver.Utility.ErrorQuery(ref errorNum, ref

                              Console.WriteLine("ErrorQuery: {0}, {1}",
errorNum, errorMsg);



                  catch (Exception ex)






                        if (driver != null && driver.Initialized)


                              // Close driver


                              Console.WriteLine("  Driver Closed");




                  Console.WriteLine("\nDone - Press Enter to Exit");







Here is what I try to do in Ironpython :


>>> import sys

>>> import clr

>>> clr.AddReferenceToFile("Agilent.AgilentU2741A.Interop.dll")

>>> from Agilent.AgilentU2741A.Interop import *

>>> a = AgilentU2741AClass()

>>> a

<Agilent.AgilentU2741A.Interop.AgilentU2741AClass object at

>>> dir(a)

['AC', 'ACCurrent', 'ACVoltage', 'Abort', 'ActualRange', 'Advanced',
'Alpha', 'A

pertureTime', 'ApertureTimeUnits', 'AutoRange', 'AutoZero', 'Cache',

n', 'Clear', 'ClearInterchangeWarnings', 'Close', 'Code', 'Configure',

eBandwidth', 'ConfigureServiceRequest', 'ConfigureSynchronization',

, 'Count', 'CreateObjRef', 'DCCurrent', 'DCVoltage', 'Delay', 'Description',

ode', 'DirectIO', 'Disable', 'DriverOperation', 'DriverSetup', 'Equals',

uery', 'FResistance', 'Fetch', 'FetchMultiPoint', 'FixedRefJunction',

', 'FrequencyMax', 'FrequencyMin', 'Function', 'GeographicalAddress',

de', 'GetLifetimeService', 'GetNextCoercionRecord',

 'GetType', 'GroupCapabilities', 'IAgilentU2741AACVoltage_AutoRange',

2741AACVoltage_Configure', 'IAgilentU2741AACVoltage_Measure',

oltage_Range', 'IAgilentU2741AContinuity_Configure',

easure', 'IAgilentU2741ADCCurrent_AutoRange',

, 'IAgilentU2741ADCCurrent_Range', 'IAgilentU2741ADCVoltage_AutoRange',

tU2741ADCVoltage_AutoZero', 'IAgilentU2741ADCVoltage_Configure',

DCVoltage_Measure', 'IAgilentU2741ADCVoltage_NPLC',

ge', 'IAgilentU2741ADCVoltage_Resolution', 'IAgilentU2741ADiode_Configure',

ilentU2741ADiode_Measure', 'IAgilentU2741AFResistance_AutoRange',

AFResistance_AutoZero', 'IAgilentU2741AFResistance_Configure',

esistance_Measure', 'IAgilentU2741AFResistance_NPLC',

_Range', 'IAgilentU2741AFResistance_Resolution',

ure', 'IAgilentU2741AFrequency_Measure',
'IAgilentU2741AResistance_AutoRange', '

IAgilentU2741AResistance_AutoZero', 'IAgilentU2741AResistance_Configure',

entU2741AResistance_Measure', 'IAgilentU2741AResistance_NPLC',

sistance_Range', 'IAgilentU2741AResistance_Resolution',

escription', 'IIviComponentIdentity_Revision',
'IIviComponentIdentity_Vendor', '

IIviDmmAdvanced_ActualRange', 'IIviDmmAdvanced_ApertureTime',

pertureTimeUnits', 'IIviDmmAdvanced_AutoZero',

cy', 'IIviDmmMeasurement_Abort', 'IIviDmmMeasurement_Fetch',

_Initiate', 'IIviDmmMeasurement_IsOverRange', 'IIviDmmMeasurement_Read',

mMeasurement_SendSoftwareTrigger', 'IIviDmmMultiPoint_Count',

ure', 'IIviDmmRTD_Resistance', 'IIviDmmThermistor_Resistance',

lope', 'IIviDmmTrigger_Source', 'IIviDmm_Advanced', 'IIviDmm_Close',

iverOperation', 'IIviDmm_Frequency', 'IIviDmm_Function', 'IIviDmm_Identity',

viDmm_Initialize', 'IIviDmm_Initialized', 'IIviDmm_Measurement',

, 'IIviDmm_Resolution', 'IIviDmm_Temperature', 'IIviDmm_Trigger',

ty', 'IIviDriver_Close', 'IIviDriver_DriverOperation',
'IIviDriver_Identity', 'I

IviDriver_Initialize', 'IIviDriver_Initialized', 'IIviDriver_Utility',

er', 'Identity', 'Initialize', 'InitializeLifetimeService', 'Initialized',

iate', 'InstrumentFirmwareRevision', 'InstrumentManufacturer',

, 'InterchangeCheck', 'InvalidateAllAttributes', 'IoResourceDescriptor',

Range', 'LockObject', 'LogicalName', 'Measure', 'Measurement',

ete', 'MemberwiseClone', 'Message', 'MultiPoint', 'NPLC',

', 'PerformCalibration', 'PowerlineFrequency', 'Preset',

, 'RTD', 'Range', 'RangeCheck', 'Read', 'ReadMultiPoint', 'ReadingUnits',

dCoercions', 'RefJunctionType', 'ReferenceEquals', 'Register', 'Reset',

librationCode', 'ResetInterchangeCheck', 'ResetWithDefaults', 'Resistance',

olution', 'Revision', 'SampleCount', 'SampleInterval', 'SampleTrigger',

yEnable', 'SecurityState', 'SelfTest', 'SendSoftwareTrigger',
'SerialNumber', 'S

erialPoll', 'Simulate', 'Slope', 'Source', 'SpecificationMajorVersion',

cationMinorVersion', 'Status', 'StoreCalibrationConstants',

Models', 'SynchronizationBusLine', 'SynchronizationState', 'System',

e', 'Thermistor', 'Thermocouple', 'TimeoutMilliseconds', 'ToString',

Type', 'Trigger', 'Type', 'UnitTemperature', 'UnlockObject', 'Utility',

 'Vendor', 'VoltageRange', 'WaitForOperationComplete', '__class__',

', '__doc__', '__getattribute__', '__hash__', '__init__', '__new__',

', '__reduce_ex__', '__repr__', '__setattr__', '__str__']

' object has no attribute 'Load'

>>> a.Initialized()

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

AttributeError: 'GenericComObject' object has no attribute 'Initialized'



At this point I was expected to just get : FALSE.

Also when I try to call the Initialize method (which seems to be imported
correctly), I get the same error : unknown attribute.

When I try to step through the available methods,  I do not get any of the
interesting ones, only the 'generic' ones.

Also I have checked the Interop assembly using  IL DASM, and there also I
get the full list, so I think the interop assembly is ok.


What do I do wrong? Is this because it is a  COM object ?  The IronPython
tutorial is not very elaborate on what is actually happening during

the exercice, so I am running a bit out of ideas here.








-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20090316/3efa7af7/attachment.html>

More information about the Ironpython-users mailing list