pyvisa / pyvisa-py

A pure python PyVISA backend
https://pyvisa-py.readthedocs.io
MIT License
282 stars 120 forks source link

Added VICP protocol #332

Closed bobmcnamara closed 1 year ago

bobmcnamara commented 2 years ago

Building on the changes that added the HiSLIP protocol, I added the VICP protocol making use of the pyvicp package I recently added to PyPI. (That package can't be directly integrated into pyvisa because of its licensing terms.)

codecov-commenter commented 2 years ago

Codecov Report

Merging #332 (3893b69) into main (685ef22) will increase coverage by 0.08%. The diff coverage is 26.02%.

@@            Coverage Diff             @@
##             main     #332      +/-   ##
==========================================
+ Coverage   22.16%   22.25%   +0.08%     
==========================================
  Files          21       21              
  Lines        3126     3199      +73     
  Branches      435      443       +8     
==========================================
+ Hits          693      712      +19     
- Misses       2415     2470      +55     
+ Partials       18       17       -1     
Flag Coverage Δ
unittests 22.25% <26.02%> (+0.08%) :arrow_up:

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pyvisa_py/tcpip.py 19.73% <26.02%> (+1.02%) :arrow_up:
pyvisa_py/protocols/rpc.py 22.02% <0.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

MatthieuDartiailh commented 1 year ago

Why did you close the PR ?

bobmcnamara commented 1 year ago

I dunno...maybe it happened when the cat walked across my laptop?

MatthieuDartiailh commented 1 year ago

Sorry I missed your latest comments. I saw the last commit but did not realize the rest was already done. Thanks again for your great contributions. I will try to merge both the PyVISA PR and this one quickly. I also found I could access an oscilloscope supporting VICP so I will be able to do investigate any issue that arises later on.

MatthieuDartiailh commented 1 year ago

Sorry for the delay. I wanted to test locally using the oscilloscope I have on hand but could not find the time to do so. In particular I wanted to extract the proper value for the InterfaceType enum using the Lecroy passport and they took some time to give me access to the passport. It seems the enum value is zero but I am not sure. Basically I cannot use NI-VISA to connect to the instrument using VICP (even though the instrument is supposed to run VICP), but VXI-11 work while it should not so I am a bit suspicious of the machine itself. I will try to get my hand on a different one. Using PyVISA-py and your PR I could access the resource and got:

lc.query("*IDN?")
'*IDN LECROY,WRHRO64ZI,LCRY3106N59472,6.9.0\n'

however running VXI-11 that should not work I get:

lc.query("*IDN?")                          
'LECROY,WRHRO64ZI,LCRY3106N59472,6.9.0\n'

Is that repeat of the query something I should expect from VICP ?

bobmcnamara commented 1 year ago

From the LeCroy XStream manual:

The COMM_HEADER command controls the way the oscilloscope formats responses to queries. There are three response formats: LONG, in which responses start with the long form of the header word; SHORT, where responses start with the short form of the header word; and OFF, for which headers are omitted from the response and units in numbers are suppressed.

Unless you request otherwise, the SHORT response format is used.

I'm not sure why the response format is different depending on the protocol (VICP vs. VXI-11), but I always sent the command "CHDR OFF" to force it off.

bobmcnamara commented 1 year ago

Here's a routine I've used to either reset the connection or to force VICP protocol when it wasn't convenient to physically access the machine:

def _steal_connection(ipaddr, port=80, protocol="vicp"):
    """
    LeCroy scopes only support a single VICP connection.  This procedure
    provides a way to free up that single connection.  In general, this
    would be used in instances where the connection didn't close cleanly
    (for instance, if you closed your laptop and went home).

    protocol is one of "vicp", "vxi11", or "usb".
    """
    from urllib.request import Request, urlopen
    from urllib.parse import urlencode

    url = "http://%s:%s/instrumentstatus.html" % (ipaddr, port)

    # turn remote interface off...
    data = urlencode(dict(Interface="Off"))
    req = Request(url, data.encode())
    response = urlopen(req)
    the_page = response.read()

    # turn remote interface back on...
    interface = dict(
        vicp="TCPIP\r\n(VICP)",
        vxi11="LXI\r\n(VXI11)",
        usb="USBTMC",
    )
    data = urlencode(dict(Interface=interface[protocol]))
    req = Request(url, data.encode())
    response = urlopen(req)
    the_page = response.read()
MatthieuDartiailh commented 1 year ago

Thanks !

I got my hands on another scope. I will do my best to test again soon.

MatthieuDartiailh commented 1 year ago

I never managed to open a VICP connection using the lecroy passport. I will merge https://github.com/pyvisa/pyvisa/pull/699 shortly and cut a release. I will then update this PR to bump the minimal pyvisa version, merge and release. Thanks again for your amazing contributions and sorry for the slow process.