继续上几篇:
Ubuntu安装Tango Control教程
自定义Tango Control设备服务在Ubuntu中的测试
Ubuntu安装PyTango步骤
文章目录
环境
- 虚拟机:VMware
- Ubuntun:20.04LTS
- Tango:9.3.5
自带例程PyTango测试
把Tango和Jive启动:
sudo /usr/local/tango/bin/tango start
/usr/local/tango/bin/jive &
服务端启动
在/usr/local/tango/bin启动
./TangoTest test
客户端测试
>>> import tango
>>> # create a device object
>>> test_device = tango.DeviceProxy("sys/tg_test/1")
>>> # every device has a state and status which can be checked with:
>>> print(test_device.state())
RUNNING
>>> print(test_device.status())
The device is in RUNNING state.
>>> # this device has an attribute called "long_scalar". Let's see which value it has...
>>> data = test_device.read_attribute("long_scalar")
>>> # ...PyTango provides a shortcut to do the same:
>>> data = test_device["long_scalar"]
>>> # the result of reading an attribute is a DeviceAttribute python object.
>>> # It has a member called "value" which contains the value of the attribute
>>> data.value
136
>>> # Check the complete DeviceAttribute members:
>>> print(data)
DeviceAttribute[
data_format = SCALAR
dim_x = 1
dim_y = 0
has_failed = False
is_empty = False
name = 'long_scalar'
nb_read = 1
nb_written = 1
quality = ATTR_VALID
r_dimension = AttributeDimension(dim_x = 1, dim_y = 0)
time = TimeVal(tv_nsec = 0, tv_sec = 1399450183, tv_usec = 323990)
type = DevLong
value = 136
w_dim_x = 1
w_dim_y = 0
w_dimension = AttributeDimension(dim_x = 1, dim_y = 0)
w_value = 0]
>>> # PyTango provides a handy pythonic shortcut to read the attribute value:
>>> test_device.long_scalar
136
>>> # Setting an attribute value is equally easy:
>>> test_device.write_attribute("long_scalar", 8776)
>>> # ... and a handy shortcut to do the same exists as well:
>>> test_device.long_scalar = 8776
>>> # TangoTest has a command called "DevDouble" which receives a number
>>> # as parameter and returns the same number as a result. Let's
>>> # execute this command:
>>> test_device.command_inout("D