1

I'm trying to write a device server with PyTango. I created a list of Attributes for the Server. How do I access the value stored in the attributes by the set_value() function?

If I have this attribute for example, how can I retrieve the value?

x_pixel_size = attribute(label = "x pixel size", dtype=float,
                         display_level = DispLevel.OPERATOR,
                         unit = 'microns', format='5.2f',
                         access = AttrWriteType.READ,
                         doc = 'Size of a single pixel along x-axis
                         of the detector')
self.x_pixel_size.set_value(720)

I want to retrieve the value 720 from the Attribute x_pixel_size. Is there a way to do this without using additional variables in the server?

NeilenMarais
  • 2,949
  • 1
  • 25
  • 23

1 Answers1

1

Of course it is possible. You can do this in this way:

from PyTango.server import run
from PyTango.server import Device, DeviceMeta
from PyTango.server import attribute, command, device_property
from PyTango import AttrQuality, AttrWriteType, DispLevel


class DeviceClass(Device):
    __metaclass__ = DeviceMeta 

    def init_device(self):
        self.x_pixel_size.set_write_value(720)

    x_pixel_size = attribute(label = "x pixel size", dtype=float,
                         display_level = DispLevel.OPERATOR,
                         unit = 'microns', format='5.2f',
                         access = AttrWriteType.READ_WRITE,
                         doc = 'Size of a single pixel along x-axis of the detector')
    def write_x_pixel_size(self, value):
        pass
    def read_x_pixel_size(self):
        return self.x_pixel_size.get_write_value() 


def main():
    run((DeviceClass,))

if __name__ == "__main__":
    main()

And you can test it using Python console:

>>> from PyTango import DeviceProxy
>>> dev = DeviceProxy('test/device/1')
>>> dev.x_pixel_size
720.0
>>> dev.x_pixel_size = 550
>>> dev.x_pixel_size
550.0
>>>

If you have any further questions, just ask. But actually I use additional variables for keeping the attribute's value for me.

Jagoda Gorus
  • 329
  • 4
  • 18
  • Hi, it was quite a long time ago when I answered your question. Was it helpful? If yes, please accept the answer. ;) – Jagoda Gorus Mar 04 '20 at 09:46