Skip to content

Your first device

A new workspace has no devices yet, so the dashboard starts empty. To look around first, click Load the demo setup there (simulated instruments, a dashboard and a procedure; remove them whenever you like) and skip to arrange a dashboard. To build your own, read on:

The empty dashboard saying that no devices are configured, with a link to the Devices page and a button to load the demo setup.The empty dashboard saying that no devices are configured, with a link to the Devices page and a button to load the demo setup.

In this step you add a pressure gauge that runs on simulated values. It needs no hardware, and later you replace the simulation with the code for your real instrument.

  1. Open the Devices page and scroll to Drivers and click New Python driver….

  2. Choose Pressure gauge, name it vacuum_gauge, and set Connection to how your instrument is connected (here: serial port; the choices are Serial port, Network (TCP), VISA and Other). For a serial port, TCP or VISA the new file already has the code that opens it (with laborchestra.transport) and its dependencies; it runs on simulated values until you switch simulate off: either in the file (the line simulate = True) or, without touching the file, as an option of the device (the menu ⋯ of the device on the Devices page, Change…). The option wins over the file.

    The dialog New device with four kinds (Blank device, RF / signal generator, Motorized stage, Pressure gauge), the name vacuum_gauge and the connection Serial port.The dialog New device with four kinds (Blank device, RF / signal generator, Motorized stage, Pressure gauge), the name vacuum_gauge and the connection Serial port.

    Names are written in snake_case: lower-case letters, digits and underscores. The name is how scripts reach the device (lab.vacuum_gauge), so pick one that says what it is in your lab.

  3. Click Create. LabOrchestra writes devices/vacuum_gauge.py into your workspace, prepares a Python environment for it (the first time this takes a minute), and starts it.

    The dialog confirming that devices/vacuum_gauge.py is in the workspace and the device runs on simulated values, with buttons to open the file.The dialog confirming that devices/vacuum_gauge.py is in the workspace and the device runs on simulated values, with buttons to open the file.
  4. Click Done. The device is in the list, with the status ready.

    The Devices page with one device, vacuum_gauge, with the status ready.The Devices page with one device, vacuum_gauge, with the status ready.

Go back to the Dashboard: the gauge is there, with its two pressures changing slowly. The two channels are numbered 0 and 1: channels (and everything else in LabOrchestra that is a list) are counted from zero, in the dashboard, in scripts and in recordings.

The dashboard showing the vacuum_gauge device as a card with two pressure channels.The dashboard showing the vacuum_gauge device as a card with two pressure channels.

devices/vacuum_gauge.py is an ordinary Python file:

devices/vacuum_gauge.py (shortened)
from laborchestra import Device
from laborchestra.profiles import PressureSensor
class VacuumGauge(Device):
profiles = [PressureSensor]
port: str = "" # options: set them on the Devices page
baudrate: int = 9600
simulate = True # no hardware: pressures that drift
poll_s = 1.0
state = {"simulated": False, "channels": []}
def run(self):
while self.running:
self.state["channels"] = [{"pressure": p if s == "ok" else None, "status": s} for s, p in self._read()]
self.sleep(self.poll_s)
  • Options are class attributes (port, baudrate, simulate, poll_s). You set them per device on the Devices page: the menu (⋯) of the device, Change….
  • state is what everyone sees. Whatever you put into it appears on the dashboard, in scripts and in recordings, without any further code.
  • profiles = [PressureSensor] says that this is a pressure gauge, so the dashboard offers the widgets for pressures.

The places marked TODO in the file are where the code for your instrument goes. When you save the file, the Devices page shows file changed, and Restart runs the new code.

Add device… on the Devices page adds a device that has already been written. Choose from one list:

  • a Python file of the workspace,
  • a Python driver that comes with LabOrchestra, such as Elliptec or the SCPI generator. It is used where it is and updated with LabOrchestra. If you need to change one, choose Change… on the device and then Make my own copy to change it…,
  • a C# driver built into LabOrchestra, such as the PicoScope oscilloscopes, or one from a plugin.

The form for the options is generated from the device itself. For a Python package (for example from PyPI) or a device on another computer, choose the kind Package or Remote at the top of the dialog. The dialog also has a link to write a new Python driver instead.

Next: arrange a dashboard.