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.

Handle Prologix USB to GPIB

See original GitHub issue

Prologix sells a GPIB-USB Controller which does not handle transparently the connections to the instrument (i.e. it is not just a GPIB device as it needs some extra commands).

The proposal is to create a custom Resource that handles deals with the prologix device without requiring extra commands from the user.

PyVISA will:

  • Provide a Resource Class based on MessageBasedResource that appears as an standard resource but internally does all the things that prologix needs.
  • Provide a prefix to indicate a custom resource name (For example +)
  • In open_resource, dispatch this custom prefix to a function that should instantiate the new ResourceClass and return it.

We should also patch other functions like:

  • resource_info

The idea is that something like this would just work

import visa
rm = visa.ResourceManager()
inst = rm.open_resource('+PROLOGIX::/dev/bla/bla::GPIB::2')
inst.query('*IDN?')

Issue Analytics

  • State:open
  • Created 9 years ago
  • Comments:40 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
cweickhmanncommented, Mar 19, 2019

Here’s a little follow up on the Prologix GPIBoE adapter. We’ve been using it in the company quite regularly now. I have recently got rid of the imho most annoying shortcoming: The lack of native read after write functionality. To circumvent this, I’ve created a little class Prologix which basically encapsulates the TCPIPSocket class of pyvisa and extends the queries with a small decorator:

class Prologix(visa.resources.TCPIPSocket):
    """
    Encapsulating class providing write("++auto 1") before and
    write("++auto 0") after queries. Every TCPIPSocket.query*() method
    is wrapped in a decorator implementing this functionality.
    Furthermore, configure() and a setGpibAddr() methods are added
    to work around limitations of the Prologix controller.
    """
    
    @decorator.decorator
    def AutoFetchResponse(fun, self, *args, **kargs):
        self.write("++auto 1")
        resp = fun(self, *args, **kargs)
        self.write("++auto 0")
        return resp
    
    def __init__(self, *args, **kargs):
        super().__init__(*args, **kargs)
    
    def configure(self, vna_gpib_address=6):
        """Set up the Prologix controller to use:
            * set Prologix into Controller mode (++mode 1)
            * not automatic read after write (++auto 0)
            * read timeout 500 ms (++read_tmo_ms 500)
            * enable EOI assertion (++eoi 1)
            * termination character "\n" (++eos 2)
            * Disable character appending (++eot_enable 0)
            * Set device GPIB address to `vna_gpib_address`, defaults to 6
        """
        self.write_termination = "\n"
        self.read_termination = "\n"
        self.write("++mode 1")
        self.write("++addr %d" % vna_gpib_address)
        self.write("++auto 0") # No automatic read after write!
        self.write("++read_tmo_ms 500")
        self.write("++eos 2")
        self.write("++eoi 1")
        self.write("++eot_enable 0")
    
    def setGpibAddr(self, vna_gpib_address=6):
        """Set GPIB address. Defaults to 6"""
        self.write("++addr %d" % vna_gpib_address)
    
    @AutoFetchResponse
    def query(self, message, delay=None):
        return super().query(message, delay=delay)
    
    @AutoFetchResponse
    def query_ascii_values(self, message, converter='f', separator=',',
                           container=list, delay=None):
        return super().query_ascii_values(message, converter=converter,
                                          separator=separator,
                                          container=container,
                                          delay=delay)
    
    @AutoFetchResponse
    def query_binary_values(self, message, datatype='f', is_big_endian=False,
                            container=list, delay=None, header_fmt='ieee',
                            expect_termination=True):
        return super().query_binary_values(message, datatype=datatype,
                                           is_big_endian=is_big_endian,
                                           container=container,
                                           delay=delay, header_fmt=header_fmt,
                                           expect_termination=expect_termination)
    
    @AutoFetchResponse
    def query_values(self, message, delay=None):
        return super().query_values(message, delay=delay)

That’s certainly not perfect, but it is practical and working. The only thing that is still ugly now is how to use pyvisa.ResourceManager with it (but a lot better than before):

import pyvisa
import vnautil.Prologix

rm = pyvisa.ResourceManager()
vna = rm.open_resource("TCPIP::192.168.0.1::1234::SOCKET", resource_pyclass=vnautil.Prologix)
vna.configure(vna_gpib_address=9)
vna.query("*IDN?")

The resource_pyclass parameter is used to override the default class for this resource locator (TCPIP::___::SOCKET is handled with TCPIPSocket).

Hope this helps.

2reactions
zamora18commented, Sep 19, 2018

It seems that there is a lot of interest in having pyvisa functional with Prologix GPIB controllers, and maybe there has been some development already made (since the original issue began 3 years ago and the thread has been idle for ~1 year). I recently acquired a GPIB-Ethernet controller and would also be willing to contribute and test.

I came across a Python wrapper for the Prologix GPIB-to-Ethernet adapter already implemented. Maybe there can be some collaboration between the developers? Again, I am willing to contribute what I can, but this would be awesome to have integrated into pyvisa (pyvisa-py).

Read more comments on GitHub >

github_iconTop Results From Across the Web

GPIB-USB CONTROLLER FAQ – Prologix Instruments
Prologix GPIB -USB controller provides a virtual serial interface to communicate with instruments, while handling all GPIB protocol details for you.
Read more >
Prologix USB to Gpib Controller : Electronics - Amazon.com
No GPIB cable needed; controller plugs on to instrument. All software configuration. No DIP switches. Metal enclosure for durability and reduced EMI. USB...
Read more >
Prologix GPIB-USB Controller - NI Community
Description: This vi handles all of the base FTDI chipset commands and will poll all of the GPIB Addresses to determine what instruments...
Read more >
Prologix - GPIB-USB CONTROLLER - SGLabs
Prologix GPIB -USB controller provides a virtual serial interface to communicate with instruments, while handling all. GPIB protocol details for you.
Read more >
Prologix GPIB USB Controller - eBay
Prologix GPIB USB Controller - Picture 1 of 2. Prologix GPIB USB Controller ... Includes 5 business days handling time after receipt of...
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