How to PyTango

Before anything else

import PyTango

Installation notes

The new PyTango, release 7.1.3 (source only), is now available to download from the Tango download page:

http://www.tango-controls.org/download

or PiPy:

http://pypi.python.org/pypi/PyTango/7.1.3

If you have already installed PyTango 7.x.x with easy_install you can simply update your PyTango version to 7.1.3 by doing:

% easy_install -U PyTango

The documentation is available at:

http://www.esrf.fr/computing/cs/tango/tango_doc/kernel_doc/pytango/latest/index.html

If you encounter problems installing or running this release, please report them back to the tango mailing list.

READ  Phân biệt cách dùng how much và how many để tránh nhầm lẫn

This version has been tagged Release_7_1_3

You can check out this version:

svn co https://tango-cs.svn.sourceforge.net/svnroot/tango-cs/PyTango/tags/Release_7_1_3 PyTango-7.1.3

You can check out the latest version:

svn co https://tango-cs.svn.sourceforge.net/svnroot/tango-cs/PyTango/trunk PyTango-latest

Nice PyTango dancing

Tiago Coutinho

Using the DeviceProxy object

Getting the polling buffer values

Only for polled attributes we can get the last N read values. the polling buffer depth is managed by the admin device.

Get/Set polled attributes

Modify the polling of attributes

Events

Creating an event callback

Configuring an event

Pushing the event

Device Server Internal Objects

Forcing in which host the device is exported

This environment variable must be set before launching the device:

user@bash:/> export OMNIORB_USEHOSTNAME=10.0.0.10

Creating a Device Server from ipython

Having defined your device in MyDS.py:

1: from MyDS import * 2: py = PyTango.PyUtil([‘MyDS.py’,’InstanceName’]) 3: py.add_TgClass(MyDSClass,MyDS,’MyDS’) 4: U = PyTango.Util.instance() 5: U.server_init() 6: U.server_run()

Get the device server admin

NOT TESTED

U = PyTango.Util.instance() U.get_dserver_device()

Modify internal polling

NOTE: It doesn’t work at init_device(); must be done later on in a hook method

U = PyTango.Util.instance() admin = U.get_dserver_device() dir(admin) [ StartPolling StopPolling AddObjPolling RemObjPolling UpdObjPollingPeriod DevPollStatus PolledDevice ] polled_attrs = {} for st in admin.DevPollStatus(name): lines = st.split(‘n’) try: polled_attrs[lines[0].split()[-1]]=lines[1].split()[-1] except: pass type_ = ‘command’ or ‘attribute’ for aname in args: if aname in polled_attrs: admin.UpdObjPollingPeriod([[200],[name,type_,aname]]) else: admin.AddObjPolling([[3000],[name,type_,aname]])

Get all polling attributes

The polling of the attributes is recorded in the property_device table of the tango database in the format of a list like [ATTR1,PERIOD1,ATTR2,PERIOD2,…]

The list of polled attributes can be accessed using this method of admin device:

dp = PyTango.DeviceProxy(‘dserver/myServerClass/id22’) polled_attrs = [a.split(‘n’)[0].split(‘ ‘)[-1] for a in dp.DevPollStatus(‘domain/family/member-01’)]

Get the device class object from the device itself

self.get_device_class()

READ  Cập nhật các đầu số VinaPhone mới nhất hiện nay

Get the devices inside a Device Server

def get_devs_in_server(self,MyClass=None): “”” Method for getting a dictionary with all the devices running in this server “”” MyClass = MyClass or type(self) or DynamicDS if not hasattr(MyClass,’_devs_in_server’): MyClass._devs_in_server = {} #This dict will keep an access to the class objects instantiated in this Tango server if not MyClass._devs_in_server: U = PyTango.Util.instance() for klass in U.get_class_list(): for dev in U.get_device_list_by_class(klass.get_name()): if isinstance(dev,DynamicDS): MyClass._devs_in_server[dev.get_name()]=dev return MyClass._devs_in_server

Identify each attribute inside read_attr_hardware()

Device server logging (using Tango logs)

Or use fandango.Logger object instead …

Adding dynamic attributes to a device

Using Database Object

Register a new device server

Remove “empty” servers from database

Force unexport of a failing server

You can check using db object if a device is still exported after killed

You can unexport this device or server with the following call:

It would normally allow you to restart the server again.

Get all servers of a given class

Differences between DB methods:

  • get_instance_name_list(exec_name): return names of instances
  • get_server_list(): returns list of all executable/instance
  • get_server_name_list(): return names of all executables

Get all devices of a server or a given class

The command is:

  • db.get_device_class_list(server_name): return [‘device/name/family’,’device_class’]*num_of_devs_in_server

The list returned includes the admin server (dserver/exec_name/instance) that must be pruned from the result:

Get all devices of a given class from the database

Get property values for a list of devices

  • db.get_device_property_list(device_name,’*’) : returns list of available properties
  • db.get_device_property(device_name,[property_name]) : return {property_name : value}

Get the history (last ten values) of a property

Get the server for a given device

Get the Info of a not running device (exported, host, server)

def get_device_info(dev): vals = PyTango.DeviceProxy(‘sys/database/2’).DbGetDeviceInfo(dev) di = dict((k,v) for k,v in zip((‘name’,’ior’,’level’,’server’,’host’,’started’,’stopped’),vals[1])) di[‘exported’],di[‘PID’] = vals[0] return di

READ  Nhiễu xạ ánh sáng

Set property values for a list of devices

Attention , Tango property values are always inserted as lists! {property_name : [ property_value ]}

Get Starter Level configuration for a list of servers

Set Memorized Value for an Attribute

db.get_device_attribute_property(‘tcoutinho/serial/01/Baudrate’,[‘__value’]) db.put_device_attribute_property(‘tcoutinho/serial/01/Baudrate’,{‘__value’:VALUE})

Useful constants and enums

Using Tango Groups

This example uses PyTangoGroup? to read the status of all devices in a Device Server

About Exceptions

Be aware that I’m not sure about all of this:

Passing Arguments to Device command_inout

When type of Arguments is special like DevVarLongStringArray the introduction of arguments is something like:

In [25]:api.manager.command_inout(‘UpdateSnapComment’,[[40],[‘provant,provant…’]])

Using asynchronous commands

Setting Attribute Config

for server in astor.values(): for dev in server.get_device_list(): dp = server.get_proxy(dev) attrs = dp.get_attribute_list() if dev.rsplit(‘/’)[-1].lower() not in [a.lower() for a in attrs]: continue conf = dp.get_attribute_config(dev.rsplit(‘/’)[-1]) conf.format = “%1.1e” conf.unit = “mbar” conf.label = “%s-Pressure”%dev print ‘setting config for %s/%s’ % (dev,conf.name) dp.set_attribute_config(conf)

Porting device servers to PyTango7

The changes to easily port PyTango?<7 devices are:

  • C++ : Replace Device_3Impl with Device_4Impl
  • Python : Replace Device_3Impl with Device_4Impl, PyDeviceClass? with DeviceClass? and PyUtil? with Util.

If you are quite lazy you can add this at the beginning of your $Class.py file (and be still parseable by Pogo):

Simplify changes by adding this line

if ‘PyUtil’ not in dir(PyTango): PyTango.PyDeviceClass = PyTango.DeviceClass PyTango.PyUtil = PyTango.Util