pyvisa / pyvisa-py

A pure python PyVISA backend
https://pyvisa-py.readthedocs.io
MIT License
288 stars 124 forks source link

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

Open iliis opened 8 years ago

iliis commented 8 years ago

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 (4c266c8bdfd021e2f0b6b1cd33556a759bcf982c, but modified as described in issue #73 ) and linux-gpib is version 4.0.2

iliis commented 8 years ago

I forgot to mention that ibtest shows the same behaviour: The first call to read works fine, but the second one results in a timeout, even tough the first read call didn't consume everything. Maybe all I have to do is somehow enable caching in linux-gpib?