NI VISA + pyVisa on Mac OS X (Snow Leopard)

风格不统一 提交于 2019-12-03 15:38:15

It turns out that NI-VISA 5.0 works well on 10.6.6.

The issue I was having was when calling pyVisa's visa.Instrument("GPIB::1") it said the library was not found. However when calling visa.get_instruments_list() displayed my GPIB adapter as GPIB0. Using this as the device I was able to connect properly.

There were a few changes that I had to make that were not documented well on NI's site (that I could find at least) in order to accomplish this. The most important being the name of the VISA library that NI-VISA 5.0 installs. It is found at /Library/Frameworks/Visa.framework/VISA. I have not tried modifying the nsi file to automatically link to this library as the pyVisa documentation mentions.

I have been unable to install pyvisa with pip. I had to use easy_install. If anyone has had success installing pyvisa with pip, I would really like to know how!

System Settings:

Python 2.7 running virutalenv + virtualenvwrapper. Snow Leopard 10.6.6. NI-VISA 5.0

Sample Code:

from pyvisa.vpp43 import visa_library
visa_library.load_library("/Library/Frameworks/Visa.framework/VISA")
import visa
visa.get_instruments_list() # Yields: ['ASRL1', 'ASRL2', 'ASRL3', 'ASRL4', 'GPIB0::1']
temp = visa.Instrument("GPIB0::1")
print temp # Yeilds: Instrument("GPIB0::1::INSTR")

Update:
After moving to Lion I have found the same issues and have had to load the library manually each time. This makes me think I'm missing something.

I installed NI-VISA-5.0.0, NI-VISA-5.1.2 and PyVisa-1.4 on OSX 10.8.2 (Mountain Lion) and i get the following error

>>> import pyvisa.vpp43 as vpp43
>>> 
>>> 
>>> vpp43.visa_library.load_library('/Library/Frameworks/VISA.framework/VISA')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/PyVISA-1.4-py2.7.egg/pyvisa/vpp43.py", line 146, in load_library
    self.__lib = self.__cdecl_lib = cdll.LoadLibrary(path)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py", line 431, in LoadLibrary
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py", line 353, in __init__
OSError: dlopen(/Library/Frameworks/VISA.framework/VISA, 6): no suitable image found.  Did find:
    /Library/Frameworks/VISA.framework/VISA: no matching architecture in universal wrapper
    /Library/Frameworks/VISA.framework/VISA: no matching architecture in universal wrapper
>>>

Works fine in Mountain Lion 10.8.5.

  1. Install NI-VISA Runtime 5.4.
  2. Install pyvisa

First make an i386 binary of Python (mac os built-in) to force Python into 32-bit mode.

$ lipo -thin i386 -output python-i386 /usr/bin/python2.7
$ ./python-i386

And then:

# make sure pyvisa is available in the built-in python
import sys
sys.path.append('path-to-your-pyvisa')

from pyvisa.vpp43 import visa_library
visa_library.load_library("/Library/Frameworks/Visa.framework/VISA")
import visa
visa.get_instruments_list()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!