I'm creating instrument classes for use with pyvisa. Rather than manually convert every SCPI command (about 400) into methods, I'd like to just copy the command quick reference into a text file and have commands like this:
[SENSe:]TEMPerature:TRANsducer:RTD:RESistance[:REFerence]? [{MIN|MAX}]
Wind up as methods like this:
def temp_tran_rtd_res_qry(*args):
<check for valid arguments>
cmd = 'TEMPerature:TRANsducer:RTD:RESistance?'
argstr = ''
for arg in args:
argstr += ' ' + arg
return self.query(cmd + argstr)
I have a handle on parsing the commands, and I figured out how to use setattr()
to create the methods with the correct names from a template function.
The part that's giving me trouble is where each method knows what to assign to cmd
. I thought I might add the original strings to the class as attributes (named similar to the methods) and parse them on the fly in the methods, but for this, the methods to be able to retrieve class attributes based on their names (or something).