How to use the sardana.sardanaattribute.SardanaAttribute function in sardana

To help you get started, we’ve selected a few sardana examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sardana-org / sardana / src / sardana / tango / pool / TriggerGate.py View on Github external
try:
            attr = self.get_attribute_by_name(name)
        except DevFailed:
            return

        quality = AttrQuality.ATTR_VALID
        priority = event_type.priority
        value, w_value, error = None, None, None

        if name == "state":
            value = self.calculate_tango_state(event_value)
        elif name == "status":
            value = self.calculate_tango_status(event_value)
        else:
            if isinstance(event_value, SardanaAttribute):
                if event_value.error:
                    error = Except.to_dev_failed(*event_value.exc_info)
                else:
                    value = event_value.value
                timestamp = event_value.timestamp
            else:
                value = event_value

        self.set_attribute(attr, value=value, w_value=w_value,
                           timestamp=timestamp, quality=quality,
                           priority=priority, error=error, synch=False)
github sardana-org / sardana / src / sardana / tango / pool / PseudoCounter.py View on Github external
except DevFailed:
            return

        quality = AttrQuality.ATTR_VALID
        priority = event_type.priority
        value, w_value, error = None, None, None

        if name == "state":
            value = self.calculate_tango_state(event_value)
        elif name == "status":
            value = self.calculate_tango_status(event_value)
        elif name == "valuebuffer":
            value = self._encode_value_chunk(event_value)
            self._first_read_cache = True
        elif name == "value":
            if isinstance(event_value, SardanaAttribute):
                # first obtain the value - during this process it may
                # enter into the error state, either when updating the elements
                # values or when calculating the pseudo value
                value = event_value.value
                if event_value.error:
                    error = Except.to_dev_failed(*event_value.exc_info)
                timestamp = event_value.timestamp
            else:
                value = event_value

            state = self.pseudo_counter.get_state(propagate=0)
            if state == State.Moving:
                quality = AttrQuality.ATTR_CHANGING
        else:
            if isinstance(event_value, SardanaAttribute):
                if event_value.error:
github sardana-org / sardana / src / sardana / tango / pool / TwoDExpChannel.py View on Github external
try:
            attr = self.get_attribute_by_name(name)
        except DevFailed:
            return

        quality = AttrQuality.ATTR_VALID
        priority = event_type.priority
        value, w_value, error = None, None, None

        if name == "state":
            value = self.calculate_tango_state(event_value)
        elif name == "status":
            value = self.calculate_tango_status(event_value)
        else:
            if isinstance(event_value, SardanaAttribute):
                if event_value.error:
                    error = Except.to_dev_failed(*event_value.exc_info)
                else:
                    value = event_value.value
                timestamp = event_value.timestamp

            if name == "value":
                state = self.twod.get_state()
                if state == State.Moving:
                    quality = AttrQuality.ATTR_CHANGING
        self.set_attribute(attr, value=value, w_value=w_value,
                           timestamp=timestamp, quality=quality,
                           priority=priority, error=error, synch=False)
github sardana-org / sardana / src / sardana / pool / poolzerodexpchannel.py View on Github external
self.start_time = timestamp
            self.value = value
        else:
            last_value, last_timestamp = self.last_value
            dt = timestamp - last_timestamp
            self.sum += dt * (last_value + value) / 2
            total_dt = timestamp - self.start_time
            self.value = self.sum / total_dt
            self.last_value = value, timestamp


def get_accumulation_class(ctype):
    return globals()[ctype + "Accumulation"]


class CurrentValue(SardanaAttribute):

    def update(self, cache=True, propagate=1):
        if not cache or not self.has_value():
            value = self.obj.read_current_value()
            self.set_value(value, propagate=propagate)


class Value(SardanaAttribute):

    DefaultAccumulationType = "Average"

    def __init__(self, *args, **kwargs):
        accumulation_type = kwargs.pop(
            'accumulation_type', self.DefaultAccumulationType)
        super(Value, self).__init__(*args, **kwargs)
        self.set_accumulation_type(accumulation_type)
github sardana-org / sardana / src / sardana / pool / poolzerodexpchannel.py View on Github external
self.last_value = value, timestamp


def get_accumulation_class(ctype):
    return globals()[ctype + "Accumulation"]


class CurrentValue(SardanaAttribute):

    def update(self, cache=True, propagate=1):
        if not cache or not self.has_value():
            value = self.obj.read_current_value()
            self.set_value(value, propagate=propagate)


class Value(SardanaAttribute):

    DefaultAccumulationType = "Average"

    def __init__(self, *args, **kwargs):
        accumulation_type = kwargs.pop(
            'accumulation_type', self.DefaultAccumulationType)
        super(Value, self).__init__(*args, **kwargs)
        self.set_accumulation_type(accumulation_type)

    def get_val(self):
        return self.obj.get_value_attribute()

    def set_accumulation_type(self, ctype):
        klass = get_accumulation_class(ctype)
        self._accumulation = klass()
