Reputation:
Previously I've used PyVisa1.4
in Python2.7
, and everything works fine.
Now I need to use Pyvisa1.4
in Python3.2
.
I knew that some syntax are changed in Python3.2. Therefore I use the 2to3
to convert the originalPysiva .py
files into the new format which are supposed to fit the Python3.2.
But now, unexpected error is generated which is related to ctypes
. And I read through the Pyvisa package .py
files and try to fix this but still don't know how to do deal with this.
I'm just trying to use the simple get_instruments_list()
command like below:
>>> import visa
>>> get_instruments_list()
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
get_instruments_list()
File "C:\Python32\Lib\site-packages\pyvisa\visa.py", line 254, in get_instruments_list
vpp43.find_resources(resource_manager.session, "?*::INSTR")
File "C:\Python32\Lib\site-packages\pyvisa\vpp43.py", line 581, in find_resources
instrument_description)
ctypes.ArgumentError: argument 2: <class 'TypeError'>: wrong type
The MAIN problem I'm facing now is how to correctly use PyVisa
in Python3.2
.
Upvotes: 3
Views: 1564
Reputation: 6063
PyVISA 1.5 (which is in beta now) provides, among other things, full Python 3 support. Take a look at the (new) documentation for instructions about how to download the latest development version at http://pyvisa.readthedocs.org/
Upvotes: 2
Reputation: 1
The problem is the str that is passed as second argument. In Python 3 the str was radically changed in order to support unicode. To correct this problem all strings before being passed to the DLL library must be encoded in ASCII. Conversely, the return strings are returned as bytes should be converted back into str.
I have corrected this on the visa.py, on the
CR = "\r" replaces CR = b"\r"
LF = "\n" replaces LF = b"\n"
ResourceTemplate init
self.vi = vpp43.open(resource_manager.session, resource_name.encode("ASCII"),
keyw.get("lock", VI_NO_LOCK))
instead of
self.vi = vpp43.open(resource_manager.session, resource_name,
keyw.get("lock", VI_NO_LOCK))
Instrument.write
vpp43.write(self.vi, message.encode("ASCII"))
instead of
vpp43.write(self.vi, message)
conversely on the read_raw the final return is replaced by
return str(buffer)
and on get_instruments_list()
vpp43.find_resources(resource_manager.session, "?*::INSTR".encode("ASCII"))
Upvotes: 0
Reputation: 1809
The newest version of Pyvisa
doesn't support Python3.2
Even thouhg you convert the syntax of Pyvisa1.4
for Python2.X
to Python3.X
by using 2to3
tool, it still won't work
Upvotes: -1