tango.pyaml.attribute#

Scalar Tango attribute access.

This module maps a single Tango attribute (or one element of a SPECTRUM attribute) onto the pyAML DeviceAccess interface.

Classes

Attribute(attribute[, unit, range, index, ...])

Tango attribute that can be written to.

AttributeConfig(*, attribute[, unit, range, ...])

Configuration model for Tango attributes.

class tango.pyaml.attribute.Attribute(attribute, unit='', range=None, index=None, writable=True)#

Bases: DeviceAccess, InitializableElement, DynamicValidation

Tango attribute that can be written to.

The Tango device proxy is obtained lazily from DeviceFactory on first access, so building an Attribute never contacts the control system.

Parameters:
  • attribute (str) – Full path of the Tango attribute (e.g., ‘my/ps/device/current’).

  • unit (str, optional) – The unit of the attribute.

  • range (tuple(min, max), optional) – Range of valid values. Use null for -∞ or +∞.

  • index (int, optional) – Zero-based index into a SPECTRUM attribute. When set, the instance behaves as a read-only scalar view of one vector element; writes are always rejected and a SPECTRUM data_format is enforced on init.

  • writable (bool, optional) – If the attribute should be writable. Default is True.

_attribute#

Full path of the Tango attribute.

Type:

str

_unit#

Unit of the attribute.

Type:

str

_range#

Configured range, or None to query Tango on first use.

Type:

tuple of (float or None, float or None) or None

_index#

Index into a SPECTRUM attribute, or None for scalar access.

Type:

int or None

_writable#

True if writes are allowed (always False when indexed).

Type:

bool

_attribute_dev#

Proxy of the device owning the attribute, set on initialization.

Type:

tango.DeviceProxy or None

_attr_config#

Tango attribute configuration, set on initialization.

Type:

tango.AttributeInfoEx or None

_attribute_dev_name#

Device part of the attribute path, set on initialization.

Type:

str or None

_attr_name#

Attribute part of the attribute path, set on initialization.

Type:

str or None

initialize()#

Connect to the Tango device and check the attribute configuration.

is_writable()#

Tell whether the attribute accepts writes.

set(value)#

Write a value asynchronously to the Tango attribute.

set_and_wait(value)#

Write a value synchronously to the Tango attribute.

get()#

Get the last written value of the attribute.

readback()#

Return the readback value with metadata.

unit()#

Return the unit of the attribute.

name()#

Return the full attribute name.

measure_name()#

Return the short attribute name (last component).

get_tango_attribute()#

Return the raw Tango attribute path without index decoration.

clone_with_tango_attribute(attribute)#

Return a shallow copy configured with another Tango attribute path.

get_range()#

Return the valid range of the attribute.

check_device_availability()#

Check whether the Tango device answers to a ping.

Raises:

pyaml.PyAMLException – If the Tango attribute is not writable.

check_device_availability()#

Check whether the Tango device answers to a ping.

Returns:

boolTrue if the device is reachable, False if initialization or the ping fails.

Return type:

bool

clone_with_tango_attribute(attribute)#

Return a shallow copy configured with another Tango attribute path.

Parameters:

attribute (str) – Tango attribute path to store in the cloned instance.

Returns:

Attribute – Copy of this instance pointing to attribute.

Return type:

Attribute

get()#

Get the last written value of the attribute.

For indexed attributes, returns the setpoint element at the configured index (w_value[index]).

Returns:

float – The last written value.

Raises:

pyaml.PyAMLException – If the Tango read fails.

Return type:

float

get_range()#

Return the valid range of the attribute.

The configured range takes precedence; otherwise the min_value and max_value limits of the Tango attribute configuration are used, which requires initialization.

Returns:

list of float or None[min, max] where an unbounded limit is None.

Raises:

pyaml.PyAMLException – If no range is configured and initialization fails.

Return type:

list[float]

get_tango_attribute()#

Return the raw Tango attribute path without index decoration.

Returns:

str – Tango attribute path stored in the configuration.

Return type:

str

initialize()#

Connect to the Tango device and check the attribute configuration.

Splits the attribute path into device and attribute names, obtains the device proxy from DeviceFactory and reads the attribute configuration.

Raises:

pyaml.PyAMLException – If the device proxy cannot be created, if an indexed attribute is not a SPECTRUM, or if a writable attribute is not writable in Tango.

is_writable()#

Tell whether the attribute accepts writes.

Returns:

boolTrue if set() and set_and_wait() are allowed.

measure_name()#

Return the short attribute name (last component).

Returns:

str – The attribute name (e.g., ‘current’), with index notation when indexed (e.g., ‘current[2]’).

Return type:

str

name()#

Return the full attribute name.

Returns:

str – The attribute path (e.g., ‘my/ps/device/current’), or with index notation when indexed (e.g., ‘my/ps/device/current[2]’).

Return type:

str

readback()#

Return the readback value with metadata.

Returns:

Value – The readback value including quality and timestamp.

Raises:

pyaml.PyAMLException – If the Tango read fails.

Return type:

Value

set(value)#

Write a value asynchronously to the Tango attribute.

Parameters:

value (float) – Value to write to the attribute.

Raises:

pyaml.PyAMLException – If the Tango write fails or this is an indexed attribute.

set_and_wait(value)#

Write a value synchronously to the Tango attribute.

Parameters:

value (float) – Value to write to the attribute.

Raises:

pyaml.PyAMLException – If the Tango write fails or this is an indexed attribute.

unit()#

Return the unit of the attribute.

Returns:

str – The unit string.

Return type:

str

class tango.pyaml.attribute.AttributeConfig(*, attribute, unit='', range=None, index=None)#

Bases: BaseModel

Configuration model for Tango attributes.

attribute#

Full path of the Tango attribute (e.g., ‘my/ps/device/current’).

Type:

str

unit#

The unit of the attribute.

Type:

str, optional

range#

Range of valid values. Use null for -∞ or +∞.

Type:

tuple(min, max), optional

index#

Zero-based index into a SPECTRUM attribute. When set, the instance behaves as a read-only scalar view of one vector element; writes are always rejected and a SPECTRUM data_format is enforced on init.

Type:

int, optional

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

model_config: ClassVar[ConfigDict] = {}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].