Skip to main content

Python reference implementation of the Laboratory Experiment COntrol (LECO) protocol

Project description

PyLECO

PyPI - Python Version codecov pypi release conda-forge release DOI Common Changelog

Python reference implementation of the Laboratory Experiment COntrol (LECO) protocol.

Note: LECO is still under development, such that the code and API might change. The LECO protocol branch pyleco-state contains the assumptions used in this project, which are not yet accepted into the LECO main branch. See this documentation for the LECO definitions including these assumptions. These things might change, if LECO defines them differently.

For a tutorial on how to get started, see GETTING_STARTED.md.

You are welcome to contribute, for more information see CONTRIBUTING.md.

Quick Start

  1. Install Python,
  2. install PyLECO with pip install pyleco or conda install conda-forge::pyleco,
  3. import the package pyleco in your python scripts,
  4. and use it as desired.

LECO Overview

Network Topology

PyLECO is an implementation of LECO, for the full protocol specifications please visit https://github.com/pymeasure/leco-protocol. LECO offers a protocol for data exchange, for example for laboratory experimental control.

There exist two different communication protocols in LECO.

  1. The control protocol allows to exchange messages between any two Components in a LECO network, which is useful for controlling devices.
  2. The data protocol is a broadcasting protocol to send information to all those, who want to receive it, which is useful for regular measurement data or for log entries.

A LECO network needs at least one Coordinator (server), which routes the messages among the connected Components.

Each Component has a name unique in the network. This name consists in the name of the Coordinator they are connected to and their own name. For example N1.component1 is the full name of component1 connected to the Coordinator of the Namespace N1. That Coordinator itself is called N1.COORDINATOR, as Coordinators are always called COORDINATOR.

Remote Procedure Calls

The default messaging content of the control protocol are remote procedure calls (RPC) according to JSON-RPC. RPC means, that you execute a method (or procedure) on a remote Component. For example you have an Actor, which is for example a Component controlling a measurement instrument. In order to set the output of that measurement instrument, you want to call the set_output method of that instrument. For that purpose, you send a message which encodes exactly that (via jsonrpc): the method to call and the parameters of that method.

Usage of the Control Protocol

Minimum Setup

For a minimum setup, you need:

  • a Coordinator (just execute coordinator in your terminal or run the coordinator.py file with your Python interpreter),
  • one Component.

For example, you can use a Communicator instance to send/receive messages via LECO protocol. The following example requests the list of Components connected currently to the Coordinator:

from pyleco.utils.communicator import Communicator

c = Communicator(name="TestCommunicator")
connected_components = c.ask_rpc(method="send_local_components")
print(connected_components)

Instrument Control

Let's say you have an instrument with a pymeasure driver Driver, which you want to control.

You need to start (in different threads):

  • a Coordinator (as described above),
  • an Actor instance listening to commands and controlling the instrument: actor = Actor(name="inst_actor", cls=Driver). For an example see the pymeasure_actor.py in the examples folder,
  • a TransparentDirector: director=TransparentDirector(actor="inst_actor"). The actor parameter has to match the Actor's name parameter. For an example of a measurement script see measurement_script.py in the examples folder.

If you want to set some property of the instrument (e.g. instrument.voltage = 5), you can just use the director transparently: director.device.voltage = 5. In the background, the TransparentDirector, which does not have a device, sends a message to the Actor to set that parameter. The Actor in turn sets that parameter of the instrument driver, which in turn will send some command to the device to take an appropriate action (e.g. setting the voltage to 5 V).

Currently you cannot call methods in a similar, transparent way, without manual intervention. You can add RemoteCall descriptor (in transparent_director module) to the director for each method call you want to use. Afterwards you can use these methods transparently similar to the property shown above.

Overview of Offered Packages and Modules

PyLECO offers the following subpackages and modules. For more information and for examples see the docstrings of the relevant methods and classes.

  • The core subpackage contains elements necessary for implementing LECO and for interacting with PyLECO, for example:
    • The Message and DataMessage class help to create and interpret LECO messages for the control and broadcasting protocol, respectively.
    • The leco_protocols module contains Protocol classes for the different LECO Components, in order to test, whether a Component satisfies the LECO standard for communicating with other programs.
    • The internal_protocols module contains Protocol classes which define the API access to PyLECO.
  • The utils subpackage contains modules useful for creating LECO Components.
    • TheCommunicator can send and receive messages, but neither blocks (just for a short time waiting for an answer) nor requires an extra thread. It satisfies the CommunicatorProtocol and is useful in scripts.
    • The MessageHandler also satisfies the CommunicatorProtocol, but handles incoming messages in a continuous loop (blocking until stopped). It is useful for creating standalone scripts, like tasks for the Starter.
    • The ExtendedMessageHandler adds the capability to subscribe and receive data protocol messages.
    • The Listener offers an interface according to the CommunicatorProtocol, but listens at the same time in an extra thread for incoming messages (with an ExtendedMessageHandler). It is useful if you want to react to incoming messages (via data or control protocol) and if you want to send messages of your own accord, for example for GUI applications.
  • The coordinators subpackage contains the different Coordinators.
    • Coordinator is the Coordinator for the control protocol (exchanging messages).
    • proxy_server is the Coordinator for the data protocol (broadcasting).
  • The actors subpackage contains Actor classes to control devices.
  • The management subpackage contains Components useful for experiment management.
    • The Starter can execute tasks in separate threads. A task could be an Actor controlling some Device.
    • The DataLogger listens to published data (via the data protocol) and collects them.
  • The directors subpackage contains Directors, which facilitate controlling actors or management utilities.
    • The Director is a base Director. It can communicate via any util, which implements the CommunicatorProtocol.
    • For example the CoordinatorDirector has a method for getting Coordinators and Components connected to a Coordinator.
    • The TransparentDirector reads / writes all messages to the remote actor, such that you use the director's device as if it were the instrument itself.

PyLECO extras

The pyleco-extras package contains additional modules. Among them are GUIs controlling the DataLogger and the Starter.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyleco-0.6.0.post1.tar.gz (141.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyleco-0.6.0.post1-py3-none-any.whl (112.7 kB view details)

Uploaded Python 3

File details

Details for the file pyleco-0.6.0.post1.tar.gz.

File metadata

  • Download URL: pyleco-0.6.0.post1.tar.gz
  • Upload date:
  • Size: 141.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pyleco-0.6.0.post1.tar.gz
Algorithm Hash digest
SHA256 ec40c508b682a79556bb71486f4ed99167587dbd0fdc2e5bc3bd539454fc8ba0
MD5 347e388da562bfe74d4912518d8d5773
BLAKE2b-256 87974aeb360d13822e8c85d80e29dc9a8b2b630f50820df26beab302f1e2d811

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyleco-0.6.0.post1.tar.gz:

Publisher: python-publish.yml on pymeasure/pyleco

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyleco-0.6.0.post1-py3-none-any.whl.

File metadata

  • Download URL: pyleco-0.6.0.post1-py3-none-any.whl
  • Upload date:
  • Size: 112.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pyleco-0.6.0.post1-py3-none-any.whl
Algorithm Hash digest
SHA256 1217b6871092a647d83adbfb7c22872b19b8a056e2624f4afe6c8744c7a6be5d
MD5 00570cf7d153bc992f7d5b6028edb66f
BLAKE2b-256 19b6135866ef4ac55c3a53fd9d4934ff83e6f71e84b1849df86855d4a76d5929

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyleco-0.6.0.post1-py3-none-any.whl:

Publisher: python-publish.yml on pymeasure/pyleco

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page