You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Instrument actions. The basic library has no mechanism to execute behaviour on the instrument
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.
The text was updated successfully, but these errors were encountered:
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
andset
members in the command dictionary seem swapped.set
is fordevice_write()
operations, andget
fordevice_read()
I addressed issue (1) by extending the table members. So for example, I have an entry for a notional measurement:
where
measVolt
is a function that emulates a meter reading:and elsewhere I have a (rudimentary) function that handles the command string:
(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
andset
members of the commands. If theset
function is meant to transform the character string that represents the argument into the type expected by theaction
function, then it should be a class that represents the type (e.g.int
), and conversely, theget
function should transform from the domain of the type returned by the action function to the VISA representation; i.e. it should usually bestr
. However, most of the default definitions for the table are the other way around. So effectively: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.The text was updated successfully, but these errors were encountered: