tivek / gpib_ctypes Goto Github PK
View Code? Open in Web Editor NEWLicense: GNU General Public License v2.0
License: GNU General Public License v2.0
Currently gpib_ctypes follows closely what is provided by linux-gpib. However some functions required to implement low level operations in pyvisa-py are missing. Currently the missing function that I believe are required are the following:
I am not sure what is the best way to address this. I feel like we could add those and then it is up to users to know that there are departing from linux-gpib provided wrapper. I can probably find the time to put together a PR, if there is an interest.
Do you plan to support NI 488.2 API?
It seems that gpib on windows/python only work on 32bit systems.
I installed latest NI 488.2 package and tried _load_lib() on ni4882.dll but seems some functions have changed:
https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z0000019NVJSA2
I used GPIB-USB-HS and it was detected on NI MAX.
I have found a bug in the gpib-ctypes loading of DLL’s. It will fail if gpib-32.dll contains dependencies to other DLL’s outside the system32 directory.
For example the “Keysight_Instrument_Control_Bundle” installs the following files:
C:\Windows\System32\gpib-32.dll
C:\Program Files\Keysight\IO Libraries Suite\bin\ioPersistedDataAccess.dll
But ctypes calls LoadLibraryEx with dwFlags=LOAD_LIBRARY_SEARCH_DEFAULT_DIRS causing it to fail to load the ioPersistedDataAccess.dll since it is not in the System32 folder.
One solution is to set winmode=0 in ctypes like this:
_lib = ctypes.WinDLL(libname, winmode = 0)
My code changes are:
diff --git "a/gpib_orig.py" "b/gpib.py"
index 64bb0e8..b822ebc 100644
--- "a/gpib_orig.py"
+++ "b/gpib.py"
@@ -32,15 +32,16 @@ def _load_lib(filename=None):
'c:\\windows\\system\\gpib-32.dll',
'c:\\gpib\\gpib-32.dll',
'gpib-32.so', 'libgpib.so.0']
- loader = ctypes.windll.LoadLibrary
else:
# most likely Linux with linux-gpib
libnames = [filename] if filename else ['libgpib.so.0', 'gpib-32.so']
- loader = ctypes.cdll.LoadLibrary
for libname in libnames:
try:
- _lib = loader(libname)
+ if platform.system() == "Windows":
+ _lib = ctypes.WinDLL(libname, winmode = 0)
+ else:
+ _lib = ctypes.cdll.LoadLibrary(libname)
break
except OSError:
continue
Hi,
I am currently trying to communicate with Keysight 35670A via GPIB. The test code is as follows:
from gpib_ctypes import make_default_gpib
make_default_gpib()
import visa
#rm = visa.ResourceManager('@py')
rm = visa.ResourceManager()
rm.list_resources()
fta = rm.open_resource('GPIB0::15::INSTR')
fta.query("*IDN?")
# Send *IDN? and read the response
fta.write('*IDN?')
idn = fta.read()
print('DEVICE INDENTIFIED AS: %s' % idn.rstrip('\n'))
I am not 100% sure if the error emanates from gbip_cytpes, bear with me if this is the wrong place to inquire.
I get the following error:
libgpib: ibBoardOpen failed to open device file /dev/gpib0
libgpib: No such file or directory
libgpib: error in is_cic()!
Traceback (most recent call last):
File "/home/galefang/eclipse-workspace/Keysight/src/GPIBtest.py", line 21, in
fta = rm.open_resource('GPIB0::15::INSTR')
File "/usr/local/lib/python3.7/dist-packages/pyvisa/highlevel.py", line 1771, in open_resource
res.open(access_mode, open_timeout)
File "/usr/local/lib/python3.7/dist-packages/pyvisa/resources/resource.py", line 218, in open
self.session, status = self._resource_manager.open_bare_resource(self._resource_name, access_mode, open_timeout)
File "/usr/local/lib/python3.7/dist-packages/pyvisa/highlevel.py", line 1725, in open_bare_resource
return self.visalib.open(self.session, resource_name, access_mode, open_timeout)
File "/usr/local/lib/python3.7/dist-packages/pyvisa-py/highlevel.py", line 194, in open
sess = cls(session, resource_name, parsed, open_timeout)
File "/usr/local/lib/python3.7/dist-packages/pyvisa-py/sessions.py", line 213, in init
self.after_parsing()
File "/usr/local/lib/python3.7/dist-packages/pyvisa-py/gpib.py", line 74, in after_parsing
self.interface = Gpib(name=minor, pad=pad, sad=sad, timeout=timeout, send_eoi=send_eoi, eos_mode=eos_mode)
File "/usr/local/lib/python3.7/dist-packages/gpib_ctypes/Gpib.py", line 31, in init
self.id = gpib.dev(name, pad, sad, timeout, send_eoi, eos_mode)
File "/usr/local/lib/python3.7/dist-packages/gpib_ctypes/gpib/gpib.py", line 303, in dev
raise GpibError("dev")
gpib_ctypes.gpib.gpib.GpibError: dev() error: Errno 9, Bad file descriptor
My pyvisa-info
returns;
Machine Details:
Platform ID: Linux-5.3.0-29-generic-x86_64-with-Ubuntu-19.10-eoan
Processor: x86_64
Python:
Implementation: CPython
Executable: /usr/bin/python3
Version: 3.7.5
Compiler: GCC 9.2.1 20191008
Bits: 64bit
Build: Nov 20 2019 09:21:52 (#default)
Unicode: UCS4
PyVISA Version: 1.10.1
Backends:
ni:
Version: 1.10.1 (bundled with PyVISA)
Binary library: Not found
py:
Version: 0.3.1
ASRL INSTR: Available via PySerial (3.4)
USB INSTR: Available via PyUSB (1.0.2). Backend: libusb1
USB RAW: Available via PyUSB (1.0.2). Backend: libusb1
TCPIP INSTR: Available
TCPIP SOCKET: Available
GPIB INSTR:
Please install linux-gpib to use this resource type.
No module named 'gpib'
Any help into the right direction is appreciated.
Regards,
Hello tivek,
Thank you for creating a gpib backend that I can use in PyVisa with PyVisa-py. The issue I am having relates to an inability to load the GPIB library. As given in your example, there is a function that can be called to have PyVisa recognize gpib_ctypes as the default GPIB module, but it seems not to be working for me.
My code:
from gpib_ctypes import make_default_gpib
make_default_gpib()
import visa as vi
connections=vi.ResourceManager('@py')
print(connections.list_resources())
#Error here
Error log:
Thank you for any assistance!
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.
We use the model 488-USB2 USB to GPIB Controller from ICS Electronics and it works fine with the gpib_ctypes package.
We run our application on Windows 7 and Windows 10, both using Python 3.7.2.
Driver version is 488-2V4: https://www.icselect.com/gpib_install%204882V4.html
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.