Driver Programming: Difference between revisions

From SweepMe! Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 10: Line 10:


This is a minimal working example to create a Device Class.
This is a minimal working example to create a Device Class.
=== Getting GUI parameter ===
If you need to know what the user configuration of the Measurement class GUI, insert the following function:
{{syntaxhighlight|lang=python|code=
def get_GUIparameter(parameter):
    print parameter
}}
The dictionary parameter is used to hand over all GUI settings to the Device Class. The print command can be used to see the content and which keys are accessible. These keys of the dictionary can vary between each Measurement Class.
In order to load a single parameter, for example the Sweep mode, use:
{{syntaxhighlight|lang=python|code=
self.sweepmode = self.parameter["SweepMode"]
}}
Input from a parameter text line is automatically splitted at each comma and separated regarding the equal sign:
{{syntaxhighlight|lang=python|code=
self.offset = float(self.parameter["Parameter"]["offset"])
self.axis  = int(self.parameter["Parameter"]["axis"])
}}
Do not forget to change the type from string to whatever you need by using int() or float(), etc.
=== Setting GUI parameter ===
If you like to provide options displayed in the Drop-Down Comboboxes or a parameter text line, insert the following function:
{{syntaxhighlight|lang=python|code=
def set_GUIparameter(parameter):
    GUIparameter = {}
    return GUIparameter
}}
If you like to change something modify the GUIparameter dictionary which you have to return:
{{syntaxhighlight|lang=python|code=
GUIparameter = {
                "SweepMode" : ["Current [A]", Voltage [V]"],  # define a list
                "Parameter" : "offset = 0.0, axis = 2" ,
              }
}}

Revision as of 20:21, 4 February 2018

A Device Class is a main.py file in which a python class-Object is inherited from a parent class called EmptyDeviceClass.

from EmptyDeviceClass import EmptyDevice  # Loading the EmptyDevice Class

class Device(EmptyDevice):            # Creating a new Device Class by inheriting from EmptyDevice
    def __init__(self):               # The python class object need to be initialized
       EmptyDevice.__init__(self)     # Finally, the initialization of EmptyDevice has to be done

This is a minimal working example to create a Device Class.


Getting GUI parameter

If you need to know what the user configuration of the Measurement class GUI, insert the following function:

def get_GUIparameter(parameter):
    print parameter

The dictionary parameter is used to hand over all GUI settings to the Device Class. The print command can be used to see the content and which keys are accessible. These keys of the dictionary can vary between each Measurement Class.

In order to load a single parameter, for example the Sweep mode, use:

self.sweepmode = self.parameter["SweepMode"]

Input from a parameter text line is automatically splitted at each comma and separated regarding the equal sign:

self.offset = float(self.parameter["Parameter"]["offset"])
self.axis   = int(self.parameter["Parameter"]["axis"])

Do not forget to change the type from string to whatever you need by using int() or float(), etc.


Setting GUI parameter

If you like to provide options displayed in the Drop-Down Comboboxes or a parameter text line, insert the following function:

def set_GUIparameter(parameter):
    GUIparameter = {}
    return GUIparameter

If you like to change something modify the GUIparameter dictionary which you have to return:

GUIparameter = {
                "SweepMode" : ["Current [A]", Voltage [V]"],  # define a list 
                "Parameter" : "offset = 0.0, axis = 2" ,
               }