Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

library integration #1

Open
byzantic opened this issue Dec 11, 2023 · 0 comments
Open

library integration #1

byzantic opened this issue Dec 11, 2023 · 0 comments

Comments

@byzantic
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant