Package: pyleco
PyLECOPython reference implementation of theLaboratory Experiment COntrol (LECO) protocol.Thereviewed branchcontains reviewed code, which does not yet contain all necessary modules and classes.
Development happens in themainbranch.Note: LECO is still under development, such that the code and API might change.
The LECO protocol branchpyleco-statecontains the assumptions used in this project, which are not yet accepted into the LECO main branch.
These things might change, if LECO defines them differently.For a tutorial on how to get started, seeGETTING_STARTED.md.Quick StartInstall Python,Executepip install pyleco,Importpylecoin your python scripts.LECO OverviewNetwork TopologyPyLECO is an implementation of LECO, for the full protocol specifications please visithttps://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.The control protocol allows to exchange messages between any two Components in a LECO network, which is useful for controlling devices.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 exampleN1.component1is the full name ofcomponent1connected to the Coordinator of the NamespaceN1.
The Coordinator istelf is always calledCOORDINATOR.Remote Procedure CallsThe default messaging content of the control protocol are remote procedure calls (RPC) according to jsonrpc.
With these RPCs you execute a method on the 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 theset_outputmethod 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 ProtocolMinimum SetupFor a minimum setup, you need:a Coordinator (just executecoordinatorin your terminal or run thecoordinator.pyfile with your Python interpreter)one ComponentFor example, you can use aCommunicatorinstance to send/receive messages via LECO protocol.
The following example requests the list of Components connected to the Coordinator:frompyleco.utils.communicatorimportCommunicatorc=Communicator(name="TestCommunicator")connected_components=c.ask_rpc(method="send_local_components")print(connected_components)Instrument ControlLet's say you have an instrument with a pymeasure driverDriver, which you want to control.You need to start (in different threads):a Coordinator (as shown above).anActorinstance listening to commands and controlling the instrument:actor = Actor(name="inst_actor", cls=Driver).
For an example see thepymeasure_actor.pyin the examples folder.aTransparentDirector:director=TransparentDirector(actor="inst_actor"). Theactorparameter has to match the Actor'snameparameter.
For an example of a measurement script seemeasurement_script.pyin the examples folder.If you want to set some property of the instrument (e.g.instrument.voltage = 5), you can just use thedirectortransparently:director.device.voltage = 5.
In the background, the TransparentDirector, which does not have adevice, 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 addRemoteCalldescriptor (in transparent_director module) to thedirectorfor 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 ModulesSee the docstrings of the individual classes for more information and for examples.Thecoresubpackage contains elements necessary for implementing LECO, especially theMessageclass, which helps to create and interpret LECO messages.Theutilssubpackage contains modules useful for creating LECO Components.TheCommunicatorcan send and receive messages, but neither blocks (just for a short time waiting for an answer) nor requires an extra thread.
It is useful for usage in scripts.TheMessageHandlerhandles incoming messages in a continuous loop (blocking until stopped).
It is useful for creating standalone scripts, like tasks for the Starter.TheListeneroffers the same interface as the Communicator, but listens in an extra thread for incoming messages.
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.Thecoordinatorssubpackage contains the differenc Coordinators.Coordinatoris the Coordinator for the control protocol (exchanging messages).proxy_serveris the Coordinator for the data protocol (broadcasting).Theactorssubpackage contains Actor classes to control devices.Themanagementsubpackage contains Components useful for experiment managementTheStartercan execute tasks in separate threads.
A task could be an Actor controlling some Device.TheDataLoggerlistens to published data (data protocol) and collects them.Thedirectorssubpackage contains Directors, which facilitate controlling actors or management utilities.For example theCoordinatorDirectorhas a method for getting Coordinators and Components connected to a Coordinator.TheTransparentDirectorreads / writes all messages to the remote actor, such that you use the director'sdeviceas if it were the instrument itself.PyLECO extrasThepyleco-extraspackage contains additional modules.
Among them are GUIs controlling theDataLoggerand theStarter.