I am an experimental physicist and am a big enthusiast of Python.
I find it great for data analysis and scripting, and I actualy also use it to interface laboratory instruments (network analyzer, scopes, signal analyzers, and signal generators...). I think Python would be a very serious competitor for MATLAB in my field if there would exist a nice library incorporating instrument drivers.
Up to now, I have been using several strategies to interface them directly from my IPython session:
Using the library pyVisa, which is nice, working for the large majority of devices, but a little bit low-level, and requires an extra layer of programming to expose useful functions to the user.
I have been able recently to use IVI-COM or .NET drivers using pythondotnet (not IronPython, which lacks NumPy/Matplotlib... libraries). This solution is obviously the most satisfying one because the IVI drivers are already quite high level, and they are usually provided by the vendors and instruments from different vendors are then interchangeable.
My first question is a rather technical one:
I read everywhere that COM objects are integrated in the .NET framework and that you can use COM objets diretly in .NET. In my case, I'm able to use COM objects by importing the comtypes module (see http://code.activestate.com/recipes/578089-using-iviscope-instrument-driver-with-python/) and dotnet
with clr
from pythondotnet, but I simply don't understand how to access those COM objects with the clr
module. Can someone explain the link between COM and .NET?
Also, I am always a little bit confused, how do I know, when I have a DLL file, if this is containing a .NET module or not, and if I can open it with version 4.0 of .NET (I am a complete beginner in these framework issues and a link to the proper documentation would be perfectly fine)?
The second question is, more generally, is there not a module that would already gather a larger number of drivers for different instruments in a unified manner? It seems to me like we must be thousands of people working on the same issues.
I recently fell on the module lantz http://lantz.glugcen.dc.uba.ar/. Unfortunately, this is in Python 3.0, while I am still using Python 2.7 (with the pythonxy distribution for Windows). Moreover, I am a bit afraid by the fact that this project is not trying to implement the IVI recommendations, which would be a good starting point.
Any comment or link to a relevant source of information would be more than welcome.
I cannot speak to the first question of yours, but I have been working on a Python interpretation of the IVI standard here: https://github.com/python-ivi/python-ivi. Unfortunately, it's also Python 3, but it's pure Python (no importing of external DLL files, COM or .NET objects), so it may not be exactly what you're looking for. However, the advantage is that means it's cross-platform and should work in both Windows and Linux.
Python IVI (and the instrument interfaces python-vxi11 and python-usbtmc) has been updated to seamlessly support both Python 2 and Python 3. It's still pure Python, so there are no external binary dependencies (DLL files, COM or .NET objects) and it works on Windows, Linux, and Mac OS X. It has even been run on a Raspberry Pi. Also, Python IVI can use PyVISA to access National Instruments compatible hardware.
I am calling this an interpretation and not an implementation, because it cannot follow the specification to the letter simply because it's Python. I have tried to follow the specification as closely as possible, but I have also tried to keep it as pythonic as possible. It's less than a year old, though, and I'm currently the only one working on it, with my meager assortment of instruments. I would be more than happy to accept contributions, if there are people out there who want to help out.
Out of the box, python-ivi supports the VXI-11 protocol over LAN (compatible, I believe, with most LXI instruments) through the python-vxi11 module (python-vxi11 is also pure Python and thus cross-platform compatible), serial instrument support with pySerial (cross-platform), and GPIB support with linux-gpib (Linux only). I plan on also wrapping PyVISA so that python-ivi will be able to use all of the interfaces supported by PyVISA.
I use COM types in standard Python (not IronPython or pythondotnet) to control IVI drivers on a daily basis. I've never needed any additional .NET bindings. I usually do things like this:
from comtypes import client
dmm = client.CreateObject('VTEXDmm.VTEXDmm')
dmm.Initialize('TCPIP::10.20.30.40::INSTR', True, True)
dmm.Measurement.Read(1000)
Another option is to use TekVisa from Tektronix.
import clr clr.AddReferenceToFileAndPath('C:\Windows\\assembly\\GAC_32\\TekVISANet\\1.1.1.0__7f19bb2a5a9ae6e8\\TekVISANet.dll')
import TekVISANet
v = TekVISANet.VISA()
v.Open("GPIB0::6::INSTR")
id =v.Write("*IDN?",50)
s = v.Read(50)
print s
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With