tivek / gpib_ctypes

GNU General Public License v2.0
14 stars 4 forks source link

Error thrown with Pyvisa due to gpib_ctypes? #1

Open mb711 opened 5 years ago

mb711 commented 5 years ago

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.

tivek commented 5 years ago

Hi @mb711,

I am currently without access to my GPIB equipment and this will require some playing around. Off the cuff I would say you don't need gpib_ctypes since you are using native VISA. (Nevertheless, I will have to test this configuration ASAP...)

Please change the order of commands so that make_default_gpib() gets a chance to run before VISA is initialized.

from gpib_ctypes import make_default_gpib
make_default_gpib()

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

Does this change anything?

tivek commented 5 years ago

@mb711, did you have a chance to try the above suggestion? Any results with that?

tivek commented 5 years ago

This seems to be a douvle-close bug similar to https://github.com/pyvisa/pyvisa-py/pull/171. What confuses me is that you seem to be using the NI backend and I am not sure what that has got to do with gpib-ctypes...

tivek commented 5 years ago

I am going to close the issue for now. @mb711, if the problem persists please feel free to reopen it and let me know if the above suggestions make any difference.

francis60k commented 5 years ago

Hi, I have the similar problem. Here is my source code.

2019-07-12_135559

Error:

2019-07-12_135620

I also try the solution you said, but it also show the error for me. How can I do next? Thanks

tivek commented 5 years ago

@francis60k, thank you for the report. I am going to look into it.