github sardana-org / sardana / src / sardana / tango / pool / MeasurementGroup.py View on Github external
if name == "state":
            event_value = self.calculate_tango_state(event_value)
        elif name == "status":
            event_value = self.calculate_tango_status(event_value)
        elif name == "acquisitionmode":
            event_value = AcqMode.whatis(event_value)
        elif name == "configuration":
            cfg = self.measurement_group.get_user_configuration()
            codec = CodecFactory().getCodec('json')
            _, event_value = codec.encode(('', cfg))
        elif name == "synchronization":
            codec = CodecFactory().getCodec('json')
            _, event_value = codec.encode(('', event_value))
        else:
            if isinstance(event_value, SardanaAttribute):
                if event_value.error:
                    error = Except.to_dev_failed(*event_value.exc_info)
                timestamp = event_value.timestamp
                event_value = event_value.value

        self.set_attribute(attr, value=event_value, timestamp=timestamp,
                           quality=quality, priority=priority, error=error,
                           synch=False)
github taurus-org / taurus / src / sardana / tango / macroserver / Door.py View on Github external
multi_attr = self.get_device_attr()
        try:
            attr = multi_attr.get_attr_by_name(name)
        except DevFailed:
            return
        
        if name == "state":
            event_value = self.calculate_tango_state(event_value)
        elif name == "status":
            event_value = self.calculate_tango_status(event_value)
        elif name == "recorddata":
            format, value = event_value
            codec = CodecFactory().getCodec(format)
            event_value = codec.encode(('', value))
        else:
            if isinstance(event_value, SardanaAttribute):
                if event_value.error:
                    error = Except.to_dev_failed(*event_value.exc_info)
                timestamp = event_value.timestamp
                event_value = event_value.value
            
            if attr.get_data_type() == ArgType.DevEncoded:
                codec = CodecFactory().getCodec('json')
                event_value = codec.encode(('', event_value))
        self.set_attribute(attr, value=event_value, timestamp=timestamp)
github sardana-org / sardana / src / sardana / pool / poolpseudocounter.py View on Github external
except LateValueException:
                    self.remove_physical_values(idx)
                    break
                physical_values.append(value)
            else:
                # loop collected all values so we can proceed to calculate
                value = self.obj.calc(physical_values)
                self.append(value, idx)
                self.remove_physical_values(idx)

    def remove_physical_values(self, idx, force=False):
        for value_buf in self.obj.get_physical_value_buffer_iterator():
            if force or not value_buf.is_value_required(idx):
                value_buf.remove(idx)

class Value(SardanaAttribute):

    def __init__(self, *args, **kwargs):
        self._exc_info = None
        super(Value, self).__init__(*args, **kwargs)
        for value_attr in self.obj.get_physical_value_attribute_iterator():
            value_attr.add_listener(self.on_change)

    def _in_error(self):
        for value_attr in self.obj.get_physical_value_attribute_iterator():
            if value_attr.error:
                return True
        return self._exc_info is not None

    def _has_value(self):
        for value_attr in self.obj.get_physical_value_attribute_iterator():
            if not value_attr.has_value():
github sardana-org / sardana / src / sardana / pool / poolioregister.py View on Github external
"""This module is part of the Python Pool libray. It defines the base classes
for """

__all__ = ["PoolIORegister"]

__docformat__ = 'restructuredtext'

import time

from sardana import ElementType
from sardana.sardanaattribute import SardanaAttribute
from sardana.pool.poolelement import PoolElement
from sardana.pool.poolacquisition import PoolIORAcquisition


class Value(SardanaAttribute):

    def __init__(self, *args, **kwargs):
        super(Value, self).__init__(*args, **kwargs)

    def update(self, cache=True, propagate=1):
        if not cache or not self.has_value():
            value = self.obj.read_value()
            self.set_value(value, propagate=propagate)


class PoolIORegister(PoolElement):

    def __init__(self, **kwargs):
        kwargs['elem_type'] = ElementType.IORegister
        PoolElement.__init__(self, **kwargs)
        self._value = Value(self, listeners=self.on_change)
github sardana-org / sardana / src / sardana / pool / poolmotor.py View on Github external
__docformat__ = 'restructuredtext'

import time
import math

from sardana import EpsilonError, State, ElementType
from sardana.sardanaattribute import SardanaAttribute, ScalarNumberAttribute, \
    SardanaSoftwareAttribute
from sardana.sardanaevent import EventType
from sardana.sardanautils import assert_type, is_number, py2_round
from sardana.pool.poolelement import PoolElement
from sardana.pool.poolmotion import PoolMotion, MotionState


class Position(SardanaAttribute):

    def __init__(self, *args, **kwargs):
        super(Position, self).__init__(*args, **kwargs)
        self.get_offset().add_listener(self.on_change)
        self.get_sign().add_listener(self.on_change)
        self.get_dial().add_listener(self.on_change)

    def get_dial(self):
        return self.obj.get_dial_position_attribute()

    def get_offset(self):
        return self.obj.get_offset_attribute()

    def get_sign(self):
        return self.obj.get_sign_attribute()