Skip to content
Snippets Groups Projects
Select Git revision
  • master default protected
  • all-stations-lofar2
  • L2SS-2357-fix-ruff
  • control-single-hba-and-lba
  • L2SS-1957-remove-pcon-control
  • v0.39.7-backports
  • Move-sdptr-to-v1.5.0
  • fix-build-ubuntu
  • tokens-in-env-files
  • fix-build
  • L2SS-2214-deploy-cdb
  • fix-missing-init
  • add-power-hardware-apply
  • L2SS-2129-Add-Subrack-Routine
  • Also-listen-internal-to-rpc
  • fix-build-dind
  • L2SS-2153--Improve-Error-Handling
  • L2SS-2153-Add-Grpc-Gateway-support
  • L2SS-1970-apsct-lol
  • DNM-pytango10.0.1rc1-test
  • v0.51.9-6 protected
  • v0.51.9-5 protected
  • v0.51.9-4 protected
  • v0.51.9-3 protected
  • v0.51.9-2 protected
  • v0.51.9-1 protected
  • v0.51.9 protected
  • v0.51.8 protected
  • v0.39.15-wsrttwo protected
  • v0.39.15-wsrt protected
  • v0.39.14-wsrt protected
  • v0.51.6 protected
  • v0.51.5-1 protected
  • v0.51.5 protected
  • v0.51.4-2 protected
  • v0.51.4-3 protected
  • v0.51.4-1 protected
  • v0.51.4 protected
  • v0.51.2 protected
  • v0.51.1 protected
40 results

control.rst

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    control.rst 3.05 KiB

    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:

    jupyter_basic_example.png

    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/.