pyvisa-py: TCP Socket connection: Issuing a query after a query that has timed out causes the previous result to be returned

If I issue a query that times out, and then issue a second query, that second query incorrectly returns the result from the first (timedout) query. The same test works fine when using the Keysight IVI backend.

To reproduce:

  • Set instrument timeout to 5 seconds
  • *RST
  • *OPC? <-- The *RST takes about 10 seconds so *OPC? times out after 5 seconds as expected
  • Wait 20 seconds to ensure that the *RST has completed
  • IDN?

The problem is that *IDN? returns ‘1’ which is the result from the *OPC? query. When using the Keysight IVI backend the *IDN? correctly returns ‘Keysight Technologies,C8700200A Test Application Framework,US12345678,20.90.0.9010’

Instrument details:

  • Keysight 5GNR Test Application Framework
  • Communication: TCP Socket

Code:

from datetime import datetime
import time
import pyvisa


def debug(*args):
    print(datetime.now(), *args)


rm = pyvisa.ResourceManager('@py')    # If I remove '@py' then it works i.e. *IDN? returns the instrument name
instrument = rm.open_resource('TCPIP0::127.0.0.1::5125::SOCKET')
instrument.timeout = 5000   # Small value to make *OPC? timeout
instrument.read_termination = '\n'

try:
    debug('Calling *RST')
    instrument.write('*RST')
    debug('Calling *OPC?')
    instrument.query('*OPC?')
except Exception as ex:
    debug(ex)

time.sleep(20)

debug('Calling *IDN?')
result = instrument.query('*IDN?')
debug('Result:', result)

Incorrect result using pyvisa-py backend:

2023-06-05 09:48:28.934000 Calling *RST 
2023-06-05 09:48:28.934000 Calling *OPC?
2023-06-05 09:48:33.989677 VI_ERROR_TMO (-1073807339): Timeout expired before operation completed.
2023-06-05 09:48:53.993221 Calling *IDN?
2023-06-05 09:48:53.995160 Result: 1   

Correct result using Keysight IVI backend (simply removing ‘@py’ from the ResourceManager constructor):

2023-06-05 09:55:28.857054 Calling *RST 
2023-06-05 09:55:28.858046 Calling *OPC?
2023-06-05 09:55:33.881024 VI_ERROR_TMO (-1073807339): Timeout expired before operation completed.
2023-06-05 09:55:53.892010 Calling *IDN?
2023-06-05 09:55:53.894488 Result: Keysight Technologies,C8700200A Test Application Framework,US12345678,20.90.0.9010

Output of pyvisa-info

Machine Details:
   Platform ID:    Windows-10-10.0.19044-SP0
   Processor:      Intel64 Family 6 Model 141 Stepping 1, GenuineIntel

Python:
   Implementation: CPython
   Executable:     C:\Program Files\Python38\python.exe
   Version:        3.8.16
   Compiler:       MSC v.1900 64 bit (AMD64)
   Bits:           64bit
   Build:          Dec 20 2022 23:15:53 (#default)
   Unicode:        UCS4

PyVISA Version: 1.13.0

Backends:
   ivi:
      Version: 1.13.0 (bundled with PyVISA)
      #1: C:\Windows\system32\visa32.dll:
         found by: auto
         bitness: 64
         Vendor: Keysight Technologies
         Impl. Version: 1377199637
         Spec. Version: 5244928
      #2: C:\Windows\system32\visa64.dll:
         found by: auto
         bitness: 64
         Vendor: Keysight Technologies
         Impl. Version: 1377199637
         Spec. Version: 5244928
   py:
      Version: 0.7.0
      TCPIP INSTR: Available
         Resource discovery:
         - VXI-11: partial (psutil not installed)
         - hislip: disabled (zeroconf not installed)
      TCPIP SOCKET: Available
      ASRL INSTR:
         Please install PySerial (>=3.0) to use this resource type.
         No module named 'serial'
      USB INSTR:
         Please install PyUSB to use this resource type.
         No module named 'usb'
      USB RAW:
         Please install PyUSB to use this resource type.
         No module named 'usb'
      VICP INSTR:
         Please install PyVICP to use this resource type.
      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 functionalities.
         No module named 'gpib'
      GPIB INTFC:
         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 functionalities.
         No module named 'gpib'

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 35 (21 by maintainers)

Commits related to this issue

Most upvoted comments

And: packet_capture_pyvisa-py_backend_hislip.zip

Output:

2023-06-09 14:03:01.537317 Calling *RST 
2023-06-09 14:03:01.538305 Calling *OPC?
2023-06-09 14:03:06.539939 VI_ERROR_TMO (-1073807339): Timeout expired before operation completed.
2023-06-09 14:03:26.541905 Calling *IDN?
2023-06-09 14:03:26.543428 Result: 1 

Sure @arr-ee, here you go: packet_capture_keysight_backend_hislip.zip

Let me know if I can help further.