pylab_ml.attributes.create_attributes

class create_attributes[source]

Bases: object

Create methods or attributes from a dictionary.

Date:

June 16, 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/method name : (Device command for read/write) , range, call functions}
Attribute/Method name:

Your provided name for the attribute/method

Device command:
  • The read nd write command for the instance, e.q. ‘TMPA?’ or None.

  • Or the method 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_tti

    show the usage to create attributes and connect to a smu with one or more channels

  • the class MPI_TA5K() instruments/thermostreamer/mpi_ta5k

    show the usage to create attributes and connect to a thermostreamer

  • the class HALAPBBoard() :

    download:../../../src/pylab_ml/pylab_ml/boards/micronas/communication/apbboard show the usage to create attributes and connect to a communication board

  • the class pxie41xx() use this class to call inst.methods_name

    instruments/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
>>>
__init__()[source]

Methods

__init__()

createattributes(dictionary[, parent, ...])

Create attributes or methods from a dictionary.

Attributes

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.

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) – The dictionary with the syntax: {attribute/methode name : (Device command for read/write) , range, call functions}.

  • parent (create_attributes, optional) – If you want to create a child, than you have to set the parent, otherwise None, by default None.

  • child (str, optional) – The name of the child, by default None.

  • childname (str, optional) – The name of the child, by default ‘’.

Return type:

None.