control.rst
-
Jan David Mol authoredJan David Mol authored
Monitoring & Control
The main API to control the station is through the Tango Controls API we expose on port 10000, which is most easily accessed using a PyTango client. The Jupyter Notebook installation we provide is such a client.
Jupyter Notebooks
The station offers Juypyter notebooks On http://localhost:8888, which allow one to interact with the station, for example to set control points, access monitoring points, or to graph their values.
The notebooks provide some predefined variables, so you don't have to look them up:
Note: the Jupyter notebooks use enhancements from the itango
suite, which provide tab completions, but also the Device
alias for DeviceProxy
as was used in the Python examples in the next section.
For example, you can start a new Station Control notebook (File->New Notebook->StationControl), and access these devices:

PyTango
To access a station from scratch using Python, we need to install some dependencies:
pip3 install tango
Then, if we know what devices are available on the station, we can access them directly:
import tango
import os
# Tango needs to know where our Tango API is running.
os.environ["TANGO_HOST"] = "localhost:10000"
# Construct a remote reference to a specific device.
# One can also use "tango://localhost:10000/LTS/Boot/1" if TANGO_HOST is not set
boot_device = tango.DeviceProxy("LTS/Boot/1")
# Print the device's state.
print(boot_device.state())
To obtain a list of all devices, we need to access the database:
import tango
# Tango needs to know where our Tango API is running.
import os
os.environ["TANGO_HOST"] = "localhost:10000"
# Connect to the database.
db = tango.Database()
# Retrieve the available devices, excluding any Tango-internal ones.
# This returns for example: ['LTS/Boot/1', 'LTS/Docker/1', ...]
devices = list(db.get_device_exported("LTS/*"))
# Connect to any of them.
any_device = tango.DeviceProxy(devices[0])
# Print the device's state.
print(any_device.state())
ReST API
We also provide a ReST API to allow the station to be controlled without needing to use the Tango API. The root access point is http://localhost:8080/tango/rest/v10/hosts/databaseds;port=10000/ (credentials: tango-cs/tango). This API allows for:
- getting and setting attribute values,
- calling commands,
- retrieving the device state,
- and more.
For example, retrieving http://localhost:8080/tango/rest/v10/hosts/databaseds;port=10000/devices/LTS/SDP/1/state returns the following JSON document:
{"state":"ON","status":"The device is in ON state."}
For a full description of this API, see https://tango-rest-api.readthedocs.io/en/latest/.