Coder Social home page Coder Social logo

pyvisa-py's Introduction

PyVISA-py

Continuous integration

Documentation building

Code Coverage

Documentation Status

PyPI - License

PyPI

A PyVISA backend that implements a large part of the "Virtual Instrument Software Architecture" (VISA) in pure Python (with the help of some nice cross platform libraries python packages!).

Description

PyVISA started as wrapper for the IVI-VISA library and therefore you need to install a VISA library in your system (National Instruments, Keysight, etc). This works most of the time, for most people. But IVI-VISA implementations are proprietary libraries that only works on certain systems. That is when PyVISA-py jumps in.

Starting from version 1.6, PyVISA allows to use different backends. These backends can be dynamically loaded. PyVISA-py is one of such backends. It implements most of the methods for Message Based communication (Serial/USB/GPIB/Ethernet) using Python and some well developed, easy to deploy and cross platform libraries

VISA and Python

Python has a couple of features that make it very interesting for measurement controlling:

  • Python is an easy-to-learn scripting language with short development cycles.
  • It represents a high abstraction level, which perfectly blends with the abstraction level of measurement programs.
  • It has a very rich set of native libraries, including numerical and plotting modules for data analysis and visualisation.
  • A large set of books (in many languages) and on-line publications is available.

Requirements

  • Python (tested with 3.6+)
  • PyVISA 1.11+

Optionally:

  • PySerial (to interface with Serial instruments)
  • PyUSB (to interface with USB instruments)
  • linux-gpib (to interface with gpib instruments, only on linux)
  • gpib-ctypes (to interface with GPIB instruments on Windows and Linux)
  • psutil (to discover TCPIP devices across multiple interfaces)
  • zeroconf (for HiSLIP and VICP devices discovery)
  • pyvicp (to enable the Teledyne LeCroy proprietary VICP protocol)

Installation

Using pip:

$ pip install pyvisa-py

Documentation

The documentation can be read online at https://pyvisa-py.readthedocs.org

pyvisa-py's People

Contributors

arr-ee avatar bobmcnamara avatar bollenn avatar bors[bot] avatar circuitfox avatar cpagravel avatar davidfabijan avatar dependabot[bot] avatar dirkenstein avatar elkevn avatar eosti avatar garlick avatar greyltc avatar herm avatar hgrecco avatar itayperl avatar jondoesntgit avatar jonyscathe avatar lmcculley avatar lovetheguitar avatar matthieudartiailh avatar mwcmwc12 avatar pre-commit-ci[bot] avatar sbor23 avatar sessl3r avatar skrchnavy avatar spauka avatar t-kopp avatar tivek avatar twam avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pyvisa-py's Issues

Are GPIB instruments supported?

README suggests yes:

Requirements:

  • linux-gpib (to interface with gpib instruments, only on linux)

Readthedocs suggests no:

Which resource types are supported?
And later:

  • GPIB INSTR

VI_ATTR_TERMCHAR_EN not enabled automatically

While debugging issue #61 I discovered another bug (or missing feature?:-) When specifying a termination character for a read request (e.g. myDevice.read('\r')), the VI_ATTR_TERMCHAR attribute is correctly set, but the VI_ATTR_TERMCHAR_EN attribute is not forced to 'True', which in my case leads to the deadlock described in issue #61. In my opinion passing a termination character as parameter to the read function should automatically enable VI_ATTR_TERMCHAR_EN.

Best Regards,
Matthias

TCPPortMapper Client inits with the PortMapperVersion type instead of a value

Trying a TCP connection to an Agilent, I got stopped by a packing error:

[...]
    p.pack_callheader(xid, self.prog, self.vers, proc, cred, verf)
  File "/usr/local/lib/python2.7/dist-packages/pyvisa-py/protocols/rpc.py", line 144, in pack_callheader
    self.pack_uint(vers)
  File "/usr/lib/python2.7/xdrlib.py", line 54, in pack_uint
    self.__buf.write(struct.pack('>L', x))
struct.error: cannot convert argument to integer

After some investigation I noticed that "vers" was a PortMapperVersion (the type, not a value), so it wouldn't pack like an integer, and it was being inserted as self.vers in the Client class from here:

class TCPPortMapperClient(PartialPortMapperClient, RawTCPClient):
    def __init__(self, host):
        RawTCPClient.__init__(self, host, PMAP_PROG, PortMapperVersion, PMAP_PORT)
        PartialPortMapperClient.__init__(self)

Shouldn't this be a value?

Error trying to use PyVISA-py on Windows

I've been using the Agilent (now Keysight) VISA implementation with PyVISA for some time on my Windows machine.
I just tried installing PyVISA-py using:

pip install -U https://github.com/hgrecco/pyvisa-py/zipball/master

However I get:

