Skip to content

New device

Matej Troják edited this page Mar 18, 2021 · 2 revisions

To make DeviceControl as agile as possible, users have the option to implement additional Device Packages. DeviceControl can then use these implementations to communicate with new device types.

All of these implementations are to be placed within the app/workspace/devices. A Python package with the following structure is expected:

|- app
|   |- workspace
|   |   |-- devices
|   |   |   |--<your-package>
|   |   |   |   |--<your-files-or whole packages>
|   |   |   |   |-- __init__.py

The __init__.py in your packages can be left empty. However, there is an __init__.py file located in the app/workspace/devices folder. In this file, a dictionary named classes can be found. You must register all your newly implemented device classes and types in this dictionary under a unique pair of keys by which DeviceControl will know to reference your device. Be sure to leave a reference to the class, not an instance of it! In order to use your device in an experiment, simply provide this pair of keys in the device_class and device_type fields when initiating the device.

New Device Implementation Guide

Your class should extend the Connector class. The super call must provide the Connector class with a dictionary.

from .. import Connector


class YourClass(Connector):
    def __init__(self, config: dict):
        super(YourClass, self).__init__(config)

The dictionary passed to the constructor contains (key, value) pairs as provided by the data message sent via Device initiation. These pairs are stored within your class as the object's attributes, meaning that a value sent under your_parameter key can be accessed within the object's methods as self.your_parameter.

To assure compatibility between your class and DeviceControl, the class must introduce the following attributes and methods.

Attributes

All classes must have a self.interpreter attribute, which is a dictionary listing all the methods in the class which you want to be able to access via Commands or Tasks under a unique ID of a str type. This will be the command's ID as referenced by DeviceControl.

from .. import Connector


class YourClass(Connector):
    def __init__(self, config: dict):
        super(YourClass, self).__init__(config)
        self.interpreter = {"cmd_id_1": self.my_method}

    def my_method():
        # do stuff

Methods

Some methods are mandatory for implementation.

def disconnect(self):
    # provide a proper way for the connection to be eliminated

def test_connection(self):
    # provide a proper way to test the connection between DeviceControl and the physical device