pyvisa / pyvisa-py

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

Closing an ASRL instrument, and resource manager, faults other unrelated USB serial devices #321

Closed GrantRolls closed 8 months ago

GrantRolls commented 2 years ago

Closing an ASRL instrument, and resource manager, faults other unrelated USB serial devices. Once opened and closed - the other devices can only be used again by re-opening the instrument, then re-opening the serial port

ttyUSB0 is an un-related serial-to-uart device ttyACM0 is the instrument being controlled

('ASRL/dev/ttyUSB0::INSTR', 'ASRL/dev/ttyACM0::INSTR')

To Reproduce

Steps to reproduce the behavior:

Scenario one; Opening and closing instrument

  1. Open serial device, send/receive data OK self._port = serial.Serial(port, baudrate=baudrate, timeout=0.1)
  2. Open instrument using self.inst = self._rm.open_resource("ASRL" + port + "::INSTR")
  3. With opened serial device, send/receive data OK
  4. Close instrument using self.inst.close()
  5. With opened serial device, send data OK, no data received
  6. Close serial device
  7. Open serial device, send data OK, no data received self._port = serial.Serial(port, baudrate=baudrate, timeout=0.1)

Scenario two; Opening serial port while instrument opened, then closing instrument

  1. Open instrument using self.inst = self._rm.open_resource("ASRL" + port + "::INSTR")
  2. Open serial device, send/receive data OK self._port = serial.Serial(port, baudrate=baudrate, timeout=0.1)
  3. Close instrument using self.inst.close()
  4. With opened serial device, send/receive data OK

Output of pyvisa-info

  Machine Details:
     Platform ID:    Linux-4.19.94-ti-r42-armv7l-with-debian-10.3
     Processor:

  Python:
     Implementation: CPython
     Executable:     /usr/bin/python3
     Version:        3.7.3
     Compiler:       GCC 8.3.0
     Bits:           32bit
     Build:          Dec 20 2019 18:57:59 (#default)
     Unicode:        UCS4

  PyVISA Version: 1.11.3

  Backends:
     ivi:
        Version: 1.11.3 (bundled with PyVISA)
        Binary library: Not found
     py:
        Version: 0.5.1
        ASRL INSTR: Available via PySerial (3.5)
        USB INSTR: Available via PyUSB (1.2.1). Backend: libusb1
        USB RAW: Available via PyUSB (1.2.1). Backend: libusb1
        TCPIP INSTR: Available
        TCPIP SOCKET: Available
        GPIB INSTR:
           Please install linux-gpib (Linux) or gpib-ctypes (Windows, Linux) to use this resource type. Note that installing gpib-ctypes will give you access to a broader range of funcionality.
           No module named 'gpib'
MatthieuDartiailh commented 2 years ago

Can you try to reproduce using only pyserial ? if you look at serial.py in pyvisa-py you will see that closing an instrument simply calls serial.Serial.close and I fail to see how pyvisa-py messes things up.