pylab_ml.attributes.create_attributes
- class create_attributes[source]
Bases:
objectCreate a methode or an attributes from a dictionary.
- Date:
May 05, 2026
- Author:
Semi-ATE <info@Semi-ATE.org>
Call the methode read() for get, or write() for set attribute, with some checks before and after calling.
Syntax from this dictonary to create the attributes:
{attribute/methode name : (Device command for read/write) , range, call functions}- Attribute/methode name:
your favorite name for the attribute/methode
- Device command:
the read nd write command for the instance, e.q. ‘TMPA?’ or None.
or the methode name e.q. ‘current_level_autorange’.
- Range:
could be None, Enum or range value (integer or float)
- Call functions:
before or after the instance write or read, you can define a functionname, which will be call and manipulate the get/set value
‘gb’= get_before() -> get, call function before the read instance. Do something before the read instance
‘ga’= get_after() -> get, call function after the read instance. Do something with the value, e.q. translate from hex to integer
‘gac’= get_after_check() -> get, call function after the read instance and check.
‘sb’= set_before() -> set, call function before write instance
‘sac’= set_after_check() -> set, call function after check, before write instance
‘sa’= set_after -> set, call function after write instance
The functions itself, have to return the modified value or None if value are not modified. If you get an error in the function, than you should set your return value to ATTR_ERROR
- Example 1:
>>> class test(create_attributes) >>> >>> properties = {'bitTime' : (('?bt', 'sbt'), [10, 3400], {'ga': '_hex2dec(value)', 'sac': '_dec2hex(value)', 'sa': 'readresult(0)'}), >>> 'airtemp' : (('TMPA?', None), None, None), >>> 'dutsensortype' : (('DSNS?','DSNS'), [0,4], None), >>> 'blaba' : (('BLAA?','BLAB'), [1.0,4.7]; None), >>> 'compressor' : (('COOL?','COOL'), 'Compressor', {'sac': '_compressor(value)'}), >>> } >>> >>> class Compressor(Enum) : >>> off= 0 >>> on = 1 >>> >>> def setup_inst(self): >>> self.createattributes(self.properties) # <-- add this line in your setup_inst >>> super().setup_inst()
- ==> this will create following attributes:
>>> # create attribute bitTime with get/set : >>> self.bitTime # get attribute : call the methode inst.query('?bt') MEASURE - 'yourDevice'.bitTime == 480 480 >>> self.bitTime = 20 # set attribute : check if value is integer, and 10<=value<=3400, >>> # if ok than call inst.write('sbt') MEASURE - 'yourDevice'.bitTime := 20
>>> # create attribute airtemp with get: >>> self.airtemp MEASURE - 'yourDevice'.airtemp == 22.2 22.2
>>> # create attribute dutsensortype with get/set : >>> self.dutsensortype # write inst.query('DSNS?'), return with int(value) MEASURE - 'yourDevice'.dutsensortype == 0 0 >>> self.dutsensortype = 3 # check if value is integer, and 0<=value<=4, >>> # if ok than inst.write('DSNS 3') MEASURE - 'yourDevice'.dutsensortype := 3 3 >>> self.dutsensortype = 5 ERROR - 'yourDevice'.dutsensortype := 5 outside limits, choose [0, 4]
>>> # create attribute blaba with get/set : >>> self.blaba # inst.query('BLAA?'), return with float(value) MEASURE - 'yourDevice'.blaba == 3.0 3.0 >>> self.blaba = 3.4 # check if value is float, and 1.0<=value<=4.7, >>> # if ok than inst.write('BLAB') MEASURE - 'yourDevice'.blaba := 3.4 3.4
>>> # create attribute compressor with get/set and values is Enum: >>> self.compressor #inst.query('COOL?'), return with the enum Compressor MEASURE - 'yourDevice'.compressor == Compressor.on <Compressor.on: 1> >>> compressor = Compressor.on # check if value in Compressor >>> # if ok than call _compressor(Compressor.on), and than inst.write('COOL 1'), MEASURE - 'yourDevice'.compressor := Compressor.on >>> compressor = 'on' # shorter but the same as before MEASURE - 'yourDevice'.compressor := Compressor.on >>> compressor = 1 # also possible MEASURE - 'yourDevice'.compressor := Compressor.on
Example 2, for calling inst.methode (none read/write): >>> properties = {‘auto_zero’: (‘auto_zero’, ‘backend.AutoZero’, {‘sac’: ‘checkstate(uncommitted)’}), >>> ‘aperture_time_units’: (‘aperture_time_units’, ‘backend.ApertureTimeUnits’, {‘sac’: ‘checkstate(uncommitted)’}), >>> ‘aperture_time’: (‘aperture_time’, None, {‘sac’: ‘checkstate(uncommitted)’}), >>> }
- see also
the class
TTI()instruments/smu/tti/base_ttishow the usage to create attributes and connect to a smu with one or more channelsthe class
MPI_TA5K()instruments/thermostreamer/mpi_ta5kshow the usage to create attributes and connect to a thermostreamerthe class
HALAPBBoard(): download:../../../src/pylab_ml/pylab_ml/boards/micronas/communication/apbboard show the usage to create attributes and connect to a communication boardthe class
pxie41xx()use this class to call inst.methods_nameinstruments/smu/natinst/pxie41xx.py
Tip
if your device has no read/write instance, than overwrite the method _call_instance() Example:
>>> def _call_instance(self, function, rw, value=None): >>> if rw == "wr": >>> self.ch[self.channel].__setattr__(function, value) # for set attribute >>> elif rw == "rd": >>> value = self.ch[self.channel].__getattribute__(function) # for get attribute >>> return (value)
Note
- necessary Methods in the class above (if you don’t overwrite the method _call_instance()):
>>> def read(self): >>> value = self.inst.read() # your code for instance read >>> return value >>> >>> def write(self,value): >>> self.instance.write(value) # your code for instance write >>>
Methods
__init__()createattributes(dictionary[, parent, ...])Create attributes or methods from a dictionary.
Attributes
if something wrong with your called methode, than set the result to self.ATTR_ERROR
last set/get attribute name.
last set attribute value.
- ATTR_ERROR
if something wrong with your called methode, than set the result to self.ATTR_ERROR
- attrLast
last set/get attribute name.
- attrLastvalue
last set attribute value.
- createattributes(dictionary, parent=None, child=None, childname='')[source]
Create attributes or methods from a dictionary.
syntax from the dictionary see example in the class documentation.
- Parameters:
dictionary (dict) – {attribute/methode name : (Device command for read/write) , range, call functions}.
- Returns:
None.