From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Error thrown with Pyvisa due to gpib_ctypes?

Hi,

I'm using python to talk to instruments over GPIB. My full script runs successfully, but I always get an error thrown in the python window at the very end of the run. I truncated my code to just the root of the issue, shown below. The error is also shown. Due to the error type, I've tried closing all my instruments and types, but no success. The error thrown is the same with and without the bottom portion of the code.

 

Also, I wasn't able to successfully talk to the instruments without the make_default_gpib() command. Calling this solved my issues, so it seems to be required for me.

 

import visa
import gpib_ctypes

from gpib_ctypes import make_default_gpib
make_default_gpib()

rm = visa.ResourceManager("C:\\Windows\\System32\\visa32.dll")
instr = rm.open_resource("GPIB0::5::INSTR")

Everything Below is code added to try to solve the issue
#Issue exist with and without below code
instr.__del__()
instr.close()
rm.close()
del instr
rm.__del__()
del rm

Error:

Exception ignored in: <function Gpib.__del__() at 0x02f60bb8>
Traceback (most recent call last):
     File "C:\Python37-32\lib\site-packages\gpib_ctypes\Gpib.py", line 37, in __del__
     File "C:\Python37-32\lib\site-packages\gpib_ctypes\gpib\gpib.py", line 230, in close
gpib_ctypes.gpib.gpib.GpibError: close() error: Iberr 23, invalid handle

Any help is greatly appreciated.

0 Kudos
Message 1 of 4
(4,792 Views)

 

This error seems to be related to a mismatch of handles passed into that specific function. From the NI Error Documentation:

 

EHDL(23)

Error Condition: Input Handle is invalid.

Possible Cause: Several GPIB commands take in the input handle of the board or the device as an input parameter which can be the source of this error. This error can occur under several circumstances. Some scenarios are listed below:

  • A valid board handle is passed in as a device handle parameter or vice versa.
  • An invalid board or device descriptor is passed as input to any NI-488.2 function.
  • A board id outside the range of 0-99 is passed in to a traditional NI-488.2 board-level function or NI-488.2 routine
    ibconfig or ibmask is called with a device unit descriptor and a board-only configuration option, or with a board unit descriptor and a device-only configuration option.

Solutions:

  • Check to see if the device-level and board-level functions are not mixed up when calling the respective functions.
  • Also check if the board index passed to the NI 488.2 call is a valid index number.

 

Hope this helps,

Claire C.
AppSW Staff Product Support Engineer
National Instruments
CLD|CTD
0 Kudos
Message 2 of 4
(4,747 Views)

The script still runs properly and completes. It's only as python closes that I see the error thrown.  How does Python and pyVisa close? It seems to call a deconstructor that I either use incorrectly or it has a bug. 

0 Kudos
Message 3 of 4
(4,745 Views)

If you want to look at the exact way this closes, you can look into this at the PyVISA GitHub, but as PyVISA itself is an open-source wrapper and not an NI product, I'm not going to be the best resource on this. If you think that this is a bug, you can report it at https://github.com/pyvisa/pyvisa/issues.

Claire C.
AppSW Staff Product Support Engineer
National Instruments
CLD|CTD
0 Kudos
Message 4 of 4
(4,732 Views)