Sans I/O python SCPI parser library.
From within your favourite python environment:
pip install scpi-protocol
Python sans I/O SCPI protocol parser library
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.
get
and set
members in the command dictionary seem swapped.
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.