Previous topic

Plot example

Next topic

Axis device driver example

This Page

Input device driver example¶

from terapy.hardware.input.base import InputDevice

class InputExample(InputDevice):
   def __init__(self):
       # Insert here what the driver should do when loaded
       # (e.g. check that the right modules/interface cards/... are present).
       # DON'T initialize the device here (see initialize() function for that).

       # variables stated in self.config will be loaded/saved
       # from/to the configuration file (devices.ini)
       self.config = ["variable1", "variable2"]
       self.variable1 = 0.0
       self.variable2 = "blah"

   def assign(self, address, ID, name):
           Configure device driver prior to initialization.
               address    -    physical address as required by communication interface driver
               ID         -    device short name (str)
               name       -    device long name (str)
       self.address = address
       self.ID = ID = name

   def initialize(self):
           Initialize device.

   def reset(self):
           Reset device.

   def read(self):
           Return values read by device.
               Device values (list of floats)
       # Return what is read as a list of floats.
       # This list can be used by a scan event in the way you like.
       # For example:
       #    -    device reads several quantities at once => pick the one of interest
       #    -    device reads the same source multiple times => compute average/variance/...
       return [0]

   def detect(self):
           Detect available devices handled by device driver.
               list of available devices, each entry as (address, short name, long name)
       return []

   def configure(self):
           Call device configuration dialog.