Using Database Object
import PyTango
db = PyTango.Database()
Register a new device server
dev = 'SR%02d/VC/ALL'%sector
klass = 'PyStateComposer'
server = klass+'/'+dev.replace('/','_')
di = PyTango.DbDevInfo()
di.name,di._class,di.server = device,klass,server
db.add_device(di)
Remove "empty" servers from database
tango = PyTango.Database()
[tango.delete_server(s)
for s in tango.get_server_list()
if all(d.lower().startswith('dserver') for d in tango.get_device_class_list(s))
]
Force unexport of a failing server
You can check using db object if a device is still exported after killed
In [40]:bool(db.import_device('dserver/HdbArchiver/11').exported)
Out[40]:True
You can unexport this device or server with the following call:
db.unexport_server('HdbArchiver/11')
It would normally allow you to restart the server again.
Get all servers of a given class
class_name = 'Modbus'
list_of_names = ['/'.join((class_name,name)) for name in db.get_instance_name_list(class_name)]
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:
list_of_devs = [dev for dev in db.get_device_class_list(server_name) if '/' in dev and not dev.startswith('dserver')]
Get all devices of a given class from the database
import operator
list_of_devs = reduce(operator.add,(list(dev for dev in db.get_device_class_list(n) \
if '/' in dev and not dev.startswith('dserver')) for n in \
('/'.join((class_name,instance)) for instance in db.get_instance_name_list(class_name)) \
))
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}
prop_names = db.get_device_property_list(device_name)
['property1','property2']
dev_props = db.get_device_property(device_name,prop_names)
{'property1':'first_value' , 'property2':'second_value' }
Get the history (last ten values) of a property
In [188]: [ph.get_value().value_string for ph in tango.get_device_property_history('some/alarms/device','AlarmsList')]
Out[188]:
[['MyAlarm:a/gauge/controller/Pressure>1e-05', 'TempAlarm:a/nice/device/Temperature_Max > 130'],
...
Get the server for a given device
>>> print db.get_server_list('Databaseds/*')
['DataBaseds/2']
>>> print db.get_device_name('DataBaseds/2','DataBase')
['sys/database/2']
>>> db_dev=PyTango.DeviceProxy('sys/database/2')
>>> print db_dev.command_inout('DbImportDevice','et/wintest/01')
([0, 2052], ['et/wintest/01', 'IOR:0100000017000xxxxxx', '4',
'WinTest/manu', 'PCTAUREL.esrf.fr', 'WinTest'])
>>>
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
Set property values for a list of devices
Attention , Tango property values are always inserted as lists! {property_name : [* property_value *]}
prop_name,prop_value = 'Prop1','Value1'
[db.put_device_property(dev,{prop_name:[prop_value]}) for dev in list_of_devs]
Get Starter Level configuration for a list of servers
[(si.name,si.mode,si.level) for si in [db.get_server_info(s) for s in list_of_servers]]
Get Attribute Label (or any config) Offline / using Database
get_database().get_device_attribute_property(dev,['a1','test'])
{'a1': {'event_period': ['1000'], 'rel_change': ['1']},
'test': {'event_period': ['1000'], 'label': ['toast']}}
Set Memorized Value for an Attribute
db.get_device_attribute_property('tcoutinho/serial/01/Baudrate',['__value'])
#deprecated # db.put_device_attribute_property('tcoutinho/serial/01/Baudrate',{'__value':VALUE})
db.put_device_attribute_property('test/sim/tds-1',{'A':{'__value':[1]}})
No comments:
Post a Comment