Coder Social home page Coder Social logo

gpib_ctypes's People

Contributors

tivek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

gpib_ctypes's Issues

gpib-32.dll fails to load with Keysight Instrument Control Bundle

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

Missing functions

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:

  • ibcac and ibgts: required for control atn
  • ibln: or a different function to specifically address a device
  • ibpct: required to implement pass control

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.

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.

Bad file descriptor

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,

Cannot locate GPIB library in PyVisa implementation

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:

  • /home/we-are-geth/.local/lib/python3.6/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)
    Traceback (most recent call last):
    File "/home/we-are-geth/Documents/PyVisa_Testing/Hello_World.py", line 7, in
    print(connections.list_resources())
    File "/home/we-are-geth/.local/lib/python3.6/site-packages/pyvisa/highlevel.py", line 1637, in list_resources
    return self.visalib.list_resources(self.session, query)
    File "/home/we-are-geth/.local/lib/python3.6/site-packages/pyvisa-py/highlevel.py", line 326, in list_resources
    for key, st in sessions.Session.iter_valid_session_classes()], [])
    File "/home/we-are-geth/.local/lib/python3.6/site-packages/pyvisa-py/highlevel.py", line 326, in
    for key, st in sessions.Session.iter_valid_session_classes()], [])
    File "/home/we-are-geth/.local/lib/python3.6/site-packages/pyvisa-py/gpib.py", line 56, in list_resources
    return ['GPIB0::%d::INSTR' % pad for pad in _find_listeners()]
    File "/home/we-are-geth/.local/lib/python3.6/site-packages/pyvisa-py/gpib.py", line 56, in
    return ['GPIB0::%d::INSTR' % pad for pad in _find_listeners()]
    File "/home/we-are-geth/.local/lib/python3.6/site-packages/pyvisa-py/gpib.py", line 34, in _find_listeners
    if gpib.listener(BOARD, i) and gpib.ask(BOARD, 1) != i:
    File "/home/we-are-geth/.local/lib/python3.6/site-packages/gpib_ctypes/gpib/gpib.py", line 417, in listener
    sta = _lib.ibln(board, pad, sad, ctypes.byref(present))
    File "/home/we-are-geth/.local/lib/python3.6/site-packages/gpib_ctypes/gpib/gpib.py", line 59, in f
    raise OSError(message)
    OSError: GPIB library not found. Please manually load it using _load_lib(filename). All GPIB functions will raise OSError until the library is manually loaded.
    [Finished in 0.3s with exit code 1]

Thank you for any assistance!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.