Driver Programming: Difference between revisions
No edit summary |
No edit summary |
||
Line 12: | Line 12: | ||
== Importing python packages == | |||
All packages which come along with SweepMe! can be imported as usual at the beginning of the file. | All packages which come along with SweepMe! can be imported as usual at the beginning of the file. | ||
If you need to import packages which are not yet included to your SweepMe! installation, you can use the [[LibraryBuilder]] to ship the python package with your DeviceClass. | If you need to import packages which are not yet included to your SweepMe! installation, you can use the [[LibraryBuilder]] to ship the python package with your DeviceClass. | ||
== Getting GUI parameter == | |||
If you need to know what the user configuration of the Measurement class GUI, insert the following function: | If you need to know what the user configuration of the Measurement class GUI, insert the following function: | ||
Line 43: | Line 43: | ||
Do not forget to change the type from string to whatever you need by using int() or float(), etc. | 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: | If you like to provide options displayed in the Drop-Down Comboboxes or a parameter text line, insert the following function: | ||
Line 61: | Line 61: | ||
}} | }} | ||
== Multichannel support == | |||
Some measurement equipment has two channels but only one communications port, e.g. some Source-Measuring-Units or Paramter Analyzers have multiple channels to independently source voltages or currents, but everything is controlled via one port. | Some measurement equipment has two channels but only one communications port, e.g. some Source-Measuring-Units or Paramter Analyzers have multiple channels to independently source voltages or currents, but everything is controlled via one port. | ||
Line 84: | Line 84: | ||
Of course, you can modify the above example to your needs. | Of course, you can modify the above example to your needs. | ||
== Stop a measurement == | |||
You can set the variable self.stopMeasurement, e.g. | You can set the variable self.stopMeasurement, e.g. | ||
Line 98: | Line 98: | ||
In that case, SweepMe! will immediately stop the measurement after the MessageBox has been confirmed by the user. | In that case, SweepMe! will immediately stop the measurement after the MessageBox has been confirmed by the user. | ||
== Communication with the user == | |||
If you like to display a message in the info box of the "Measurement" tab, you can use: | If you like to display a message in the info box of the "Measurement" tab, you can use: | ||
Line 111: | Line 111: | ||
Please note that the message box is non-blocking and the measurement will continue, even if the the message is not confirmed by the user. | Please note that the message box is non-blocking and the measurement will continue, even if the the message is not confirmed by the user. | ||
== Log messages to a file == | |||
You can easily write messages to a file using | You can easily write messages to a file using | ||
Line 120: | Line 120: | ||
== Inter Device Class communication == | |||
Starting with the function [[connect]], each Device Class has the dictionary self.device_communication. One can store information using a key string. This key string should be as unique as possible to prevent accidential overwriting by another Device Class. | Starting with the function [[connect]], each Device Class has the dictionary self.device_communication. One can store information using a key string. This key string should be as unique as possible to prevent accidential overwriting by another Device Class. | ||
Inter Device Class communication might be required if the access to a certain physical device can be generated only once, but needs to be known by multiple Device Classes. For example, a Device Class which opens an own port object to communicate with a spectrometer will have exclusive access to that port. In order to allow multiple Spectrometer modules in the sequencer to access that port object it must be made available to all of them. | Inter Device Class communication might be required if the access to a certain physical device can be generated only once, but needs to be known by multiple Device Classes. For example, a Device Class which opens an own port object to communicate with a spectrometer will have exclusive access to that port. In order to allow multiple Spectrometer modules in the sequencer to access that port object it must be made available to all of them. |
Revision as of 13:35, 28 July 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.
Importing python packages
All packages which come along with SweepMe! can be imported as usual at the beginning of the file. If you need to import packages which are not yet included to your SweepMe! installation, you can use the LibraryBuilder to ship the python package with your DeviceClass.
Getting GUI parameter
If you need to know what the user configuration of the Measurement class GUI, insert the following function:
def get_GUIparameter(self, 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(self):
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" , # define a comma-separated string where variable and value are connected by an equal sign
}
Multichannel support
Some measurement equipment has two channels but only one communications port, e.g. some Source-Measuring-Units or Paramter Analyzers have multiple channels to independently source voltages or currents, but everything is controlled via one port.
Of course, one could implement a Device Class for each channel of the device but in case of changes multiple files have to be revised. In order to unify the device handling, you can define multiple channels in the __init__ function of your Device Class by using:
self.multichannel = ["CH1", "CH2", "CH3", "CH4"]
In that case, the use will see four Device Classes in the GUI of the Measurment Class with the string defined above at the end.
To figure out which channel is chosen by the user, use:
def get_GUIparameter(self, parameter):
self.device = self.parameter["Device"]
self.channel = int(self.device[-1])
The above example will first read out the name of the chosen Device Class. Assuming that the last character of the string is the channel, the channel number can be defined as an integer value. Of course, you can modify the above example to your needs.
Stop a measurement
You can set the variable self.stopMeasurement, e.g.
self.stopMeasurement = "text-to-be-displayed-in-a-message-box-to-inform-user"
If SweepMe! detects a non-empty string it will stop the measurement after the current function returns. Use "return False" to let the current function return immediately.
Alternatively, you can use the following function
self.stop_Measurement("text-to-be-displayed-in-a-message-box-to-inform-user")
In that case, SweepMe! will immediately stop the measurement after the MessageBox has been confirmed by the user.
Communication with the user
If you like to display a message in the info box of the "Measurement" tab, you can use:
self.message_Info("text-to-be-displayed-in-the-info-box")
If you like to inform the user with a message box, use
self.message_Box("text-to-be-displayed-in-the-message-box")
Please note that the message box is non-blocking and the measurement will continue, even if the the message is not confirmed by the user.
Log messages to a file
You can easily write messages to a file using
self.write_Log("message-to-be-saved")
The message will be saved in the file temp_logbook.txt within the temp-folder. When saving data the leading "temp" of the file will be automatically renamed by the given file name.
Inter Device Class communication
Starting with the function connect, each Device Class has the dictionary self.device_communication. One can store information using a key string. This key string should be as unique as possible to prevent accidential overwriting by another Device Class. Inter Device Class communication might be required if the access to a certain physical device can be generated only once, but needs to be known by multiple Device Classes. For example, a Device Class which opens an own port object to communicate with a spectrometer will have exclusive access to that port. In order to allow multiple Spectrometer modules in the sequencer to access that port object it must be made available to all of them.