Giter Site home page Giter Site logo

scpi-protocol's Introduction

scpi-protocol

Pypi version

Sans I/O python SCPI parser library.

Installation

From within your favourite python environment:

pip install scpi-protocol

scpi-protocol's People

Contributors

tiagocoutinho avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

scpi-protocol's Issues

library integration

Hi, I'm trying to implement an SCPI based instrument, using this library and python-vxi11-server

First of all, thanks very much for writing this library, it is a neat way of representsing the commands as a dictionary.

However, I'm having a little difficulty integrating the library - I have something working, but there are a couple of areas that I'm unclear about.

  1. Instrument actions. The basic library has no mechanism to execute behaviour on the instrument
  2. The meaning of the get and set members in the command dictionary seem swapped.
    • assuming set is for device_write() operations, and get for device_read()

I addressed issue (1) by extending the table members. So for example, I have an entry for a notional measurement:

STD_CMDS = Commands(
    {
        "*CLS": FuncCmd(doc="clear status"),
        "*ESE": IntCmd(doc="standard event status enable register"),
        "*ESR": IntCmdR(doc="standard event event status register"),
        "*IDN": IDNCmd(),
        "*OPC": IntCmdR(set=None, doc="operation complete"),
        "*OPT": IntCmdR(doc="return model number of any installed options"),
        "*RCL": IntCmdW(set=int, doc="return to user saved setup"),
        "*RST": FuncCmd(doc="reset"),
        "*SAV": IntCmdW(doc="save the preset setup as the user-saved setup"),
        "*SRE": IntCmdW(doc="service request enable register"),
        "*STB": StrCmdR(doc="status byte register"),
        "*TRG": FuncCmd(doc="bus trigger"),
        "*TST": Cmd(get=lambda x: not __decode_OnOff(x), doc="self-test query"),
        "*WAI": FuncCmd(doc="wait to continue"),
        "SYSTem:ERRor[:NEXT]": ErrCmd(doc="return and clear oldest system error"),

        "[MEASure:]VOLTage[:DC]" : FloatCmdR(action=measVolt, doc="measure voltage")
    }
)

where measVolt is a function that emulates a meter reading:

def measVolt(x):
    return 1.437

and elsewhere I have a (rudimentary) function that handles the command string:

def handleCmds(cmds):
    cs = split_line(cmds)
    #print(cs,'\n')
    for c in cs :
        cmd  = STD_CMDS[c.name]
        resp = None
        if c.query :
            resp = cmd['get'](cmd['action'](c.args))
        else :
            if cmd['set'] :
                resp = cmd['action'](* list(map(cmd['set'], c.args)))
            else :
                resp = cmd['action']()
        return resp

(Note that this doesn't really handle anything other than a simple command string at the moment)

However, here I had to change the sense of the get and set members of the commands. If the set function is meant to transform the character string that represents the argument into the type expected by the action function, then it should be a class that represents the type (e.g. int), and conversely, the get function should transform from the domain of the type returned by the action function to the VISA representation; i.e. it should usually be str. However, most of the default definitions for the table are the other way around. So effectively:

FloatCmdR = partial(Cmd, get=str)

This extends to the default get function defined for *IDN? which decodes an IDN string, though I can't see why this would be needed, and I just generate the string.

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.