访问PyTango属性值

时间:2019-01-15 11:00:06

标签: python python-2.7 tango

我正在尝试使用PyTango编写设备服务器。我为服务器创建了一个属性列表。如何通过set_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)

我想从属性x_pixel_size中检索值720。是否可以在不使用服务器中其他变量的情况下做到这一点?

1 个答案:

答案 0 :(得分:0)

当然可以。您可以通过以下方式做到这一点:

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()

您可以使用Python控制台对其进行测试:

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

如果还有其他问题,请提出。但是实际上我使用了其他变量来为我保留属性的值。