Python 2.7.7 |Anaconda 2.0.1 (32-bit)| (default, Jun 11 2014, 10:41:43) [MSC v.1
500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
>>> import visa
>>> rm = visa.ResourceManager('@py')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Anaconda\lib\site-packages\pyvisa\highlevel.py", line 1471, in __new_
_
    visa_library = open_visa_library(visa_library)
  File "C:\Anaconda\lib\site-packages\pyvisa\highlevel.py", line 1440, in open_v
isa_library
    cls = get_wrapper_class(wrapper)
  File "C:\Anaconda\lib\site-packages\pyvisa\highlevel.py", line 1420, in get_wr
apper_class
    pkg = __import__(pkgname)
  File "C:\Anaconda\lib\site-packages\pyvisa-py\__init__.py", line 26, in <modul
e>
    from .highlevel import PyVisaLibrary
  File "C:\Anaconda\lib\site-packages\pyvisa-py\highlevel.py", line 20, in <modu
le>
    from pyvisa.compat import integer_types, OrderedDict
ImportError: cannot import name OrderedDict

This is the debug info output:

C:\Users\marnj>python -c "from pyvisa import util; util.get_debug_info()"
Machine Details:
   Platform ID:    Windows-7-6.1.7601-SP1
   Processor:      Intel64 Family 6 Model 58 Stepping 9, GenuineIntel

Python:
   Implementation: CPython
   Executable:     C:\Anaconda\python.exe
   Version:        2.7.7
   Compiler:       MSC v.1500 32 bit (Intel)
   Bits:           32bit
   Build:          Jun 11 2014 10:41:43 (#default)
   Unicode:        UCS2

VISA:
   PyVISA Version: 1.6.1.dev0

   #1: C:\windows\system32\visa32.dll
      found by: auto
      bitness: 32
   #2: C:\windows\system32\visa32.dll
      found by: auto
      bitness: 32

ASRL error

Hi,

First of all, your code is awesome, and thank you so much for it.
I believe there may be a missing class for ASRL connections though. I call pyvisa (using the latest pyvisa-py and pyvisa) as follows:

rm = visa.ResourceManager("@py")
resource = u'ASRL1::/dev/ttyUSB0::INSTR'
my_instrument = rm.open_resource(resource)

The traceback for the error is:

Traceback (most recent call last):
File "takedata.py", line 51, in
my_instrument = rm.open_resource(resource)
File "/usr/local/lib/python2.7/dist-packages/PyVISA-1.6.4.dev0-py2.7.egg/pyvisa/highlevel.py", line 1609, in open_resource
info = self.resource_info(resource_name)
File "/usr/local/lib/python2.7/dist-packages/PyVISA-1.6.4.dev0-py2.7.egg/pyvisa/highlevel.py", line 1576, in resource_info
ret, err = self.visalib.parse_resource_extended(self.session, resource_name)
File "/usr/local/lib/python2.7/dist-packages/PyVISA_py-0.2.dev0-py2.7.egg/pyvisa-py/highlevel.py", line 275, in parse_resource_extended
parsed = rname.parse_resource_name(resource_name)
File "/usr/local/lib/python2.7/dist-packages/PyVISA-1.6.4.dev0-py2.7.egg/pyvisa/rname.py", line 187, in from_string
raise InvalidResourceName.bad_syntax(subclass.syntax,
AttributeError: type object 'ASRLInstr' has no attribute 'syntax'

and my setup is as follows:
Machine Details:
Platform ID: Linux-3.18.0-trunk-rpi-armv6l-with-debian-7.8
Processor:

Python:
Implementation: CPython
Executable: /usr/bin/python
Version: 2.7.3
Compiler: GCC 4.6.3
Bits: 32bit
Build: Mar 18 2014 05:13:23 (#default)
Unicode: UCS4

PyVISA Version: 1.6.4.dev0

Backends:
ni:
Version: 1.6.4.dev0 (bundled with PyVISA)
Binary library: Not found
py:
Version: 0.2.dev0
ASRL INSTR: Available via PySerial (2.7)
GPIB INSTR:
Please install linux-gpib to use this resource type.
No module named gpib
TCPIP INSTR: Available
USB INSTR: Available via PyUSB (1.0.0rc1). Backend: libusb1
USB RAW: Available via PyUSB (1.0.0rc1). Backend: libusb1

My apologies if I simply misunderstand how to correctly deal with ASRL based instruments.

Thank you,
Michael

USB Device Not Detected

import visa
rm = visa.ResourceManager("@py")
print rm.list_resources()

returns:

(u'ASRLCOM1::INSTR',)

But using the ni driver:

import visa
rm = visa.ResourceManager()
print rm.list_resources()

returns:

(u'USB0::0x0957::0x0509::MY42403191::INSTR', u'ASRL1::INSTR', u'ASRL3::INSTR')

Why doesn't the pyvisa-py driver detect the USB device? It is an E5071B Agilent Network Analyzer.

here is my debug:

Machine Details:
Platform ID: Windows-XP-5.1.2600-SP3
Processor: x86 Family 6 Model 14 Stepping 8, GenuineIntel

Python:
Implementation: CPython
Executable: C:\src\venv\Scripts\python.exe
Version: 2.7.9
Compiler: MSC v.1500 32 bit (Intel)
Bits: 32bit
Build: Dec 10 2014 12:24:55 (#default)
Unicode: UCS2

PyVISA Version: 1.6.3

Backends:
ni:
Version: 1.6.3 (bundled with PyVISA)
#1: C:\WINDOWS\system32\visa32.dll:
found by: auto
bitness: 32
Vendor: National Instruments
Impl. Version: 5243905
Spec. Version: 5243136
#2: C:\WINDOWS\system32\visa32.dll:
found by: auto
bitness: 32
Vendor: National Instruments
Impl. Version: 5243905
Spec. Version: 5243136
py:
Version: 0.1
ASRL INSTR: Available via PySerial (N/A)
TCPIP INSTR: Available
USB INSTR: Available via PyUSB (1.0.0b2). Backend: N/A

UnicodeDecodeError with USB INSTR but not with TCPIP INSTR

Hello,
when trying to read the trace binary data from a Rigol scope using USB I get often errors like UnicodeDecodeError: 'ascii' codec can't decode byte 0x80 in position 12: ordinal not in range(128). Sometimes I get this error even when the instrument should have sent a real ASCII string, but it might be actually sending invalid bytes due to scope FW bugs. Anyway, I think the UnicodeDecodeError should not happen in any case.
When I connect using Ethernet this error does not happen.

With the log enabled this is what I get:

2015-11-03 19:35:22,312 - pyvisa - DEBUG - SerialSession was correctly imported.
2015-11-03 19:35:22,342 - pyvisa - DEBUG - USBSession and USBRawSession were correctly imported.
2015-11-03 19:35:22,344 - pyvisa - DEBUG - TCPIPSession was correctly imported.
2015-11-03 19:35:22,345 - pyvisa - DEBUG - GPIBSession was correctly imported.
2015-11-03 19:35:22,345 - pyvisa - DEBUG - Created library wrapper for unset
2015-11-03 19:35:22,345 - pyvisa - DEBUG - Created ResourceManager with session 6034227
2015-11-03 19:35:22,345 - pyvisa - DEBUG - USB0::6833::1230::DS1ZC162943448::0::INSTR - opening ...
2015-11-03 19:35:22,508 - pyvisa - DEBUG - USB0::6833::1230::DS1ZC162943448::0::INSTR - is open with session 9064266
24000000
2015-11-03 19:35:24,013 - pyvisa - DEBUG - USB0::6833::1230::DS1ZC162943448::0::INSTR - reading 20480 bytes (last status <StatusCode.success_max_count_read: 1073676294>)
act_md= u'24000000\n\x7f' md= 24000000
Memory depth set to 24000000
0
2015-11-03 19:35:25,016 - pyvisa - DEBUG - USB0::6833::1230::DS1ZC162943448::0::INSTR - reading 20480 bytes (last status <StatusCode.success_max_count_read: 1073676294>)
Traceback (most recent call last):
  File "mytest.py", line 10, in <module>
    cd = s.read()
  File "/home/username/mylib.py", line 67, in read
    d = self.i.read_raw()
  File "/usr/lib/python2.7/site-packages/PyVISA-1.8-py2.7.egg/pyvisa/resources/messagebased.py", line 306, in read_raw
    chunk, status = self.visalib.read(self.session, size)
  File "/usr/lib/python2.7/site-packages/PyVISA_py-0.3.dev0-py2.7.egg/pyvisa-py/highlevel.py", line 253, in read
    return self.sessions[session].read(count)
  File "/usr/lib/python2.7/site-packages/PyVISA_py-0.3.dev0-py2.7.egg/pyvisa-py/usb.py", line 102, in read
    usb.USBError)
  File "/usr/lib/python2.7/site-packages/PyVISA_py-0.3.dev0-py2.7.egg/pyvisa-py/sessions.py", line 323, in _read
    current = reader().encode('ascii')
UnicodeDecodeError: 'ascii' codec can't decode byte 0x80 in position 12: ordinal not in range(128)
2015-11-03 19:35:25,222 - pyvisa - DEBUG - USB0::6833::1230::DS1ZC162943448::0::INSTR - closing
2015-11-03 19:35:25,222 - pyvisa - DEBUG - USB0::6833::1230::DS1ZC162943448::0::INSTR - is closed

I have also tried to use query_binary_values() instead of read_raw() but I get the same error

Traceback (most recent call last):
  File "mytest.py", line 10, in <module>
    cd = s.read()
  File "/home/username/mylib.py", line 68, in read
    d = self.i.query_binary_values("WAV:DATA?", datatype='b', is_big_endian=True)
  File "/usr/lib/python2.7/site-packages/PyVISA-1.8-py2.7.egg/pyvisa/resources/messagebased.py", line 481, in query_binary_values
    block = self.read_raw()
  File "/usr/lib/python2.7/site-packages/PyVISA-1.8-py2.7.egg/pyvisa/resources/messagebased.py", line 306, in read_raw
    chunk, status = self.visalib.read(self.session, size)
  File "/usr/lib/python2.7/site-packages/PyVISA_py-0.3.dev0-py2.7.egg/pyvisa-py/highlevel.py", line 253, in read
    return self.sessions[session].read(count)
  File "/usr/lib/python2.7/site-packages/PyVISA_py-0.3.dev0-py2.7.egg/pyvisa-py/usb.py", line 102, in read
    usb.USBError)
  File "/usr/lib/python2.7/site-packages/PyVISA_py-0.3.dev0-py2.7.egg/pyvisa-py/sessions.py", line 323, in _read
    current = reader().encode('ascii')
UnicodeDecodeError: 'ascii' codec can't decode byte 0x80 in position 12: ordinal not in range(128)

System information:

$ python -m visa info
Machine Details:
   Platform ID:    Linux-3.17.1-smp-i686-x86_64
   Processor:      x86_64

Python:
   Implementation: CPython
   Executable:     /usr/bin/python
   Version:        2.7.5
   Compiler:       GCC 4.8.0
   Bits:           32bit
   Build:          May 29 2013 03:26:28 (#default)
   Unicode:        UCS2

PyVISA Version: 1.8

Backends:
   ni:
      Version: 1.8 (bundled with PyVISA)
      Binary library: Not found
   py:
      Version: 0.3.dev0
      ASRL INSTR: Available via PySerial (2.7)
      TCPIP INSTR: Available 
      USB RAW: Available via PyUSB (1.0.0b2). Backend: libusb1
      USB INSTR: Available via PyUSB (1.0.0b2). Backend: libusb1
      GPIB INSTR: Available via Linux GPIB (< 4.0)
      TCPIP SOCKET: Available 

TypeError: can't concat bytes to str (When using gpib)

Hi, I'm trying to connect pyvisa and pyvisa-py to a instrument using gpib (NI-USB-B adaptor), and I've manged to open a connection to the instrument, however when I try to query it, pyvisa-py breaks and throws me a traceback. It is a python3 specific problem, as it works fine in python2.7.

Python 3.4.3 (default, Mar 25 2015, 17:13:50) 
[GCC 4.9.2 20150304 (prerelease)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import visa
>>> visa.log_to_screen()
>>> rm = visa.ResourceManager('@py')
2015-08-18 11:05:35,438 - pyvisa - DEBUG - SerialSession was not imported No module named 'serial'.
2015-08-18 11:05:35,440 - pyvisa - DEBUG - USBSession and USBRawSession were not imported No module named 'usb'.
2015-08-18 11:05:35,448 - pyvisa - DEBUG - TCPIPSession was not imported cannot import name 'TCPIPSession'.
2015-08-18 11:05:35,451 - pyvisa - DEBUG - GPIBSession was correctly imported.
2015-08-18 11:05:35,451 - pyvisa - DEBUG - Created library wrapper for unset
2015-08-18 11:05:35,452 - pyvisa - DEBUG - Created ResourceManager with session 5468318
>>> rm.list_resources()
('GPIB0::20::INSTR',)
>>> inst = rm.open_resource('GPIB0::20::INSTR')
2015-08-18 11:06:01,818 - pyvisa - DEBUG - GPIB0::20::INSTR - opening ...
2015-08-18 11:06:01,822 - pyvisa - DEBUG - GPIB0::20::INSTR - is open with session 8322128
>>> print(inst.query("*IDN?"))
2015-08-18 11:06:12,064 - pyvisa - DEBUG - GPIB.write b'*IDN?\r\n'
2015-08-18 11:06:12,074 - pyvisa - DEBUG - GPIB0::20::INSTR - reading 20480 bytes (last status <StatusCode.success_max_count_read: 1073676294>)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.4/site-packages/pyvisa/resources/messagebased.py", line 407, in query
    return self.read()
  File "/usr/lib/python3.4/site-packages/pyvisa/resources/messagebased.py", line 332, in read
    message = self.read_raw().decode(enco)
  File "/usr/lib/python3.4/site-packages/pyvisa/resources/messagebased.py", line 306, in read_raw
    chunk, status = self.visalib.read(self.session, size)
  File "/usr/lib/python3.4/site-packages/pyvisa-py/highlevel.py", line 253, in read
    return self.sessions[session].read(count)
  File "/usr/lib/python3.4/site-packages/pyvisa-py/gpib.py", line 119, in read
    return self._read(reader, count, checker, False, None, False, gpib.GpibError)
  File "/usr/lib/python3.4/site-packages/pyvisa-py/sessions.py", line 318, in _read
    out += current
TypeError: can't concat bytes to str

And some version info:

PyVISA Version: 1.8.dev0

Backends:
   ni:
      Version: 1.8.dev0 (bundled with PyVISA)
      Binary library: Not found
   py:
      Version: 0.2.dev2
      USB INSTR:
         Please install PyUSB to use this resource type.
         No module named 'usb'
      TCPIP INSTR: Available 
      USB RAW:
         Please install PyUSB to use this resource type.
         No module named 'usb'
      ASRL INSTR:
         Please install PySerial to use this resource type.
         No module named 'serial'
      TCPIP SOCKET: Available 
      GPIB INSTR: Available 

Problem connecting to TCPIP instrument

Hi there! I'm trying to connect to my instrument via TCP/IP and I'm running into an issue. I can connect with telnet, but cannot connect using PyVISA with PyVISA-py. Here's what I'm getting. Any help debugging this will be greatly appreciated.

pi@raspberrypi ~ $ telnet
telnet> open 10.0.0.113 5025
Trying 10.0.0.113...
Connected to 10.0.0.113.
Escape character is '^]'.
*IDN?
B&K Precision ,891,4030MP1002, 1.24/ 1.04/ 1.03B
^]

telnet> quit
Connection closed.
pi@raspberrypi ~ $ sudo python
Python 2.7.8 (default, Oct 30 2014, 18:30:15)
[GCC 4.9.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import visa; rm = visa.ResourceManager("@py");
>>> inst = rm.open_resource("TCPIP::10.0.0.113::5025::INSTR")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/PyVISA-1.6.3.dev0-py2.7.egg/pyvisa/highlevel.py", line 1638, in open_resource
    res.open(access_mode, open_timeout)
  File "/usr/local/lib/python2.7/dist-packages/PyVISA-1.6.3.dev0-py2.7.egg/pyvisa/resources/resource.py", line 165, in open
    self.session, status = self._resource_manager.open_bare_resource(self._resource_name, access_mode, open_timeout)
  File "/usr/local/lib/python2.7/dist-packages/PyVISA-1.6.3.dev0-py2.7.egg/pyvisa/highlevel.py", line 1602, in open_bare_resource
    return self.visalib.open(self.session, resource_name, access_mode, open_timeout)
  File "/usr/local/lib/python2.7/dist-packages/PyVISA_py-0.1.dev0-py2.7.egg/pyvisa-py/highlevel.py", line 180, in open
    sess = cls(session, resource_name, parsed)
  File "/usr/local/lib/python2.7/dist-packages/PyVISA_py-0.1.dev0-py2.7.egg/pyvisa-py/sessions.py", line 183, in __init__
    self.after_parsing()
  File "/usr/local/lib/python2.7/dist-packages/PyVISA_py-0.1.dev0-py2.7.egg/pyvisa-py/tcpip.py", line 45, in after_parsing
    self.interface = vxi11.CoreClient(self.parsed['host_address'])
  File "/usr/local/lib/python2.7/dist-packages/PyVISA_py-0.1.dev0-py2.7.egg/pyvisa-py/protocols/vxi11.py", line 199, in __init__
    super(CoreClient, self).__init__(host, DEVICE_CORE_PROG, DEVICE_CORE_VERS)
  File "/usr/local/lib/python2.7/dist-packages/PyVISA_py-0.1.dev0-py2.7.egg/pyvisa-py/protocols/rpc.py", line 569, in __init__
    pmap = TCPPortMapperClient(host)
  File "/usr/local/lib/python2.7/dist-packages/PyVISA_py-0.1.dev0-py2.7.egg/pyvisa-py/protocols/rpc.py", line 547, in __init__
    RawTCPClient.__init__(self, host, PMAP_PROG, PMAP_VERS, PMAP_PORT)
  File "/usr/local/lib/python2.7/dist-packages/PyVISA_py-0.1.dev0-py2.7.egg/pyvisa-py/protocols/rpc.py", line 321, in __init__
    self.connect()
  File "/usr/local/lib/python2.7/dist-packages/PyVISA_py-0.1.dev0-py2.7.egg/pyvisa-py/protocols/rpc.py", line 325, in connect
    self.sock.connect((self.host, self.port))
  File "/usr/lib/python2.7/socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
socket.error: [Errno 111] Connection refused
>>> from pyvisa import util
>>> util.get_debug_info()
Machine Details:
   Platform ID:    Linux-3.12.33+-armv6l-with-debian-7.6
   Processor:

Python:
   Implementation: CPython
   Executable:     /usr/bin/python
   Version:        2.7.8
   Compiler:       GCC 4.9.1
   Bits:           32bit
   Build:          Oct 30 2014 18:30:15 (#default)
   Unicode:        UCS4

PyVISA Version: 1.6.3.dev0

Backends:
   ni:
      Version: 1.6.3.dev0 (bundled with PyVISA)
      Binary library: Not found
   py:
      Version: 0.1.dev0
      ASRL INSTR: Available via PySerial (N/A)
      TCPIP INSTR: Available
      USB INSTR: Available via PyUSB (1.0.0rc1). Backend: libusb1

>>>

PyVISA-py does not appear to work with VM of Ubuntu

Hi I am not sure if I'm having issues with my VM or PyVISA-py. I installed the latest PyVISA-py on my Ubuntu VM at work so I can start running all my test scripts in Linux instead of Windows, however somethings seem to not work correctly. Below is an output I get after checking to see what devices I have available to connect to.

Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.

import visa
rm = visa.ResourceManager('@py')
rm.list_resources()
(u'ASRL/dev/ttyS31::INSTR', u'ASRL/dev/ttyS30::INSTR', u'ASRL/dev/ttyS29::INSTR', u'ASRL/dev/ttyS28::INSTR', u'ASRL/dev/ttyS27::INSTR', u'ASRL/dev/ttyS26::INSTR', u'ASRL/dev/ttyS25::INSTR', u'ASRL/dev/ttyS24::INSTR', u'ASRL/dev/ttyS23::INSTR', u'ASRL/dev/ttyS22::INSTR', u'ASRL/dev/ttyS21::INSTR', u'ASRL/dev/ttyS20::INSTR', u'ASRL/dev/ttyS19::INSTR', u'ASRL/dev/ttyS18::INSTR', u'ASRL/dev/ttyS17::INSTR', u'ASRL/dev/ttyS16::INSTR', u'ASRL/dev/ttyS15::INSTR', u'ASRL/dev/ttyS14::INSTR', u'ASRL/dev/ttyS13::INSTR', u'ASRL/dev/ttyS12::INSTR', u'ASRL/dev/ttyS11::INSTR', u'ASRL/dev/ttyS10::INSTR', u'ASRL/dev/ttyS9::INSTR', u'ASRL/dev/ttyS8::INSTR', u'ASRL/dev/ttyS7::INSTR', u'ASRL/dev/ttyS6::INSTR', u'ASRL/dev/ttyS5::INSTR', u'ASRL/dev/ttyS4::INSTR', u'ASRL/dev/ttyS3::INSTR', u'ASRL/dev/ttyS2::INSTR', u'ASRL/dev/ttyS1::INSTR', u'ASRL/dev/ttyS0::INSTR')

and here is the output of python -m visa info on my VM. Any help would be much appreciated!! Thanks!

Machine Details:
Platform ID: Linux-3.13.0-61-generic-x86_64-with-Ubuntu-14.04-trusty
Processor: x86_64

Python:
Implementation: CPython
Executable: /usr/bin/python
Version: 2.7.6
Compiler: GCC 4.8.2
Bits: 64bit
Build: Jun 22 2015 17:58:13 (#default)
Unicode: UCS4

PyVISA Version: 1.8

Backends:
ni:
Version: 1.8 (bundled with PyVISA)
Binary library: Not found
py:
Version: 0.2
ASRL INSTR: Available via PySerial (2.7)
TCPIP INSTR: Available
USB RAW: Available via PyUSB (1.0.0b2). Backend: libusb1
USB INSTR: Available via PyUSB (1.0.0b2). Backend: libusb1
GPIB INSTR:
Please install linux-gpib to use this resource type.
No module named gpib
TCPIP SOCKET: Available

struct problems on python2.7

when running on python2.7 I get errors with struct.pack:

File "/home/hybrid5/.local/lib/python2.7/site-packages/pyvisa-py/protocols/rpc.py", line 282, in sendfrag
header = struct.pack(">I", x)
TypeError: Struct() argument 1 must be string, not unicode

locally I fixed the two occurences of struct.pack to use a byte-string literal and that seems to work fine.

PyVisa not using PyVisa-py ->NotImplementedError

I just started with the pyVisa-py Tutorial on https://pyvisa-py.readthedocs.org/en/latest/:

import visa

rm = visa.ResourceManager('@py')
print(rm)
rm.list_resources()

and get the following error message:

raceback (most recent call last):
  File "/src/usb/ATP_USB_Double/usbutu.py", line 5, in <module>
    rm.list_resources()
  File "/usr/local/lib/python2.7/dist-packages/pyvisa/highlevel.py", line 1554, in list_resources
    find_list, return_counter, instrument_description, err = lib.find_resources(self.session, query)
  File "/usr/local/lib/python2.7/dist-packages/pyvisa/highlevel.py", line 500, in find_resources
    raise NotImplementedError
NotImplementedError

I am using a Raspi 2 with Linux:
Linux (none) 3.18.7-v7+ #755 SMP PREEMPT Thu Feb 12 17:20:48 GMT 2015 armv7l GNU/Linux

python -m visa info

gives me:

Machine Details:
   Platform ID:    Linux-3.18.7-v7+-armv7l-with-debian-7.8
   Processor:

Python:
   Implementation: CPython
   Executable:     /usr/bin/python
   Version:        2.7.3
   Compiler:       GCC 4.6.3
   Bits:           32bit
   Build:          Mar 18 2014 05:13:23 (#default)
   Unicode:        UCS4

PyVISA Version: 1.6.3

Backends:
   ni:
      Version: 1.6.3 (bundled with PyVISA)
      Binary library: Not found
   py:
      Version: 0.2.dev0
      ASRL INSTR:
         Please install PySerial to use this resource type.
         No module named tools.list_ports
      GPIB INSTR:
         Please install linux-gpib to use this resource type.
         No module named gpib
      TCPIP INSTR: Available
      USB INSTR: Available via PyUSB (N/A). Backend: libusb10
      USB RAW: Available via PyUSB (N/A). Backend: libusb10

It seems to me that Python is searching inside the pyvisa/highlevel.py instead of the pyvisa-py/highlevel.py for the list_resources function.

USB pipe error and connect problems with pyvisa-py 0.2

I suppose I should have filed a new bug intead of replying to an old thread. Sorry--I'm new to Github.

I'm using:
PyVISA==1.8
PyVISA-py==0.2

I'm having a problem with an Agilent 34411A multimeter. The stack trace looks like this. Last week I was able to get about one '*IDN?' query out of the machine and then all subsequent writes and queries failed until I unplugged/replugged/reconnected. It seems there is some bug deep in USB protocol handler. The same code works for a Keithley 2110 multimeter, so it must be some small difference in how they interact over USB which is tripping up pyvisa-py.

Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python2.7/dist-packages/pyvisa/highlevel.py", line 1644, in open_resource
res.open(access_mode, open_timeout)
File "/usr/local/lib/python2.7/dist-packages/pyvisa/resources/resource.py", line 203, in open
self.session, status = self.resource_manager.open_bare_resource(self.resource_name, access_mode, open_timeout)
File "/usr/local/lib/python2.7/dist-packages/pyvisa/highlevel.py", line 1601, in open_bare_resource
return self.visalib.open(self.session, resource_name, access_mode, open_timeout)
File "/usr/local/lib/python2.7/dist-packages/pyvisa-py/highlevel.py", line 191, in open
sess = cls(session, resource_name, parsed)
File "/usr/local/lib/python2.7/dist-packages/pyvisa-py/sessions.py", line 184, in __init
self.after_parsing()
File "/usr/local/lib/python2.7/dist-packages/pyvisa-py/usb.py", line 176, in after_parsing
self.parsed.serial_number)
File "/usr/local/lib/python2.7/dist-packages/pyvisa-py/protocols/usbtmc.py", line 232, in init
super(USBTMC, self).init(vendor, product, serial_number, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/pyvisa-py/protocols/usbtmc.py", line 166, in init
raise Exception('failed to set configuration\n %s' % e)
Exception: failed to set configuration
[Errno 16] Resource busy

Here's an example where the first query succeeded but then it fails thereafter. Maybe there is a pyvisa-py problem in releasing the USB bus? Below, I query the DC range, I get 100mV as a response, but then I query it again and it fails due to a Pipe Error. Immediately prior, I set up i = rm.open_resource()

i.query('SENS:VOLT:DC:RANG?')
u'+1.00000000E-01\n'
i.query('SENS:VOLT:DC:RANG?')
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python2.7/dist-packages/pyvisa/resources/messagebased.py", line 407, in query
return self.read()
File "/usr/local/lib/python2.7/dist-packages/pyvisa/resources/messagebased.py", line 332, in read
message = self.read_raw().decode(enco)
File "/usr/local/lib/python2.7/dist-packages/pyvisa/resources/messagebased.py", line 306, in read_raw
chunk, status = self.visalib.read(self.session, size)
File "/usr/local/lib/python2.7/dist-packages/pyvisa-py/highlevel.py", line 253, in read
return self.sessions[session].read(count)
File "/usr/local/lib/python2.7/dist-packages/pyvisa-py/usb.py", line 102, in read
usb.USBError)
File "/usr/local/lib/python2.7/dist-packages/pyvisa-py/sessions.py", line 313, in _read
current = reader()
File "/usr/local/lib/python2.7/dist-packages/pyvisa-py/usb.py", line 96, in
return self._read(lambda: self.interface.read(1),
File "/usr/local/lib/python2.7/dist-packages/pyvisa-py/protocols/usbtmc.py", line 307, in read
raw_write(req)
File "/usr/local/lib/python2.7/dist-packages/pyvisa-py/protocols/usbtmc.py", line 204, in write
raise ValueError(str(e))
ValueError: [Errno 32] Pipe error

PYVISA-py visa.ResourceManager('@py') not working. rm.list_resources() not working

The package was working fine 2 days ago. Suddenly from yesterday rm.list_resources() is throwing errors.
Since I know the instrument address from when everything was working fine earlier I can communicate with the device. However I cant id any new device connected.
This is what I use to establish connection
import visa
rm = visa.ResourceManager('@py')
rm.list_resources()
scope = rm.open_resource('USB0::1689::874::C037144::0::INSTR')
However step 3 is throwing error since yesterday.
Details are as follows
rohan@Jarvis:~$ python -m visa info
Machine Details:
Platform ID: Linux-3.13.0-76-generic-x86_64-with-Ubuntu-14.04-trusty
Processor: x86_64

Python:
Implementation: CPython
Executable: /usr/bin/python
Version: 2.7.6
Compiler: GCC 4.8.2
Bits: 64bit
Build: Jun 22 2015 17:58:13 (#default)
Unicode: UCS4

PyVISA Version: 1.8

Backends:
ni:
Version: 1.8 (bundled with PyVISA)
#1: /usr/lib/x86_64-linux-gnu/libvisa.so.0.0.0:
found by: auto
bitness: 64
Could not get more info:
VI_ERROR_NSUP_ATTR (-1073807331): The specified attribute is not defined or supported by the referenced object.
py:
Version: 0.3.dev0
ASRL INSTR: Available via PySerial (3.0.1)
TCPIP INSTR: Available
USB RAW: Available via PyUSB (1.0.0b2). Backend: libusb1
USB INSTR: Available via PyUSB (1.0.0b2). Backend: libusb1
GPIB INSTR: Available via Linux GPIB (4.0.2)
TCPIP SOCKET: Available
sim:
Version: 0.3
Spec version: 1.1

I'll also attach a pip list
rohan@Jarvis:~$ pip list
adium-theme-ubuntu (0.3.4)
apt-xapian-index (0.45)
argparse (1.2.1)
astroid (1.0.1)
chardet (2.0.1)
colorama (0.2.5)
command-not-found (0.3)
debtagshw (0.1)
decorator (3.4.0)
defer (1.0.6)
dirspec (13.10)
dnspython (1.11.1)
docutils (0.11)
duplicity (0.6.23)
enum34 (1.1.2)
gpib (1.0)
html5lib (0.999)
httplib2 (0.8)
ipython (1.2.1)
Jinja2 (2.7.2)
lockfile (0.8)
logilab-common (0.61.0)
lxml (3.3.3)
MarkupSafe (0.18)
matplotlib (1.3.1)
mercurial (2.8.2)
numpy (1.8.2)
oauthlib (0.6.1)
oneconf (0.3.7.14.04.1)
PAM (0.4.2)
pep8 (1.4.6)
pexpect (3.1)
Pillow (2.3.0)
pip (1.5.4)
piston-mini-client (0.7.5)
psutil (1.2.1)
py (1.4.20)
pycrypto (2.6.1)
pycups (1.9.66)
pycurl (7.19.3)
pyflakes (0.8.1)
Pygments (1.6)
pygobject (3.12.0)
pygpgme (0.3)
pylint (1.1.0)
pyOpenSSL (0.13)
pyparsing (2.0.1)
pyserial (3.0.1)
pysmbc (1.0.14.1)
python-apt (0.9.3.5ubuntu2)
python-dateutil (1.5)
python-debian (0.1.21-nmu2ubuntu2)
pytz (2012c)
pyusb (1.0.0b2)
PyVISA (1.8)
PyVISA-py (0.3.dev0)
PyVISA-sim (0.3)
pyxdg (0.25)
PyYAML (3.11)
pyzmq (14.0.1)
reportlab (3.0)
requests (2.2.1)
roman (2.0.0)
rope (0.9.2)
scipy (0.13.3)
sessioninstaller (0.0.0)
setuptools (3.3)
simplegeneric (0.8.1)
six (1.5.2)
software-center-aptd-plugins (0.0.0)
Sphinx (1.2.2)
spyder (2.2.5)
ssh-import-id (3.21)
stringparser (0.4.1)
system-service (0.1.6)
Twisted-Core (13.2.0)
Twisted-Web (13.2.0)
unity-lens-photos (1.0)
urllib3 (1.7.1)
usbtc08 (0.1.1)
wheel (0.24.0)
wsgiref (0.1.2)
xdiagnose (3.6.3build2)
zope.interface (4.0.5)

AttributeError: 'bytes' object has no attribute 'encode' when reading from GPIB

Executing this code:

import visa
visa.log_to_screen()
rm = visa.ResourceManager('@py')
spectrum_analyzer = rm.open_resource('GPIB0::20::INSTR')
spectrum_analyzer.write("*IDN?")
print(spectrum_analyzer.read_raw())

Fails with:

2015-12-15 16:01:40,178 - pyvisa - DEBUG - SerialSession was correctly imported.
2015-12-15 16:01:40,203 - pyvisa - DEBUG - USBSession and USBRawSession were correctly imported.
2015-12-15 16:01:40,209 - pyvisa - DEBUG - TCPIPSession was correctly imported.
2015-12-15 16:01:40,212 - pyvisa - DEBUG - GPIBSession was correctly imported.
2015-12-15 16:01:40,212 - pyvisa - DEBUG - Created library wrapper for unset
2015-12-15 16:01:40,213 - pyvisa - DEBUG - Created ResourceManager with session 4163272
2015-12-15 16:01:40,213 - pyvisa - DEBUG - GPIB0::20::INSTR - opening ...
2015-12-15 16:01:40,217 - pyvisa - DEBUG - GPIB0::20::INSTR - is open with session 9839346
2015-12-15 16:01:40,217 - pyvisa - DEBUG - GPIB.write b'*IDN?\r\n'
2015-12-15 16:01:40,226 - pyvisa - DEBUG - GPIB0::20::INSTR - reading 20480 bytes (last status <StatusCode.success_max_count_read: 1073676294>)
Traceback (most recent call last):
  File "./measure.py", line 21, in <module>
    print(spectrum_analyzer.read_raw())
  File "/usr/lib/python3.4/site-packages/pyvisa/resources/messagebased.py", line 306, in read_raw
    chunk, status = self.visalib.read(self.session, size)
  File "/usr/lib/python3.4/site-packages/PyVISA_py-0.3.dev0-py3.4.egg/pyvisa-py/highlevel.py", line 253, in read
    return self.sessions[session].read(count)
  File "/usr/lib/python3.4/site-packages/PyVISA_py-0.3.dev0-py3.4.egg/pyvisa-py/gpib.py", line 128, in read
    return self._read(reader, count, checker, False, None, False, gpib.GpibError)
  File "/usr/lib/python3.4/site-packages/PyVISA_py-0.3.dev0-py3.4.egg/pyvisa-py/sessions.py", line 323, in _read
    current = reader().encode('ascii')
AttributeError: 'bytes' object has no attribute 'encode'
2015-12-15 16:01:40,321 - pyvisa - DEBUG - GPIB0::20::INSTR - closing
2015-12-15 16:01:40,322 - pyvisa - DEBUG - GPIB0::20::INSTR - is closed
2015-12-15 16:01:40,332 - pyvisa - DEBUG - Closing ResourceManager (session: 4163272)

I worked around it by changing line https://github.com/hgrecco/pyvisa-py/blob/master/pyvisa-py/sessions.py#L323 to

current = reader()

if not isinstance(current, bytes):
    current = current.encode('ascii')

My System:

python3 -m visa info
Machine Details:
   Platform ID:    Linux-4.2.6-201.fc22.x86_64+debug-x86_64-with-fedora-22-Twenty_Two
   Processor:      x86_64

Python:
   Implementation: CPython
   Executable:     /usr/bin/python3
   Version:        3.4.2
   Compiler:       GCC 5.1.1 20150618 (Red Hat 5.1.1-4)
   Bits:           64bit
   Build:          Jul  9 2015 17:24:30 (#default)
   Unicode:        UCS4

PyVISA Version: 1.8

Backends:
   ni:
      Version: 1.8 (bundled with PyVISA)
      Binary library: Not found
   py:
      Version: 0.3.dev0
      GPIB INSTR: Available via Linux GPIB (b'4.0.2')
      USB RAW: Available via PyUSB (1.0.0b2). Backend: libusb1
      USB INSTR: Available via PyUSB (1.0.0b2). Backend: libusb1
      ASRL INSTR: Available via PySerial (2.7)
      TCPIP SOCKET: Available 
      TCPIP INSTR: Available 

pyvisa-py is at current master (4c266c8) and linux-gpib is version 4.0.2

Support for TCPIP SOCKET

It would be nice to have support for TCPIP SOCKET protocol, as TCPIP is the only protocol that should always work. Could you give some pointers about what would need to be adapted from the INSTR case to support the SOCKET case ?

getting error: Could not instantiate backend

Similar to previously reported issue(s) but slightly different and previously suggested fixes didn't seem to work. I'm relatively new to python and even more so to pyvisa/pyvisa-py .. here's what I've looked for so far:

'pip list' shows:
pyusb (1.0.0b2)
PyVISA (1.8)
pyserial (3.0)
pyusb (1.0.0b2)

Output of 'python -m visa info':
Machine Details:
Platform ID: Windows-7-6.1.7601-SP1
Processor: Intel64 Family 6 Model 61 Stepping 4, GenuineIntel

Python:
Implementation: CPython
Executable: C:\Anaconda2\python.exe
Version: 2.7.10
Compiler: MSC v.1500 64 bit (AMD64)
Bits: 64bit
Build: Dec 1 2015 11:29:38 (#default)
Unicode: UCS2

PyVISA Version: 1.8

Backends:
ni:
Version: 1.8 (bundled with PyVISA)
#1: C:\windows\system32\visa32.dll:
found by: auto
bitness: 64
Vendor: National Instruments
Impl. Version: 15728640
Spec. Version: 5243904
#2: C:\windows\system32\visa32.dll:
found by: auto
bitness: 64
Vendor: National Instruments
Impl. Version: 15728640
Spec. Version: 5243904
py:
Could not instantiate backend
-> No backend available

I am thinking that all the required pieces are there for the serial and USB backends, (and TCPIP as well?) Any guidance is much appreciated.

Problem with connection to Instrument (Spectracom CNT91 Time Interval Counter)

Hi, I am trying to interface to a Spectracom CNT91 time interval counter using pyvisa-py on a Red Hat Linux machine.

When using print rm.list_resources() it prints the following:

(u'USB0::5355::145::286688::0::INSTR',)

What it should be printing is:

('USB0::0x14EB::0x0091::286688::INSTR')

It seems to be printing the correct Vendor and Product ID in Decimal. (5355 instead of 0x14EB and 145 instead of 0x0091). However, I can open_resource() using either one of the resource names and request the IDN number.

PENDULUM, CNT-91, 286688, V1.30 24 May 2013 08:30

But I can only request the IDN number once. Any further requests after the first IDN read and the following error is displayed:

print(inst.query('*IDN?'))
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python2.7/dist-packages/pyvisa/resources/messagebased.py", line 401, in query
self.write(message)
File "/usr/local/lib/python2.7/dist-packages/pyvisa/resources/messagebased.py", line 207, in write
count = self.write_raw(message.encode(enco))
File "/usr/local/lib/python2.7/dist-packages/pyvisa/resources/messagebased.py", line 185, in write_raw
return self.visalib.write(self.session, message)
File "/usr/local/lib/python2.7/dist-packages/pyvisa-py/highlevel.py", line 271, in write
return self.sessions[session].write(data)
File "/usr/local/lib/python2.7/dist-packages/pyvisa-py/usb.py", line 117, in write
count = self.interface.write(data)
File "/usr/local/lib/python2.7/dist-packages/pyvisa-py/protocols/usbtmc.py", line 286, in write
bytes_sent += raw_write(data)
File "/usr/local/lib/python2.7/dist-packages/pyvisa-py/protocols/usbtmc.py", line 204, in write
raise ValueError(str(e))
ValueError: [Errno 110] Operation timed out

System info is as follows:

[renier@tfrtest00 ~]$ python -m visa info
Machine Details:
Platform ID: Linux-2.6.32-279.el6.x86_64-x86_64-with-redhat-6.3-Santiago
Processor: x86_64

Python:
Implementation: CPython
Executable: /usr/local/bin/python
Version: 2.7.0
Compiler: GCC 4.4.6 20120305 (Red Hat 4.4.6-4)
Bits: 64bit
Build: Aug 24 2015 04:16:07 (#r27:82500)
Unicode: UCS2

PyVISA Version: 1.8

Backends:
ni:
Version: 1.8 (bundled with PyVISA)
#1: /usr/local/vxipnp/linux/lib64/libvisa.so:
found by: auto
bitness: 64
Vendor: National Instruments
Impl. Version: 15728640
Spec. Version: 5243904
py:
Version: 0.2
ASRL INSTR:
Please install PySerial to use this resource type.
No module named serial
TCPIP INSTR: Available
USB RAW: Available via PyUSB (1.0.0rc1). Backend: libusb1
USB INSTR: Available via PyUSB (1.0.0rc1). Backend: libusb1
GPIB INSTR:
Please install linux-gpib to use this resource type.
No module named gpib
TCPIP SOCKET: Available

We have interfaced to the CNT91 using pyvisa and the NI Visa driver on a windows machine. The code is working and we are able to read back values from the unit. We now need to get this working on the Linux machine.

Help will be appreciated.
Thanks.

serial device timeout being set to 2000 seconds

Hi,

In serial.py, you set a default read and write timeout value of "2000".

According to the pyserial API docs, timeout is in seconds:

Possible values for the parameter timeout:

timeout = None: wait forever
timeout = 0: non-blocking mode (return immediately on read)
timeout = x: set timeout to x seconds (float allowed)

Did you mean to use a value of "2" instead?

USB Raw devices

USB Raw devices don't seem to be supported at the moment. Is this just some bug I don't see or is there something missing? If the latter is the case I'll iron out a couple issues with my locally working solution and submit it as a PR

Edit: I've seen a couple devices out there which simply had 1 Bulk in and one out, which is what I would target to add

No listed devices

Machine Details:

Platform ID: Linux-4.0.6-1-ARCH-x86_64-with-glibc2.2.5
Processor:

Python:

Implementation: CPython
Executable: /usr/bin/python
Version: 2.7.10
Compiler: GCC 5.1.0
Bits: 64bit
Build: May 26 2015 04:16:29 (#default)
Unicode: UCS4

PyVISA Version: 1.7

Backends:

ni:

  Version: 1.7 (bundled with PyVISA)
  Binary library: Not found

py:

  Version: 0.2.dev2
  ASRL INSTR: Available via PySerial (2.7)
  TCPIP INSTR: Available 
  USB RAW: Available via PyUSB (1.0.0b2). Backend: libusb1
  USB INSTR: Available via PyUSB (1.0.0b2). Backend: libusb1
  GPIB INSTR:
     Please install linux-gpib to use this resource type.
     No module named gpib
  TCPIP SOCKET: Available 

Unwanted behaviour:

When running:

import visa

rm = visa.ResourceManager('@py')  # Choose backend, default NI-VISA or py-visa
rm.list_resources()

No connected devices show.

Justification:

Inside /dev I can see usbtmc0 and for simple code the device echoes correctly when I read and write directly from /dev/usbtmc0: http://www.cibomahto.com/2010/04/controlling-a-rigol-oscilloscope-using-linux-and-python/ so my oscilloscope is "present" but is not being correctly detected.

Possible mismatch:

I note that the API from the link seems a bit different from what is being talked about at http://www.keysight.com/upload/cmc_upload/All/usbtmc.html?&cc=AU&lc=eng , where in the latter the first device should appear at usbtmc1 and usbtmc0 is used for talking with the driver; however on my setup, only usbtmc0 appears and it is a device, as in the example which I linked in 'Justification'.

Issue with Keysight USBTMC devices

I have troubles using pyvisa-py to communicate with Keysight USBTMC devices on Linux:

Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import visa; rm = visa.ResourceManager('@py'); l = rm.list_resources(); d = rm.open_resource(l[0])
>>> d.ask('*IDN?')
u'Agilent Technologies,34972A,MY49023315,1.17-1.12-02-02\n'
>>> d.ask('*IDN?')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/manip/src/test-pyvisa-py/local/lib/python2.7/site-packages/pyvisa/resources/messagebased.py", line 407, in query
    return self.read()
  File "/home/manip/src/test-pyvisa-py/local/lib/python2.7/site-packages/pyvisa/resources/messagebased.py", line 332, in read
    message = self.read_raw().decode(enco)
  File "/home/manip/src/test-pyvisa-py/local/lib/python2.7/site-packages/pyvisa/resources/messagebased.py", line 306, in read_raw
    chunk, status = self.visalib.read(self.session, size)
  File "/home/manip/src/test-pyvisa-py/local/lib/python2.7/site-packages/pyvisa-py/highlevel.py", line 253, in read
    return self.sessions[session].read(count)
  File "/home/manip/src/test-pyvisa-py/local/lib/python2.7/site-packages/pyvisa-py/usb.py", line 102, in read
    usb.USBError)
  File "/home/manip/src/test-pyvisa-py/local/lib/python2.7/site-packages/pyvisa-py/sessions.py", line 313, in _read
    current = reader()
  File "/home/manip/src/test-pyvisa-py/local/lib/python2.7/site-packages/pyvisa-py/usb.py", line 96, in <lambda>
    return self._read(lambda: self.interface.read(1),
  File "/home/manip/src/test-pyvisa-py/local/lib/python2.7/site-packages/pyvisa-py/protocols/usbtmc.py", line 307, in read
    raw_write(req)
  File "/home/manip/src/test-pyvisa-py/local/lib/python2.7/site-packages/pyvisa-py/protocols/usbtmc.py", line 204, in write
    raise ValueError(str(e))
ValueError: [Errno 110] Operation timed out
>>> 

as you can see, the second '*IDN?' command fails. I see some associated kernel messages:

[  716.703289] usb 1-10: new high-speed USB device number 11 using xhci_hcd
[  717.254758] usb 1-10: New USB device found, idVendor=0957, idProduct=2007
[  717.254768] usb 1-10: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[  717.254772] usb 1-10: Product: 34972A
[  717.254777] usb 1-10: Manufacturer: Keysight Technologies
[  717.254780] usb 1-10: SerialNumber: MY49023315
[  717.255088] usb 1-10: ep 0x2 - rounding interval to 128 microframes, ep desc says 255 microframes
[  717.255098] usb 1-10: ep 0x81 - rounding interval to 128 microframes, ep desc says 255 microframes
[  721.411616] usb 1-10: ep 0x2 - rounding interval to 128 microframes, ep desc says 255 microframes
[  721.411621] usb 1-10: ep 0x81 - rounding interval to 128 microframes, ep desc says 255 microframes
[  721.565855] usb 1-10: reset high-speed USB device number 11 using xhci_hcd
[  721.731155] usb 1-10: ep 0x2 - rounding interval to 128 microframes, ep desc says 255 microframes
[  721.731169] usb 1-10: ep 0x81 - rounding interval to 128 microframes, ep desc says 255 microframes
[  728.383831] xhci_hcd 0000:00:14.0: WARN Event TRB for slot 10 ep 2 with no TDs queued?
[  730.379499] xhci_hcd 0000:00:14.0: WARN Event TRB for slot 10 ep 2 with no TDs queued?

where the last two warnings correspond to the two '*IDN?' commands I issued. After that all attemps to communicate with the USBTMC device (read or write) fail until I reboot the device.

I'm able to communicate correctly with the device using the Linux usbtmc kernel driver:

Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> d = os.open('/dev/usbtmc0', os.O_RDWR)
>>> os.write(d, '*IDN?\r\n')
7
>>> os.read(d, 1024)
'Agilent Technologies,34972A,MY49023315,1.17-1.12-02-02\n'
>>> os.write(d, '*IDN?\r\n')
7
>>> os.read(d, 1024)
'Agilent Technologies,34972A,MY49023315,1.17-1.12-02-02\n'
>>> os.write(d, '*IDN?\r\n')
7
>>> os.read(d, 1024)
'Agilent Technologies,34972A,MY49023315,1.17-1.12-02-02\n'

usbtmc assertion failure

Linux, Python3 - talking to a Rigol ds1102e scope.
Most operations complete ok.
Trying to get the channel data from the scope.
ie: rawdata = inst.query_binary_values(":WAV:DATA? CHAN1")[10:]
Which is on the order of 1024 n-bit values. (I think - not really sure)

usbtmc.py croaks.

  File "./test.py", line 42, in <module>
    main()
  File "./test.py", line 29, in main
    rawdata = inst.query_binary_values(":WAV:DATA? CHAN1")[10:]
  File "/usr/local/lib/python3.4/dist-packages/pyvisa/resources/messagebased.py", line 458, in query_binary_values
    block = self.read_raw()
  File "/usr/local/lib/python3.4/dist-packages/pyvisa/resources/messagebased.py", line 283, in read_raw
    chunk, status = self.visalib.read(self.session, size)
  File "/usr/local/lib/python3.4/dist-packages/pyvisa-py/highlevel.py", line 297, in read
    return self.sessions[session].read(count)
  File "/usr/local/lib/python3.4/dist-packages/pyvisa-py/usb.py", line 107, in read
    usb.USBError)
  File "/usr/local/lib/python3.4/dist-packages/pyvisa-py/sessions.py", line 312, in _read
    current = reader()
  File "/usr/local/lib/python3.4/dist-packages/pyvisa-py/usb.py", line 101, in <lambda>
    return self._read(lambda: self.interface.read(1),
  File "/usr/local/lib/python3.4/dist-packages/pyvisa-py/protocols/usbtmc.py", line 327, in read
    response = BulkInMessage.from_bytes(resp)
  File "/usr/local/lib/python3.4/dist-packages/pyvisa-py/protocols/usbtmc.py", line 95, in from_bytes
    assert msgid == MsgID.dev_dep_msg_in
AssertionError

Here are the setup details:

python3 -m visa info
Machine Details:
   Platform ID:    Linux-3.13.0-45-generic-i686-with-Ubuntu-14.04-trusty
   Processor:      i686

Python:
   Implementation: CPython
   Executable:     /usr/bin/python3
   Version:        3.4.0
   Compiler:       GCC 4.8.2
   Bits:           32bit
   Build:          Apr 11 2014 13:05:18 (#default)
   Unicode:        UCS4

PyVISA Version: 1.6.3

Backends:
   ni:
      Version: 1.6.3 (bundled with PyVISA)
      #1: /usr/lib/i386-linux-gnu/libvisa.so.0.0.0:
         found by: auto
         bitness: 32
         Could not get more info:
            VI_ERROR_NSUP_ATTR (-1073807331): The specified attribute is not defined or supported by the referenced object.
   py:
      Version: 0.1
      TCPIP INSTR: Available 
      USB INSTR: Available via PyUSB (1.0.0b2). Backend: libusb1
      ASRL INSTR: Available via PySerial (N/A)

Thanks for PyVisa-py - I've gotten further with it than with librevisa.
Let me know if you need any more details.

Jason H.

Deadlock on Read with TCPIP Socket

In debugging a problem with reading data from a device using the TCPIP socket connection I discovered a problem in the read method of the TCPIPSocketSession class (ln. 391ff in tcpip.py; version 0.3.dev0): the select function is called without a timeout and therefore may block indefinitely in case the VI_ATTR_TERMCHAR_EN attribute is not set. In my case the while loop is executed once in the beginning to receive the data and then blocks forever the second time it gets to the select call.

My environment: Windows 7 Enterprise, SP1, Python 3.4.1

Best Regards,
Matthias

No backend available on Win7 with latest versions

C:\Users\marnj>python -m visa info
Machine Details:
   Platform ID:    Windows-7-6.1.7601-SP1
   Processor:      Intel64 Family 6 Model 58 Stepping 9, GenuineIntel

Python:
   Implementation: CPython
   Executable:     C:\Anaconda\python.exe
   Version:        2.7.7
   Compiler:       MSC v.1500 32 bit (Intel)
   Bits:           32bit
   Build:          Jun 11 2014 10:41:43 (#default)
   Unicode:        UCS2

PyVISA Version: 1.6.4.dev0

Backends:
   ni:
      Version: 1.6.4.dev0 (bundled with PyVISA)
      #1: C:\windows\system32\visa32.dll:
         found by: auto
         bitness: 32
         Vendor: Keysight Technologies
         Impl. Version: 1360312085
         Spec. Version: 5243136
      #2: C:\windows\system32\visa32.dll:
         found by: auto
         bitness: 32
         Vendor: Keysight Technologies
         Impl. Version: 1360312085
         Spec. Version: 5243136
   py:
      Version: 0.2.dev0
      ASRL INSTR: Available via PySerial (N/A)
      TCPIP INSTR: Available
      USB INSTR: Available via PyUSB (1.0.0b2). Backend: N/A
      USB RAW: Available via PyUSB (1.0.0b2). Backend: N/A
Python 2.7.7 |Anaconda 2.1.0 (32-bit)| (default, Jun 11 2014, 10:41:43) [MSC v.1
500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
>>> import visa
>>> rm = visa.ResourceManager('@py')
>>> rm.list_resources()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Anaconda\lib\site-packages\pyvisa\highlevel.py", line 1554, in list_r
esources
    find_list, return_counter, instrument_description, err = lib.find_resources(
self.session, query)
  File "C:\Anaconda\lib\site-packages\pyvisa-py\highlevel.py", line 240, in find
_resources
    for key, st in sessions.Session.iter_valid_session_classes()], [])
  File "C:\Anaconda\lib\site-packages\pyvisa-py\usb.py", line 148, in list_resou
rces
    for dev in usbtmc.find_tmc_devices():
  File "C:\Anaconda\lib\site-packages\pyvisa-py\protocols\usbtmc.py", line 69, i
n find_tmc_devices
    return find_devices(vendor, product, serial_number, is_usbtmc, **kwargs)
  File "C:\Anaconda\lib\site-packages\pyvisa-py\protocols\usbutil.py", line 200,
 in find_devices
    return usb.core.find(find_all=True, custom_match=cm, **kwargs)
  File "C:\Anaconda\lib\site-packages\usb\core.py", line 1199, in find
    raise ValueError('No backend available')
ValueError: No backend available

Unable to connect to a Keithley DMM 2701 through TCPIP/Ethernet

I am trying to use PyVISA-py as a backend to PyVISA on a device which runs Debian 7.8 wheezy. I have installed the latest versions of both PyVISA and PyVISA-py available as of the time of this post.

When I run

python -m visa info

I get:

Machine Details:
   Platform ID:    Linux-3.8.13-bone70-armv7l-with-debian-7.8
   Processor:      

Python:
   Implementation: CPython
   Executable:     /usr/bin/python
   Version:        2.7.3
   Compiler:       GCC 4.6.3
   Bits:           32bit
   Build:          Mar 14 2014 17:55:54 (#default)
   Unicode:        UCS4

PyVISA Version: 1.8.dev0

Backends:
   ni:
      Version: 1.8.dev0 (bundled with PyVISA)
      Binary library: Not found
   py:
      Version: 0.2.dev2
      ASRL INSTR:
         Please install PySerial to use this resource type.
         No module named tools.list_ports
      GPIB INSTR:
         Please install linux-gpib to use this resource type.
         No module named gpib
      TCPIP INSTR: Available 
      USB INSTR: Available via PyUSB (1.0.0rc1). Backend: libusb1
      USB RAW: Available via PyUSB (1.0.0rc1). Backend: libusb1

Then I go ahead and try communication with the Keithley using these commands:

import visa
rm = visa.ResourceManager('@py')
dmm = rm.open_resource('TCPIP::10.66.53.50::inst0:INSTR')

I get:

error                                     Traceback (most recent call last)
<ipython-input-3-478994839e1c> in <module>()
----> 1 dmm = rm.open_resource('TCPIP::10.66.53.50::inst0::INSTR')

/usr/local/lib/python2.7/dist-packages/PyVISA-1.8.dev0-py2.7.egg/pyvisa/highlevel.pyc in open_resource(self, resource_name, access_mode, open_timeout, **kwargs)
   1632                 raise ValueError('%r is not a valid attribute for type %s' % (key, res.__class__.__name__))
   1633 
-> 1634         res.open(access_mode, open_timeout)
   1635 
   1636         for key, value in kwargs.items():

/usr/local/lib/python2.7/dist-packages/PyVISA-1.8.dev0-py2.7.egg/pyvisa/resources/resource.pyc in open(self, access_mode, open_timeout)
    182         logger.debug('%s - opening ...', self._resource_name, extra=self._logging_extra)
    183         with self._resource_manager.ignore_warning(constants.VI_SUCCESS_DEV_NPRESENT):
--> 184             self.session, status = self._resource_manager.open_bare_resource(self._resource_name, access_mode, open_timeout)
    185 
    186             if status == constants.VI_SUCCESS_DEV_NPRESENT:

/usr/local/lib/python2.7/dist-packages/PyVISA-1.8.dev0-py2.7.egg/pyvisa/highlevel.pyc in open_bare_resource(self, resource_name, access_mode, open_timeout)
   1596         :return: Unique logical identifier reference to a session.
   1597         """
-> 1598         return self.visalib.open(self.session, resource_name, access_mode, open_timeout)
   1599 
   1600     def open_resource(self, resource_name,

/usr/local/lib/python2.7/dist-packages/PyVISA_py-0.2.dev2-py2.7.egg/pyvisa-py/highlevel.pyc in open(self, session, resource_name, access_mode, open_timeout)
    196         cls = sessions.Session.get_session_class(parsed.interface_type_const, parsed.resource_class)
    197 
--> 198         sess = cls(session, resource_name, parsed)
    199 
    200         return self._register(sess), constants.StatusCode.success

/usr/local/lib/python2.7/dist-packages/PyVISA_py-0.2.dev2-py2.7.egg/pyvisa-py/sessions.pyc in __init__(self, resource_manager_session, resource_name, parsed)
    182                       constants.VI_ATTR_RSRC_CLASS: parsed.resource_class,
    183                       constants.VI_ATTR_INTF_TYPE: parsed.interface_type}
--> 184         self.after_parsing()
    185 
    186     def after_parsing(self):

/usr/local/lib/python2.7/dist-packages/PyVISA_py-0.2.dev2-py2.7.egg/pyvisa-py/tcpip.pyc in after_parsing(self)
     43         # TODO: board_number not handled
     44         # TODO: lan_device_name not handled
---> 45         self.interface = vxi11.CoreClient(self.parsed.host_address)
     46 
     47         self.lock_timeout = 10000

/usr/local/lib/python2.7/dist-packages/PyVISA_py-0.2.dev2-py2.7.egg/pyvisa-py/protocols/vxi11.pyc in __init__(self, host)
    195         self.packer = Vxi11Packer()
    196         self.unpacker = Vxi11Unpacker('')
--> 197         super(CoreClient, self).__init__(host, DEVICE_CORE_PROG, DEVICE_CORE_VERS)
    198 
    199     def create_link(self, id, lock_device, lock_timeout, name):

/usr/local/lib/python2.7/dist-packages/PyVISA_py-0.2.dev2-py2.7.egg/pyvisa-py/protocols/rpc.pyc in __init__(self, host, prog, vers)
    580     """
    581     def __init__(self, host, prog, vers):
--> 582         pmap = TCPPortMapperClient(host)
    583         port = pmap.get_port((prog, vers, IPPROTO_TCP, 0))
    584         pmap.close()

/usr/local/lib/python2.7/dist-packages/PyVISA_py-0.2.dev2-py2.7.egg/pyvisa-py/protocols/rpc.pyc in __init__(self, host)
    558 
    559     def __init__(self, host):
--> 560         RawTCPClient.__init__(self, host, PMAP_PROG, PMAP_VERS, PMAP_PORT)
    561         PartialPortMapperClient.__init__(self)
    562 

/usr/local/lib/python2.7/dist-packages/PyVISA_py-0.2.dev2-py2.7.egg/pyvisa-py/protocols/rpc.pyc in __init__(self, host, prog, vers, port)
    323     def __init__(self, host, prog, vers, port):
    324         Client.__init__(self, host, prog, vers, port)
--> 325         self.connect()
    326 
    327     def connect(self):

/usr/local/lib/python2.7/dist-packages/PyVISA_py-0.2.dev2-py2.7.egg/pyvisa-py/protocols/rpc.pyc in connect(self)
    327     def connect(self):
    328         self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
--> 329         self.sock.connect((self.host, self.port))
    330 
    331     def close(self):

/usr/lib/python2.7/socket.pyc in meth(name, self, *args)
    222 
    223 def meth(name,self,*args):
--> 224     return getattr(self._sock,name)(*args)
    225 
    226 for _m in _socketmethods:

error: [Errno 110] Connection timed out

Any help is highly appreciated.

PS. I can ping the IP address 10.66.53.50 with zero packets lost.

Problem connecting to TCP/IP INSTR class device

I'm having a problem with INSTR devices. I can confirm my INSTR device does work with NI backend.

Working NI backend

C:\Users\lmcculley\Documents\libusb>python
Python 2.7.9 (default, Dec 10 2014, 12:28:03) [MSC v.1500 64 bit (AMD64)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> import visa; rm = visa.ResourceManager();
>>> inst = rm.open_resource("TCPIP::10.0.0.189::INSTR")
>>> inst.query("*IDN?")
u''
>>> inst.read_termination = '\n'
>>> inst.query("*IDN?")
u'B&K Precision Corporation;TDO3000B;123456;V2.02.0F.13 110315D'
>>>

Non-working PY backend

pi@raspberrypi ~/pyvisa-py $ sudo python
Python 2.7.8 (default, Oct 30 2014, 18:30:15)
[GCC 4.9.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import visa; rm = visa.ResourceManager("@py");
>>> inst = rm.open_resource("TCPIP::10.0.0.189::INSTR")
>>> inst.query("*IDN?")
u''
>>> inst.read_termination = "\n"
>>> inst.query("*IDN?")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/PyVISA-1.6.3.dev0-py2.7.egg/pyvisa/resources/messagebased.py", line 384, in query
    return self.read()
  File "/usr/local/lib/python2.7/dist-packages/PyVISA-1.6.3.dev0-py2.7.egg/pyvisa/resources/messagebased.py", line 309, in read
    message = self.read_raw().decode(enco)
  File "/usr/local/lib/python2.7/dist-packages/PyVISA-1.6.3.dev0-py2.7.egg/pyvisa/resources/messagebased.py", line 283, in read_raw
    chunk, status = self.visalib.read(self.session, size)
  File "pyvisa-py/highlevel.py", line 297, in read
    return self.sessions[session].read(count)
  File "pyvisa-py/tcpip.py", line 106, in read
    self.lock_timeout, flags, term_char)
  File "pyvisa-py/protocols/vxi11.py", line 217, in device_read
    self.unpacker.unpack_device_read_resp)
  File "pyvisa-py/protocols/rpc.py", line 237, in make_call
    pack_func(args)
  File "pyvisa-py/protocols/vxi11.py", line 115, in pack_device_read_parms
    self.pack_int(term_char)
  File "/usr/lib/python2.7/xdrlib.py", line 46, in result
    raise ConversionError(e.args[0])
xdrlib.ConversionError: cannot convert argument to integer
>>> inst.read_termination = "\r"
>>> inst.query("*IDN?")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/PyVISA-1.6.3.dev0-py2.7.egg/pyvisa/resources/messagebased.py", line 384, in query
    return self.read()
  File "/usr/local/lib/python2.7/dist-packages/PyVISA-1.6.3.dev0-py2.7.egg/pyvisa/resources/messagebased.py", line 309, in read
    message = self.read_raw().decode(enco)
  File "/usr/local/lib/python2.7/dist-packages/PyVISA-1.6.3.dev0-py2.7.egg/pyvisa/resources/messagebased.py", line 283, in read_raw
    chunk, status = self.visalib.read(self.session, size)
  File "pyvisa-py/highlevel.py", line 297, in read
    return self.sessions[session].read(count)
  File "pyvisa-py/tcpip.py", line 106, in read
    self.lock_timeout, flags, term_char)
  File "pyvisa-py/protocols/vxi11.py", line 217, in device_read
    self.unpacker.unpack_device_read_resp)
  File "pyvisa-py/protocols/rpc.py", line 237, in make_call
    pack_func(args)
  File "pyvisa-py/protocols/vxi11.py", line 115, in pack_device_read_parms
    self.pack_int(term_char)
  File "/usr/lib/python2.7/xdrlib.py", line 46, in result
    raise ConversionError(e.args[0])
xdrlib.ConversionError: cannot convert argument to integer
>>> inst.read_termination = "\r\n"
>>> inst.query("*IDN?")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/PyVISA-1.6.3.dev0-py2.7.egg/pyvisa/resources/messagebased.py", line 384, in query
    return self.read()
  File "/usr/local/lib/python2.7/dist-packages/PyVISA-1.6.3.dev0-py2.7.egg/pyvisa/resources/messagebased.py", line 309, in read
    message = self.read_raw().decode(enco)
  File "/usr/local/lib/python2.7/dist-packages/PyVISA-1.6.3.dev0-py2.7.egg/pyvisa/resources/messagebased.py", line 283, in read_raw
    chunk, status = self.visalib.read(self.session, size)
  File "pyvisa-py/highlevel.py", line 297, in read
    return self.sessions[session].read(count)
  File "pyvisa-py/tcpip.py", line 106, in read
    self.lock_timeout, flags, term_char)
  File "pyvisa-py/protocols/vxi11.py", line 217, in device_read
    self.unpacker.unpack_device_read_resp)
  File "pyvisa-py/protocols/rpc.py", line 237, in make_call
    pack_func(args)
  File "pyvisa-py/protocols/vxi11.py", line 115, in pack_device_read_parms
    self.pack_int(term_char)
  File "/usr/lib/python2.7/xdrlib.py", line 46, in result
    raise ConversionError(e.args[0])
xdrlib.ConversionError: cannot convert argument to integer
>>>

AttributeError: 'Device' object has no attribute 'serial_number' on Linux machine

Just installed pyvisa and pyvisa-py today from github master zips on an Ubuntu machine.

Here's my python -m visa info output:

Machine Details:
   Platform ID:    Linux-3.13.0-43-generic-x86_64-with-debian-jessie-sid
   Processor:      x86_64

Python:
   Implementation: CPython
   Executable:     /home/mj-ubuntu/anaconda/bin/python
   Version:        2.7.9
   Compiler:       GCC 4.4.7 20120313 (Red Hat 4.4.7-1)
   Bits:           64bit
   Build:          Mar  9 2015 16:20:48 (#default)
   Unicode:        UCS4

PyVISA Version: 1.8.dev0

Backends:
   ni:
      Version: 1.8.dev0 (bundled with PyVISA)
      Binary library: Not found
   py:
      Version: 0.2.dev2
      ASRL INSTR: Available via PySerial (2.7)
      TCPIP INSTR: Available 
      USB RAW: Available via PyUSB (1.0.0b1). Backend: libusb1
      USB INSTR: Available via PyUSB (1.0.0b1). Backend: libusb1
      GPIB INSTR:
         Please install linux-gpib to use this resource type.
         No module named gpib
      TCPIP SOCKET: Available 

Here's the error I get:

In [4]: rm.list_resources()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-4-a14d33fc6d00> in <module>()
----> 1 rm.list_resources()

/home/mj-ubuntu/anaconda/lib/python2.7/site-packages/pyvisa/highlevel.pyc in list_resources(self, query)
   1558         """
   1559 
-> 1560         return self.visalib.list_resources(self.session, query)
   1561 
   1562     def list_resources_info(self, query='?*::INSTR'):

/home/mj-ubuntu/anaconda/lib/python2.7/site-packages/pyvisa-py/highlevel.pyc in list_resources(self, session, query)
    230 
    231         resources = sum([st.list_resources()
--> 232                          for key, st in sessions.Session.iter_valid_session_classes()], [])
    233 
    234         query = query.replace('?*', '.*')

/home/mj-ubuntu/anaconda/lib/python2.7/site-packages/pyvisa-py/usb.pyc in list_resources()
    201                                   manufacturer_id=dev.idVendor,
    202                                   model_code=dev.idProduct,
--> 203                                   serial_number=dev.serial_number,
    204                                   usb_interface_number=intfc))
    205         return out

AttributeError: 'Device' object has no attribute 'serial_number'

gpib.interface.read() timeouts when reading single bytes

After "fixing" issue #73, executing the same code results in a timeout:

import visa
visa.log_to_screen()
rm = visa.ResourceManager('@py')
spectrum_analyzer = rm.open_resource('GPIB0::20::INSTR')
spectrum_analyzer.write("*IDN?")
print(spectrum_analyzer.read_raw())

returns

2015-12-15 16:10:52,693 - pyvisa - DEBUG - SerialSession was correctly imported.
2015-12-15 16:10:52,721 - pyvisa - DEBUG - USBSession and USBRawSession were correctly imported.
2015-12-15 16:10:52,727 - pyvisa - DEBUG - TCPIPSession was correctly imported.
2015-12-15 16:10:52,731 - pyvisa - DEBUG - GPIBSession was correctly imported.
2015-12-15 16:10:52,731 - pyvisa - DEBUG - Created library wrapper for unset
2015-12-15 16:10:52,731 - pyvisa - DEBUG - Created ResourceManager with session 8264632
2015-12-15 16:10:52,732 - pyvisa - DEBUG - GPIB0::20::INSTR - opening ...
2015-12-15 16:10:52,737 - pyvisa - DEBUG - GPIB0::20::INSTR - is open with session 3110499
2015-12-15 16:10:52,737 - pyvisa - DEBUG - GPIB.write b'*IDN?\r\n'
2015-12-15 16:10:52,746 - pyvisa - DEBUG - GPIB0::20::INSTR - reading 20480 bytes (last status <StatusCode.success_max_count_read: 1073676294>)

*** LONG PAUSE HERE (30s) ***

b'R'
2015-12-15 16:11:26,336 - pyvisa - DEBUG - GPIB0::20::INSTR - closing
2015-12-15 16:11:26,338 - pyvisa - DEBUG - GPIB0::20::INSTR - is closed
2015-12-15 16:11:26,344 - pyvisa - DEBUG - Closing ResourceManager (session: 8264632)

Appearantly, it reads a single byte and then stalls in https://github.com/hgrecco/pyvisa-py/blob/master/pyvisa-py/gpib.py#L126. Removing the '1' and changing this line to

reader = lambda: self.interface.read() # defaults to 512 bytes

seems to work so far.


My System:

python3 -m visa info
Machine Details:
   Platform ID:    Linux-4.2.6-201.fc22.x86_64+debug-x86_64-with-fedora-22-Twenty_Two
   Processor:      x86_64

Python:
   Implementation: CPython
   Executable:     /usr/bin/python3
   Version:        3.4.2
   Compiler:       GCC 5.1.1 20150618 (Red Hat 5.1.1-4)
   Bits:           64bit
   Build:          Jul  9 2015 17:24:30 (#default)
   Unicode:        UCS4

PyVISA Version: 1.8

Backends:
   ni:
      Version: 1.8 (bundled with PyVISA)
      Binary library: Not found
   py:
      Version: 0.3.dev0
      GPIB INSTR: Available via Linux GPIB (b'4.0.2')
      USB RAW: Available via PyUSB (1.0.0b2). Backend: libusb1
      USB INSTR: Available via PyUSB (1.0.0b2). Backend: libusb1
      ASRL INSTR: Available via PySerial (2.7)
      TCPIP SOCKET: Available 
      TCPIP INSTR: Available 

pyvisa-py is at current master (4c266c8, but modified as described in issue #73 ) and linux-gpib is version 4.0.2

Implementation error when using rm = visa.ResourceManager("@py")

I apologize in advance If I am in the wrong place but I am not sure if my problem is related to pyvisa or pyvisa-py. Under linux (Ubuntu 15.04), I am trying to play with pyvisa to communicate with a couple of instruments.

I have not problem using the backend '@SiM" and when I query the list of resources:
import visa
rm = visa.ResourceManager("@SiM")
print(rm.list_resources())

I have the following output:
('GPIB0::4::65535::INSTR', 'ASRL1::INSTR', 'ASRL2::INSTR', 'TCPIP0::localhost:4444::inst0::INSTR', 'GPIB0::8::65535::INSTR', 'USB0::0x1111::0x2222::0x1234::0::INSTR', 'GPIB0::9::65535::INSTR', 'ASRL3::INSTR', 'USB0::0x1111::0x2222::0x2468::0::INSTR', 'TCPIP0::localhost::10001::SOCKET', 'TCPIP0::localhost:3333::inst0::INSTR', 'ASRL4::INSTR', 'TCPIP0::localhost:1111::inst0::INSTR', 'USB0::0x1111::0x2222::0x4444::0::INSTR', 'TCPIP0::localhost:2222::inst0::INSTR', 'USB0::0x1111::0x2222::0x3692::0::INSTR', 'GPIB0::10::65535::INSTR')

However when I try to shift to '@py' I have an error about the implementation:
import visa
rm = visa.ResourceManager("@py")
print(rm.list_resources())

I have the error:
Traceback (most recent call last):
File "Try-Pyvisa.py", line 3, in
print(rm.list_resources())
File "/home/bizarri/bin/miniconda3/lib/python3.4/site-packages/pyvisa/highlevel.py", line 1560, in list_resources
return self.visalib.list_resources(self.session, query)
File "/home/bizarri/bin/miniconda3/lib/python3.4/site-packages/pyvisa/highlevel.py", line 669, in list_resources
raise NotImplementedError
NotImplementedError

I am kind of lost...
Here is the output when I query the visa information (python3 -m visa info)

Python:
Implementation: CPython
Executable: /home/bizarri/bin/miniconda3/bin/python3
Version: 3.4.3
Compiler: GCC 4.4.7 20120313 (Red Hat 4.4.7-1)
Bits: 64bit
Build: Jun 4 2015 15:29:08 (#default)
Unicode: UCS4

PyVISA Version: 1.7

Backends:
ni:
Version: 1.7 (bundled with PyVISA)
Binary library: Not found
py:
Version: 0.1
USB INSTR: Available via PyUSB (1.0.0b2). Backend: libusb1
TCPIP INSTR: Available
ASRL INSTR: Available via PySerial (N/A)
sim:
Version: 0.2
Spec version: 1.1

Any idea where I have to look for?

Thanks,

Greg

Struggling to get started with a NI GPIB-ENET/100

Hi, I'm on linux and was unable to get the official NI-VISA installed. I'm interested in using pyvisa-py to communicate with an Agilent power meter over an NI GPIB-ENET/100, which I believe is a VISA-compatible device.

NMAP is showing the device is responding:

$ nmap 192.168.1.232

Starting Nmap 6.40 ( http://nmap.org ) at 2015-06-09 12:33 MDT
Nmap scan report for 192.168.1.232
Host is up (0.024s latency).
Not shown: 998 closed ports
PORT     STATE SERVICE
5000/tcp open  upnp
5003/tcp open  filemaker

Nmap done: 1 IP address (1 host up) scanned in 13.47 seconds

However I can't seem to find the correct command string to open the resource.

enet100 = rm.open_resource('TCPIP::192.168.1.232::inst0::INSTR')
...
socket.error: [Errno 111] Connection refused

I could keep stabbing at it ad nauseam but I figured I'd check first and see: does pyvisa even work through a converter like the GPIB-ENET/100. If so, what kind of command string should I be testing?

Support for non-decimal numbers in device string, issue in return value of usb/get_attribute

Maybe I'm missing something but currently non-decimal device strings don't seem to be supported. This should be easily possible. Feel free to point out any issues with this.

the get_attribute() function in usb.py returns only one value if the attribute is unknown. This raises an error because it's obviously not iterable.
try:
return self._get_attribute(attribute), constants.StatusCode.success
except UnknownAttribute as e:
logger.exception(str(e))
return constants.StatusCode.error_nonsupported_attribute

Serial VISA device fails to open: TypeError: __init__() got an unexpected keyword argument 'writeTimeout'

On Ubuntu 14.04, fresh install:
pip3 install pyvisa pyvisa-py pyserial

>>> import visa
>>> rm = visa.ResourceManager("@py")
>>> rm.list_resources()
('ASRL/dev/ttyUSB0::INSTR',)
>>> dev = rm.open_resource(rm.list_resources()[0])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.4/dist-packages/pyvisa/highlevel.py", line 1644, in open_resource
    res.open(access_mode, open_timeout)
  File "/usr/local/lib/python3.4/dist-packages/pyvisa/resources/resource.py", line 203, in open
    self.session, status = self._resource_manager.open_bare_resource(self._resource_name, access_mode, open_timeout)
  File "/usr/local/lib/python3.4/dist-packages/pyvisa/highlevel.py", line 1601, in open_bare_resource
    return self.visalib.open(self.session, resource_name, access_mode, open_timeout)
  File "/usr/local/lib/python3.4/dist-packages/pyvisa-py/highlevel.py", line 191, in open
    sess = cls(session, resource_name, parsed)
  File "/usr/local/lib/python3.4/dist-packages/pyvisa-py/sessions.py", line 184, in __init__
    self.after_parsing()
  File "/usr/local/lib/python3.4/dist-packages/pyvisa-py/serial.py", line 68, in after_parsing
    self.interface = cls(port=self.parsed.board, timeout=2000, writeTimeout=2000)
TypeError: __init__() got an unexpected keyword argument 'writeTimeout'

Support for multiple GPIB controllers

At present, PyVISA-py (via Linux GPIB) only seems to support communication with a single GPIB controller. Is control via multiple GPIB controllers currently supported in PyVISA-py? If not, is there a consensus as to whether this would be a desirable feature?

GPIB devices can be daisy-chained together so that a single controller can communicate with up to fifteen devices. I would like to have multiple controllers connected (for example, a National Instruments GPIB PCI card and a National Instruments GPIB-USB-HS controller) in order to communicate with more than fifteen devices, if necessary. When I do this, the output of rm.list_resources(), where rm is an instance of visa.ResourceManager('@py'), lists only the GPIB devices connected to the controller I have designated as the 'system controller' (also known as 'controller-in-charge', 'CiC' or 'master controller') in /etc/gpib.conf (the configuration file of Linux GPIB). This would appear to be because rm.list_resources() calls gpib.listener(), which requires that the queried interface be the system controller.

For clarity, here is the output of python3 -m visa info. Note that the Linux GPIB version number is 4.0.0 (as you can see, I am using the latest stable release of PyVISA-py, 0.2, which doesn't report the Linux GPIB version number as the development version does):

Machine Details:
   Platform ID:    Linux-3.13.0-62-generic-x86_64-with-Ubuntu-14.04-trusty
   Processor:      x86_64

Python:
   Implementation: CPython
   Executable:     /usr/bin/python3
   Version:        3.4.0
   Compiler:       GCC 4.8.2
   Bits:           64bit
   Build:          Jun 19 2015 14:20:21 (#default)
   Unicode:        UCS4

PyVISA Version: 1.8

Backends:
   ni:
      Version: 1.8 (bundled with PyVISA)
      Binary library: Not found
   py:
      Version: 0.2
      TCPIP SOCKET: Available 
      USB RAW: Available via PyUSB (1.0.0b2). Backend: libusb1
      TCPIP INSTR: Available 
      USB INSTR: Available via PyUSB (1.0.0b2). Backend: libusb1
      GPIB INSTR: Available 
      ASRL INSTR: Available via PySerial (2.6)

Also, to avoid any confusion, here is gpib.conf:

/***********************************************************************
                 GPIB.CONF IEEE488 library config file
                             -------------------

   copyright            : (C) 2002 by Frank Mori Hess
                          (C) 1994 by C.Schroeter
   email                : [email protected]
 ***************************************************************************/
/***************************************************************************
 *    
 *   Syntax:
 *
 *         interface { ... } starts new interface board section
 *         device {...} device configuration
 *
 ***************************************************************************/

/* This section configures the configurable driver characteristics
 * for an interface board, such as board address, and interrupt level.
 * minor = 0 configures /dev/gpib0, minor = 1 configures /dev/gpib1, etc.
 */

interface {
    minor = 0   /* board index, minor = 0 uses /dev/gpib0, minor = 1 uses /dev/gpib1, etc. */
    board_type = "ni_pci"   /* type of interface board being used */
    pad = 0 /* primary address of interface             */
    master = yes    /* interface board is system controller */
}

interface {
    minor = 1   /* board index, minor = 0 uses /dev/gpib0, minor = 1 uses /dev/gpib1, etc. */
    board_type = "ni_usb_b" /* type of interface board being used */
    pad = 0 /* primary address of interface             */
    master = no /* interface board is system controller */
}

Interfacing an Keithley current amplifier via a NI GPIB/ENET 1000

Hi,

at first I have following setup of pyvisa:

Machine Details:
   Platform ID:    Linux-3.12.53-40-desktop-x86_64-with-SuSE-13.1-x86_64
   Processor:      x86_64

Python:
   Implementation: CPython
   Executable:     /usr/bin/python
   Version:        2.7.6
   Compiler:       GCC
   Bits:           64bit
   Build:          Nov 21 2013 15:55:38 (#default)
   Unicode:        UCS4

PyVISA Version: 1.8

Backends:
   ni:
       Version: 1.8 (bundled with PyVISA)
       Binary library: Not found
   py:
       Version: 0.2
       ASRL INSTR: Available via PySerial (3.0.1)
       TCPIP INSTR: Available 
       USB RAW: Available via PyUSB (1.0.0rc1). Backend: libusb1
       USB INSTR: Available via PyUSB (1.0.0rc1). Backend: libusb1
       GPIB INSTR: Available 
       TCPIP SOCKET: Available 

I'm trying to interface an Keithley current amplifier (gpib port 23) via a NI GPIB/ENET 1000.
As I understand from the manual I have to use to interface the ENET controller the "ASRL-String". The ENET controller is working with the IP 192.168.62.39 and Port 5000. Now I tried to connect to the Keithley via the enet with:

 import visa
 rm = visa.ResourceManager('@py')
 inst = rm.open_resource('ASRL23::192.168.62.39::5000::INSTR')

I got following error:

 Traceback (most recent call last):                                                                                  
   File "<stdin>", line 1, in <module>                                                                               
   File "/usr/lib64/python2.7/site-packages/pyvisa/highlevel.py", line 1626, in open_resource                        
   resource_pyclass = self._resource_classes[(info.interface_type, info.resource_class)]
 AttributeError: 'int' object has no attribute 'interface_type'

I'm completely new to gpib, pyvisa and pyvisa-py and I hope somebody can help. That would be great!
Thanks a lot!!!

RIGOL DM3068 TCP/IP ERROR IN LINUX

Hello,

I'm going crazy in order to communicate with the DMM pyvisa-py on TCPIP:

2015-08-20 00:09:39,056 - pyvisa - DEBUG - Created library wrapper for unset
2015-08-20 00:09:39,056 - pyvisa - DEBUG - Created ResourceManager with session 2052846
2015-08-20 00:09:39,056 - pyvisa - DEBUG - TCPIP0::192.168.1.144::INSTR - opening ...
2015-08-20 00:09:39,091 - pyvisa - DEBUG - TCPIP0::192.168.1.144::INSTR - is open with session 7697116
2015-08-20 00:09:39,106 - pyvisa - DEBUG - TCPIP0::192.168.1.144::INSTR - reading 20480 bytes (last status <StatusCode.success_max_count_read: 1073676294>)

2015-08-20 00:09:48,769 - pyvisa - DEBUG - TCPIP0::192.168.1.144::INSTR - closing
Exception NotImplementedError: NotImplementedError() in <bound method TCPIPInstrument.del of <'TCPIPInstrument'(u'TCPIP0::192.168.1.144::inst0::INSTR')>> ignored

the python script is this:

import visa
visa.log_to_screen()
rm = visa.ResourceManager("@py")
inst = rm.open_resource("TCPIP0::192.168.1.144::INSTR")
print(inst.query("*IDN?"))

I'm used Linux 64bit and WindowsXp with python 2.7 32bit, but the error is the same.
I sniffed the network traffic and does not receive the correct response, the protocol VXI11 reports a timeout error.
With original software and NI-VISA library work fine, not with PyVisa and the same NI-VISA.

This is the debug with last pyvisa-py and python3

2015-08-20 00:23:17,237 - pyvisa - DEBUG - SerialSession was correctly imported.
2015-08-20 00:23:17,254 - pyvisa - DEBUG - USBSession and USBRawSession were correctly imported.
2015-08-20 00:23:17,264 - pyvisa - DEBUG - TCPIPSession was not imported cannot import name 'TCPIPSession'.
2015-08-20 00:23:17,266 - pyvisa - DEBUG - GPIBSession was not imported No module named 'gpib'.
2015-08-20 00:23:17,267 - pyvisa - DEBUG - Created library wrapper for unset
2015-08-20 00:23:17,267 - pyvisa - DEBUG - Created ResourceManager with session 6265688
2015-08-20 00:23:17,267 - pyvisa - DEBUG - TCPIP0::192.168.1.144::INSTR - opening ...
2015-08-20 00:23:17,267 - pyvisa - DEBUG - RawTCPClient: connecting to socket at (192.168.1.144, 111)
2015-08-20 00:23:17,273 - pyvisa - DEBUG - Make call <PortMapperVersion.get_port: 3>, (395183, 1, 6, 0), '<bound method PortMapperPacker.pack_mapping of <pyvisa-py.protocols.rpc.PortMapperPacker object at 0x7fd5132b1ba8>>', '<bound method PortMapperUnpacker.unpack_uint of <pyvisa-py.protocols.rpc.PortMapperUnpacker object at 0x7fd5162ad048>>'
2015-08-20 00:23:17,273 - pyvisa - DEBUG - Sending record through <socket.socket fd=12, family=AddressFamily.AF_INET, type=SocketType.SOCK_STREAM, proto=0, laddr=('192.168.1.103', 59810), raddr=('192.168.1.144', 111)>: b'\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x02\x00\x01\x86\xa0\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x06\x07\xaf\x00\x00\x00\x01\x00\x00\x00\x06\x00\x00\x00\x00'
2015-08-20 00:23:17,283 - pyvisa - DEBUG - Received record through <socket.socket fd=12, family=AddressFamily.AF_INET, type=SocketType.SOCK_STREAM, proto=0, laddr=('192.168.1.103', 59810), raddr=('192.168.1.144', 111)>: b'\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02f'
2015-08-20 00:23:17,283 - pyvisa - DEBUG - RawTCPClient: closing socket
2015-08-20 00:23:17,283 - pyvisa - DEBUG - RawTCPClient: connecting to socket at (192.168.1.144, 614)
2015-08-20 00:23:17,290 - pyvisa - DEBUG - Make call 10, (411798420, 0, 10000, 'inst0'), '<bound method Vxi11Packer.pack_create_link_parms of <pyvisa-py.protocols.vxi11.Vxi11Packer object at 0x7fd5132cdf98>>', '<bound method Vxi11Unpacker.unpack_create_link_resp of <pyvisa-py.protocols.vxi11.Vxi11Unpacker object at 0x7fd5132cdd68>>'
2015-08-20 00:23:17,290 - pyvisa - DEBUG - Sending record through <socket.socket fd=12, family=AddressFamily.AF_INET, type=SocketType.SOCK_STREAM, proto=0, laddr=('192.168.1.103', 48346), raddr=('192.168.1.144', 614)>: b"\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x02\x00\x06\x07\xaf\x00\x00\x00\x01\x00\x00\x00\n\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x18\x8b\x8b\x94\x00\x00\x00\x00\x00\x00'\x10\x00\x00\x00\x05inst0\x00\x00\x00"
2015-08-20 00:23:17,302 - pyvisa - DEBUG - Received record through <socket.socket fd=12, family=AddressFamily.AF_INET, type=SocketType.SOCK_STREAM, proto=0, laddr=('192.168.1.103', 48346), raddr=('192.168.1.144', 614)>: b'\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02f\x00\x00\x04\x00'
2015-08-20 00:23:17,303 - pyvisa - DEBUG - TCPIP0::192.168.1.144::INSTR - is open with session 6559734
2015-08-20 00:23:17,303 - pyvisa - DEBUG - Make call 11, (0, 10000, 10000, 136, b'_IDN?\r\n'), '<bound method Vxi11Packer.pack_device_write_parms of <pyvisa-py.protocols.vxi11.Vxi11Packer object at 0x7fd5132cdf98>>', '<bound method Vxi11Unpacker.unpack_device_write_resp of <pyvisa-py.protocols.vxi11.Vxi11Unpacker object at 0x7fd5132cdd68>>'
2015-08-20 00:23:17,303 - pyvisa - DEBUG - Sending record through <socket.socket fd=12, family=AddressFamily.AF_INET, type=SocketType.SOCK_STREAM, proto=0, laddr=('192.168.1.103', 48346), raddr=('192.168.1.144', 614)>: b"\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x02\x00\x06\x07\xaf\x00\x00\x00\x01\x00\x00\x00\x0b\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'\x10\x00\x00'\x10\x00\x00\x00\x88\x00\x00\x00\x07_IDN?\r\n\x00"
2015-08-20 00:23:17,309 - pyvisa - DEBUG - Received record through <socket.socket fd=12, family=AddressFamily.AF_INET, type=SocketType.SOCK_STREAM, proto=0, laddr=('192.168.1.103', 48346), raddr=('192.168.1.144', 614)>: b'\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0b\x00\x00\x00\x00'
2015-08-20 00:23:17,309 - pyvisa - DEBUG - TCPIP0::192.168.1.144::INSTR - reading 20480 bytes (last status <StatusCode.success_max_count_read: 1073676294>)
2015-08-20 00:23:17,310 - pyvisa - DEBUG - Make call 12, (0, 1024, 10000, 10000, 0, 0), '<bound method Vxi11Packer.pack_device_read_parms of <pyvisa-py.protocols.vxi11.Vxi11Packer object at 0x7fd5132cdf98>>', '<bound method Vxi11Unpacker.unpack_device_read_resp of <pyvisa-py.protocols.vxi11.Vxi11Unpacker object at 0x7fd5132cdd68>>'
2015-08-20 00:23:17,310 - pyvisa - DEBUG - Sending record through <socket.socket fd=12, family=AddressFamily.AF_INET, type=SocketType.SOCK_STREAM, proto=0, laddr=('192.168.1.103', 48346), raddr=('192.168.1.144', 614)>: b"\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x02\x00\x06\x07\xaf\x00\x00\x00\x01\x00\x00\x00\x0c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00'\x10\x00\x00'\x10\x00\x00\x00\x00\x00\x00\x00\x00"
2015-08-20 00:23:26,962 - pyvisa - DEBUG - Received record through <socket.socket fd=12, family=AddressFamily.AF_INET, type=SocketType.SOCK_STREAM, proto=0, laddr=('192.168.1.103', 48346), raddr=('192.168.1.144', 614)>: b'\x00\x00\x00\x03\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0f\x00\x00\x00\x00\x00\x00\x00\x00'

2015-08-20 00:23:26,975 - pyvisa - DEBUG - TCPIP0::192.168.1.144::INSTR - closing
2015-08-20 00:23:26,975 - pyvisa - DEBUG - Make call 23, 0, '<bound method Vxi11Packer.pack_device_link of <pyvisa-py.protocols.vxi11.Vxi11Packer object at 0x7fd5132cdf98>>', '<bound method Vxi11Unpacker.unpack_device_error of <pyvisa-py.protocols.vxi11.Vxi11Unpacker object at 0x7fd5132cdd68>>'
2015-08-20 00:23:26,975 - pyvisa - DEBUG - Sending record through <socket.socket fd=12, family=AddressFamily.AF_INET, type=SocketType.SOCK_STREAM, proto=0, laddr=('192.168.1.103', 48346), raddr=('192.168.1.144', 614)>: b'\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x02\x00\x06\x07\xaf\x00\x00\x00\x01\x00\x00\x00\x17\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
2015-08-20 00:23:26,983 - pyvisa - DEBUG - Received record through <socket.socket fd=12, family=AddressFamily.AF_INET, type=SocketType.SOCK_STREAM, proto=0, laddr=('192.168.1.103', 48346), raddr=('192.168.1.144', 614)>: b'\x00\x00\x00\x04\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
2015-08-20 00:23:26,983 - pyvisa - DEBUG - RawTCPClient: closing socket
2015-08-20 00:23:26,983 - pyvisa - DEBUG - TCPIP0::192.168.1.144::INSTR - is closed
2015-08-20 00:23:26,987 - pyvisa - DEBUG - Closing ResourceManager (session: 6265688)

Best regards

With logging, lots of UnicodeDecodeError

When I enable logging at DEBUG level, pyvisa-py generates many UnicodeDecodeError :

Traceback (most recent call last):
  File "/usr/lib/python2.7/logging/__init__.py", line 859, in emit
    msg = self.format(record)
  File "/usr/lib/python2.7/logging/__init__.py", line 732, in format
    return fmt.format(record)
  File "/usr/lib/python2.7/logging/__init__.py", line 471, in format
    record.message = record.getMessage()
  File "/usr/lib/python2.7/logging/__init__.py", line 335, in getMessage
    msg = msg % self.args
UnicodeDecodeError: 'ascii' codec can't decode byte 0xde in position 35: ordinal not in range(128)
Logged from file rpc.py, line 324

Same thing at line 296 of rpc.py (in sendrecord()).

Error with Serial communication `serial.py`

Getting an error when trying to connect to a device using cp210x driver. Here's the output of the error. My best guess is it has something to do with /dev/ttyAMC0 existing while /DEV/TTYAMC0 definitely does not exist.

Python 2.7.8 (default, Oct 30 2014, 18:30:15)
[GCC 4.9.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import visa
>>> rm = visa.ResourceManager("@py")
>>> rm.list_resources()
(u'ASRL/dev/ttyACM0::INSTR',)
>>> inst = rm.open_resource("ASRL/dev/ttyACM0::INSTR")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/PyVISA-1.6.2.dev0-py2.7.egg/pyvisa/highlevel.py", line 1631, in open_resource
    res.open(access_mode, open_timeout)
  File "/usr/local/lib/python2.7/dist-packages/PyVISA-1.6.2.dev0-py2.7.egg/pyvisa/resources/resource.py", line 165, in open
    self.session, status = self._resource_manager.open_bare_resource(self._resource_name, access_mode, open_timeout)
  File "/usr/local/lib/python2.7/dist-packages/PyVISA-1.6.2.dev0-py2.7.egg/pyvisa/highlevel.py", line 1595, in open_bare_resource
    return self.visalib.open(self.session, resource_name, access_mode, open_timeout)
  File "pyvisa-py/highlevel.py", line 180, in open
    sess = cls(session, resource_name, parsed)
  File "pyvisa-py/sessions.py", line 156, in __init__
    self.after_parsing()
  File "pyvisa-py/serial.py", line 61, in after_parsing
    self.interface = serial.Serial(port=self.parsed['board'], timeout=2000, writeTimeout=2000)
  File "/usr/local/lib/python2.7/dist-packages/serial/serialutil.py", line 261, in __init__
    self.open()
  File "/usr/local/lib/python2.7/dist-packages/serial/serialposix.py", line 358, in open
    raise SerialException("could not open port %s,%s: %s" % (self._port, self.portstr, msg))
serial.serialutil.SerialException: could not open port /DEV/TTYACM0,/DEV/TTYACM0: [Errno 2] No such file or directory: '/DEV/TTYACM0'

Can't connect to usb instrument

I'm on:
Anaconda 2.1.0 (64 bit), Python 2.7.8 on Ubuntu 14.04
pyvisa 1.6.1.dev0 (updated today)
pyvisa-py 0.1.dev0
pyusb 1.0.0b1

I have a Keysight scope connected over USB.

rm.list_resources()
(u'USB0::10893::36894::Unknown::0::INSTR',)

scope = rm.open_resource('USB0::10893::36894::Unknown::0::INSTR')
....
/home/mj-ubuntu/anaconda/lib/python2.7/site-packages/pyvisa-py/protocols/usbtmc.pyc in init(self, vendor, product, serial_number, device_filters, timeout, **kwargs)
160 except usb.core.USBError as e:
161 #self.log_error("Could not set configuration")
--> 162 raise Exception('failed to set configuration')
163
164 self.usb_intf = self._find_interface(self.usb_dev, self.INTERFACE)

Exception: failed to set configuration

Any thoughts?

Problem with using "query" and 'write' method on raspberry pi2

I am using raspberry pi 2 with pyvisa to control Tektronix signal oscilloscope. The issue I got is I cannot use 'write' and 'query' methods and both of them gave the same error:

>>> inst.write('measu:meas1:source1 ch1')
>>> inst.query('measu:meas1:value?')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/pyvisa/resources/messagebased.py", line 187, in write
    count = self.write_raw(message.encode(enco))
  File "/usr/local/lib/python2.7/dist-packages/pyvisa/resources/messagebased.py", line 165, in write_raw
    return self.visalib.write(self.session, message)
  File "/usr/local/lib/python2.7/dist-packages/pyvisa-py/highlevel.py", line 281, in write
    return self.sessions[session].write(data)
  File "/usr/local/lib/python2.7/dist-packages/pyvisa-py/usb.py", line 117, in write
    count = self.interface.write(data)
  File "/usr/local/lib/python2.7/dist-packages/pyvisa-py/protocols/usbtmc.py", line 286, in write
    bytes_sent += raw_write(data)
  File "/usr/local/lib/python2.7/dist-packages/pyvisa-py/protocols/usbtmc.py", line 202, in write
    return self.usb_send_ep.write(data)
File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 349, in write
    return self.device.write(self, data, timeout)
  File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 878, in write
    self.__get_timeout(timeout)
  File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb1.py", line 760, in bulk_write
    timeout)
  File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb1.py", line 856, in __write
    _check(retval)
  File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb1.py", line 552, in _check
    raise USBError(_strerror(ret), ret, _libusb_errno[ret])
  File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb1.py", line 541, in _strerror
    return _lib.libusb_strerror(errcode).decode('utf8')
  File "/usr/lib/python2.7/ctypes/__init__.py", line 378, in __getattr__
    func = self.__getitem__(name)
  File "/usr/lib/python2.7/ctypes/__init__.py", line 383, in __getitem__
    func = self._FuncPtr((name_or_ordinal, self))
AttributeError: /lib/arm-linux-gnueabihf/libusb-1.0.so.0: undefined symbol: libusb_strerror

Error when trying to use query('*IDN?')

Hi there, I'm getting an error when just trying to query a device that is connected via USBTMC. Any help would be greatly appreciated.

Python 2.7.3 (default, Mar 18 2014, 05:13:23)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import visa
>>> rm = visa.ResourceManager("@py")
>>> rm.list_resources()
(u'USB0::62701::60986::Unknown::0::INSTR',)
>>> inst = rm.open_resource('USB0::62701::60986::Unknown::0::INSTR')
>>> inst.query('*idn?')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/PyVISA-1.6.2.dev0-py2.7.egg/pyvisa/resources/messagebased.py", line 378, in query
    self.write(message)
  File "/usr/local/lib/python2.7/dist-packages/PyVISA-1.6.2.dev0-py2.7.egg/pyvisa/resources/messagebased.py", line 184, in write
    count = self.write_raw(message.encode(enco))
  File "/usr/local/lib/python2.7/dist-packages/PyVISA-1.6.2.dev0-py2.7.egg/pyvisa/resources/messagebased.py", line 162, in write_raw
    return self.visalib.write(self.session, message)
  File "pyvisa-py/highlevel.py", line 309, in write
    return self.sessions[session].write(data)
  File "pyvisa-py/usb.py", line 120, in write
    count = self.interface.write(data)
  File "pyvisa-py/protocols/usbtmc.py", line 292, in write
    data = BulkOutMessage.build_array(self._btag, end > size, data[begin:end])
  File "pyvisa-py/protocols/usbtmc.py", line 72, in build_array
    chunk + \
TypeError: Struct() argument 1 must be string, not unicode
>>> from pyvisa import util
>>> util.get_debug_info()
Machine Details:
   Platform ID:    Linux-3.12.33+-armv6l-with-debian-7.6
   Processor:

Python:
   Implementation: CPython
   Executable:     /usr/bin/python
   Version:        2.7.3
   Compiler:       GCC 4.6.3
   Bits:           32bit
   Build:          Mar 18 2014 05:13:23 (#default)
   Unicode:        UCS4

PyVISA Version: 1.6.2.dev0

Backends:
   ni:
      Version: 1.6.2.dev0 (bundled with PyVISA)
      Binary library: Not found
   py:
      Version: 0.1.dev0
      ASRL INSTR: Available via PySerial (N/A)
      TCPIP INSTR: Available
      USB INSTR: Available via PyUSB (1.0.0rc1). Backend: libusb1
   sim:
      Does not provide debug info

Pipe error with controlling Tektronix MSO4034

I got a very strange error in controlling the Tektronix oscilloscope via PyVISA. Right now, I can only run six lines of command after getting it connected with raspberry pi 2. What I mean connected is that after I write the command "inst = rm.open_resource(rm.list_resources()[0])" in python interrupter. After whatever six lines of command, the pipe error appears in the following:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/pyvisa/resources/messagebased.py", line 187, in write
    count = self.write_raw(message.encode(enco))
  File "/usr/local/lib/python2.7/dist-packages/pyvisa/resources/messagebased.py", line 165, in write_raw
    return self.visalib.write(self.session, message)
  File "/usr/local/lib/python2.7/dist-packages/pyvisa-py/highlevel.py", line 281, in write
    return self.sessions[session].write(data)
  File "/usr/local/lib/python2.7/dist-packages/pyvisa-py/usb.py", line 117, in write
    count = self.interface.write(data)
  File "/usr/local/lib/python2.7/dist-packages/pyvisa-py/protocols/usbtmc.py", line 286, in write
    bytes_sent += raw_write(data)
  File "/usr/local/lib/python2.7/dist-packages/pyvisa-py/protocols/usbtmc.py", line 204, in write
    raise ValueError(str(e))
ValueError: [Errno 32] Pipe error

I have to re-enable the USB connection on the signal oscilloscope to get it working again.

Import of OrderedDict fails

In highlevel.py

from pyvisa.compat import integer_types, OrderedDict

throws an exception (OrderedDict is not defined). Shouldn't it be:

from pyvisa.compat import integer_types
from collections import OrderedDict

?

Problem with TCPIP HISLIP connection

I can connect to my Keysight scope on Ubuntu over LAN using inst0 but I get the following error when trying to use hislip0:

In [5]: scope = rm.open_resource("TCPIP0::141.121.97.63::hislip0::INSTR")
---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
<ipython-input-5-7399acaeaf7f> in <module>()
----> 1 scope = rm.open_resource("TCPIP0::141.121.97.63::hislip0::INSTR")

/home/mj-ubuntu/anaconda/lib/python2.7/site-packages/pyvisa/highlevel.pyc in open_resource(self, resource_name, access_mode, open_timeout, resource_pyclass, **kwargs)
   1642                 raise ValueError('%r is not a valid attribute for type %s' % (key, res.__class__.__name__))
   1643 
-> 1644         res.open(access_mode, open_timeout)
   1645 
   1646         for key, value in kwargs.items():

/home/mj-ubuntu/anaconda/lib/python2.7/site-packages/pyvisa/resources/resource.pyc in open(self, access_mode, open_timeout)
    201         logger.debug('%s - opening ...', self._resource_name, extra=self._logging_extra)
    202         with self._resource_manager.ignore_warning(constants.VI_SUCCESS_DEV_NPRESENT):
--> 203             self.session, status = self._resource_manager.open_bare_resource(self._resource_name, access_mode, open_timeout)
    204 
    205             if status == constants.VI_SUCCESS_DEV_NPRESENT:

/home/mj-ubuntu/anaconda/lib/python2.7/site-packages/pyvisa/highlevel.pyc in open_bare_resource(self, resource_name, access_mode, open_timeout)
   1599         :return: Unique logical identifier reference to a session.
   1600         """
-> 1601         return self.visalib.open(self.session, resource_name, access_mode, open_timeout)
   1602 
   1603     def open_resource(self, resource_name,

/home/mj-ubuntu/anaconda/lib/python2.7/site-packages/pyvisa-py/highlevel.pyc in open(self, session, resource_name, access_mode, open_timeout)
    189         cls = sessions.Session.get_session_class(parsed.interface_type_const, parsed.resource_class)
    190 
--> 191         sess = cls(session, resource_name, parsed)
    192 
    193         return self._register(sess), constants.StatusCode.success

/home/mj-ubuntu/anaconda/lib/python2.7/site-packages/pyvisa-py/sessions.pyc in __init__(self, resource_manager_session, resource_name, parsed)
    182                       constants.VI_ATTR_RSRC_CLASS: parsed.resource_class,
    183                       constants.VI_ATTR_INTF_TYPE: parsed.interface_type}
--> 184         self.after_parsing()
    185 
    186     def after_parsing(self):

/home/mj-ubuntu/anaconda/lib/python2.7/site-packages/pyvisa-py/tcpip.pyc in after_parsing(self)
     60 
     61         if error:
---> 62             raise Exception("error creating link: %d" % error)
     63 
     64         self.link = link

Exception: error creating link: 3

This is my setup:

mj-ubuntu@Austin-Compaq-8510p:~$ python -m visa info
Machine Details:
   Platform ID:    Linux-3.13.0-63-generic-x86_64-with-debian-jessie-sid
   Processor:      x86_64

Python:
   Implementation: CPython
   Executable:     /home/mj-ubuntu/anaconda/bin/python
   Version:        2.7.10
   Compiler:       GCC 4.4.7 20120313 (Red Hat 4.4.7-1)
   Bits:           64bit
   Build:          May 28 2015 17:02:03 (#default)
   Unicode:        UCS4

PyVISA Version: 1.8

Backends:
   ni:
      Version: 1.8 (bundled with PyVISA)
      Binary library: Not found
   py:
      Version: 0.3.dev0
      ASRL INSTR: Available via PySerial (2.7)
      TCPIP INSTR: Available 
      USB RAW: Available via PyUSB (1.0.0b2). Backend: libusb1
      USB INSTR: Available via PyUSB (1.0.0b2). Backend: libusb1
      GPIB INSTR:
         Please install linux-gpib to use this resource type.
         No module named gpib
      TCPIP SOCKET: Available 
   sim:
      Version: 0.3
      Spec version: 1.1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.