question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[COM] Communication issue with HP3577A using GPIB and VISA

See original GitHub issue

I use a HP3577 connected via a genuine NI USB-GPIB-HS adapter to my host PC. It used to work last week, then I suddenly couldn’t run my scripts any more. I noticed that even a minimal code:

import pyvisa as visa

rm = visa.ResourceManager()
print(rm)
hp = rm.open_resource('GPIB0::11::INSTR')
print(hp)
hp.write('AB4')

Caused the issue:

Resource Manager of Visa Library at C:\WINDOWS\system32\visa32.dll
GPIBInstrument at GPIB0::11::0::INSTR
Traceback (most recent call last):

  File "D:\Github_Sixtimesseven\VisaInstruments\Simplevisa\SimpleVisa\untitled0.py", line 14, in <module>
    hp.write('AB4')

  File "C:\Users\justrandom\anaconda3\envs\ba21\lib\site-packages\pyvisa\resources\messagebased.py", line 197, in write
    count = self.write_raw(message.encode(enco))

  File "C:\Users\justrandom\anaconda3\envs\ba21\lib\site-packages\pyvisa\resources\messagebased.py", line 157, in write_raw
    return self.visalib.write(self.session, message)[0]

  File "C:\Users\justrandom\anaconda3\envs\ba21\lib\site-packages\pyvisa\ctwrapper\functions.py", line 2796, in write
    ret = library.viWrite(session, data, len(data), byref(return_count))

  File "C:\Users\justrandom\anaconda3\envs\ba21\lib\site-packages\pyvisa\ctwrapper\highlevel.py", line 222, in _return_handler
    return self.handle_return_value(session, ret_value)  # type: ignore

  File "C:\Users\justrandom\anaconda3\envs\ba21\lib\site-packages\pyvisa\highlevel.py", line 251, in handle_return_value
    raise errors.VisaIOError(rv)

VisaIOError: VI_ERROR_TMO (-1073807339): Timeout expired before operation completed.

Causes the instrument to go into remote and lock up (power cycle required), it does not set average mode 4 (AB4 command) which is tested and should work and has worked last week. I tried another instrument and it was not working as well (Keithley 238).

I tried another PC and uninstalling visa and the 488-2 drivers. I reinstalled the oldest (17.6) version and updated pyvisa (it was already up to date). Right now I can talk to the other instruments but the HP3577 locks up as before.

Instrument details

  • Model: HP3577A
  • Communication: GPIB
  • Link to the documentation (if available): https://www.pearl-hifi.com/06_Lit_Archive/15_Mfrs_Publications/20_HP_Agilent/HP_3577A_3-Chan_VNA/HP_3577A_Operators.pdf

Output of pyvisa-info

C:\Users\justrandom\anaconda3\envs\ba21\lib\site-packages\gpib_ctypes\gpib\gpib.py:54: UserWarning: GPIB library not found. Please manually load it using _load_lib(filename). All GPIB functions will raise OSError until the library is manually loaded.
  warnings.warn(message)
Machine Details:
   Platform ID:    Windows-10-10.0.19042-SP0
   Processor:      AMD64 Family 23 Model 113 Stepping 0, AuthenticAMD

Python:
   Implementation: CPython
   Executable:     C:\Users\justrandom\anaconda3\envs\ba21\python.exe
   Version:        3.9.7
   Compiler:       MSC v.1916 64 bit (AMD64)
   Bits:           64bit
   Build:          Sep 23 2021 07:24:41 (#default)
   Unicode:        UCS4

PyVISA Version: 1.11.3

Backends:
   ivi:
      Version: 1.11.3 (bundled with PyVISA)
      #1: C:\WINDOWS\system32\visa32.dll:
         found by: auto
         bitness: 64
         Vendor: National Instruments
         Impl. Version: National Instruments
         Spec. Version: National Instruments
      #2: C:\WINDOWS\system32\visa64.dll:
         found by: auto
         bitness: 64
         Vendor: National Instruments
         Impl. Version: National Instruments
         Spec. Version: National Instruments
   py:
      Version: 0.5.2
      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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:20 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
sixtemessevencommented, Dec 14, 2021

Well, hmm. I’m pretty sure I rebooted the instrument yesterday. Maybe I did not open a new spyder console… I did unplug and change the gpio adapter usb location (usb 2 to usb 3). Not sure why but now it seems to be working.

Test script:

import pyvisa as visa

rm = visa.ResourceManager()
print(rm)
hp = rm.open_resource('GPIB0::11::INSTR')
#hp.read_termination = "\r\n"
#hp.write_termination = "\r\n"
print(hp)
hp.write('IPR')

My fix in resource.py line 162

        self._resource_name: str
        try:
            # Attempt to normalize the resource name. Can fail for aliases
            self._resource_name = str(rname.ResourceName.from_string(resource_name))
            position = self._resource_name.find("::0")
            self._resource_name = self._resource_name[0: position:] + self._resource_name[(position+2) + 1::]
        except rname.InvalidResourceName:
            self._resource_name = resource_name

Not that great but it works…

0reactions
sixtemessevencommented, Jan 30, 2022

Thanks for the confirmation. It is very nice to know that the resource name is truly in cause here.

Ideally, a fix should be applied in the GPIB resource name class to omit the secondary address when it is irrelevant. Given how the code is currently working, it may not be exactly obvious how to fix it, but feel free to have a look and make a PR if you have time. Otherwise, I will try to get to it ASAP, but I would appreciate if you could test the patch.

Sure, if I find some time first I will look into it. Otherwise I would be happy to test your patch.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can I use a GPIB-USB-B to talk to a HP3577A Network analizer
Hello, We have a GPIB-USB-B which we used on a project several years ago on another instrument. We now want to be able...
Read more >
Mobile friendly online documentation · Issue #2 - GitHub
No bitness for NI-VISA backend in Mac OS #122 ... [COM] Communication issue with HP3577A using GPIB and VISA #640.
Read more >
Troubleshooting GPIB Interface - MATLAB & Simulink
GPIB support in MATLAB ® is provided through the VISA-GPIB interface. Issue. If you are having trouble connecting to or communicating with your...
Read more >
How can I make NI LabVIEW communicate with my 82357A ...
When using NI LabVIEW, it is not always necessary to install NI-VISA. ... Turn the instrument on and ensure that it is configured...
Read more >
VENABLE WINDOWS VERSION 4.5 RLC SOFTWARE AND ...
Installation Procedure for use with GPIB Adapter . ... If any problem occurs with the Venable software attempting to communicate to the.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found