Miscellaneous#
Util#
- class tango.Util(args)#
This class is a used to store TANGO device server process data and to provide the user with a set of utility methods.
This class is implemented using the singleton design pattern. Therefore a device server process can have only one instance of this class and its constructor is not public. Example:
util = tango.Util.instance() print(util.get_host_name())
- add_Cpp_TgClass(device_class_name, tango_device_class_name)#
Register a new C++ tango class.
If there is a shared library file called MotorClass.so which contains a MotorClass class and a _create_MotorClass_class method. Example:
util.add_Cpp_TgClass('MotorClass', 'Motor')
Note
the parameter ‘device_class_name’ must match the shared library name.
Deprecated since version 7.1.2: Use
tango.Util.add_class()instead.
- add_TgClass(klass_device_class, klass_device, device_class_name=None)#
Register a new python tango class. Example:
util.add_TgClass(MotorClass, Motor) util.add_TgClass(MotorClass, Motor, 'Motor') # equivalent to previous line
Deprecated since version 7.1.2: Use
tango.Util.add_class()instead.
- add_class(self, class<DeviceClass>, class<DeviceImpl>, language="python") None#
Register a new tango class (‘python’ or ‘c++’).
If language is ‘python’ then args must be the same as
tango.Util.add_TgClass(). Otherwise, args should be the ones intango.Util.add_Cpp_TgClass(). Example:util.add_class(MotorClass, Motor) util.add_class('CounterClass', 'Counter', language='c++')
Added in version 7.1.2.
- connect_db(self: tango._tango.Util) None#
Connect the process to the TANGO database. If the connection to the database failed, a message is displayed on the screen and the process is aborted
- create_device(self, klass_name, device_name, alias=None, cb=None) None#
Creates a new device of the given class in the database, creates a new DeviceImpl for it and calls init_device (just like it is done for existing devices when the DS starts up)
An optional parameter callback is called AFTER the device is registered in the database and BEFORE the init_device for the newly created device is called
- Parameters:
klass_name (
str) – the device class namedevice_name (
str) – the device namealias (
str) – optional alias. Default value is None meaning do not create device aliascb (
typing.Callable) – a callback that is called AFTER the device is registered in the database and BEFORE the init_device for the newly created device is called. Typically you may want to put device and/or attribute properties in the database here. The callback must receive a parameter device_name (str). Default value is None meaning no callback
- Throws:
-
the device name exists already or
the given class is not registered for this DS.
the cb is not a callable
Added in version 7.1.2.
- delete_device(klass_name: str, device_name: str) None#
Deletes an existing device from the database and from this running server
- Parameters:
- Throws:
-
the device name doesn’t exist in the database
the device name doesn’t exist in this DS.
Added in version 7.1.2.
- fill_attr_polling_buffer(device: DeviceImpl, attribute_name: str, attr_history_stack: TimedAttrData | list[TimedAttrData]) None#
Fill attribute polling buffer with your own data. E.g.:
def fill_history(): util = Util.instance(False) # note is such case quality will ATTR_VALID, and time_stamp will be time.time() util.fill_attr_polling_buffer(device, attribute_name, TimedAttrData(my_new_value))
or:
def fill_history(): util = Util.instance(False) data = TimedAttrData(value=my_new_value, quality=AttrQuality.ATTR_WARNING, w_value=my_new_w_value, time_stamp=my_time) util.fill_attr_polling_buffer(device, attribute_name, data)
or:
def fill_history(): util = Util.instance(False) data = [TimedAttrData(my_new_value), TimedAttrData(error=RuntimeError("Cannot read value")] util.fill_attr_polling_buffer(device, attribute_name, data)
- Parameters:
device (
tango.DeviceImpl) – the device to fill attribute polling bufferattribute_name (
str) – name of the attribute to fill polling bufferattr_history_stack (
tango.TimedAttrDataor list[tango.TimedAttrData]) – data to be inserted.
- Raises:
Added in version 10.1.0.
- fill_cmd_polling_buffer(device: DeviceImpl, command_name: str, cmd_history_stack: TimedCmdData | list[TimedCmdData]) None#
Fill attribute polling buffer with your own data. E.g.:
def fill_history(): util = Util.instance(False) # note is such time_stamp will be set to time.time() util.fill_cmd_polling_buffer(device, command_name, TimedCmdData(my_new_value))
or:
def fill_history(): util = Util.instance(False) data = TimedCmdData(value=my_new_value, time_stamp=my_time) util.fill_cmd_polling_buffer(device, command_name, data)
or:
def fill_history(): util = Util.instance(False) data = [TimedCmdData(my_new_value), TimedCmdData(error=RuntimeError("Cannot read value")] util.fill_cmd_polling_buffer(device, command_name, data)
- Parameters:
device (
tango.DeviceImpl) – the device to fill command polling buffercommand_name (
str) – name of the command to fill polling buffercmd_history_stack (
tango.TimedCmdDataor list[tango.TimedCmdData]) – data to be inserted
- Raises:
Added in version 10.1.0.
- get_class_list() list[DeviceClass]#
Returns a list of objects of inheriting from DeviceClass
- get_database(self: tango._tango.Util) tango._tango.Database#
Get a reference to the TANGO database object
Added in version 7.0.0.
- get_device_by_name(self: tango._tango.Util, dev_name: str) object#
Get a device reference from its name
- Parameters:
dev_name (
str) – The TANGO device name- Return type:
DeviceImpl
Added in version 7.0.0.
- get_device_ior(self: tango._tango.Util, device: tango._tango.DeviceImpl) str#
Get the CORBA Interoperable Object Reference (IOR) associated with the device
- Parameters:
device (
LatestDeviceImpl) –LatestDeviceImpldevice object
- get_device_list(self: tango._tango.Util, arg0: str) list#
Get device list from name. It is possible to use a wild card (‘*’) in the name parameter (e.g. “*”, “/tango/tangotest/n*”, …)
- Return type:
list[DeviceImpl]
Added in version 7.0.0.
- get_device_list_by_class(self: tango._tango.Util, class_name: str) object#
Get the list of device references for a given TANGO class. Return the list of references for all devices served by one implementation of the TANGO device pattern implemented in the process.
Added in version 7.0.0.
- get_ds_exec_name(self: tango._tango.Util) str#
Get the device server executable name.
Added in version 3.0.4.
- get_ds_inst_name(self: tango._tango.Util) str#
Get the device server instance name.
Added in version 3.0.4.
- get_ds_name(self: tango._tango.Util) str#
Get the device server name. The device server name is the <device server executable name>/<the device server instance name>
Added in version 3.0.4.
- get_dserver_device(self: tango._tango.Util) tango._tango.DServer#
Get a reference to the dserver device attached to the device server process.
- Return type:
Added in version 7.0.0.
- get_dserver_ior(self: tango._tango.Util, device_server: tango._tango.DServer) str#
Get the CORBA Interoperable Object Reference (IOR) associated with the device server
- get_host_name(self: tango._tango.Util) str#
Get the host name where the device server process is running.
Added in version 3.0.4.
- get_pid(self: tango._tango.Util) int#
Get the device server process identifier.
- get_pid_str(self: tango._tango.Util) str#
Get the device server process identifier as a string.
Added in version 3.0.4.
- get_polling_threads_pool_size(self: tango._tango.Util) int#
Get the maximum number of threads in the polling threads pool
- get_serial_model(self: tango._tango.Util) tango._tango.SerialModel#
Get the serialization model.
- Return type:
- get_server_version(self: tango._tango.Util) str#
Get the device server version.
- get_sub_dev_diag(self: tango._tango.Util) tango._tango.SubDevDiag#
Get the internal sub device manager
Added in version 7.0.0.
- get_tango_lib_release(self: tango._tango.Util) int#
Get the TANGO library version number number coded in 3 digits (for instance 550,551,552,600,….).
- get_trace_level(self: tango._tango.Util) int#
Get the process trace level.
- get_version_str(self: tango._tango.Util) str#
Get the IDL TANGO version.
Added in version 3.0..
- static instance(*args, **kwargs)#
Overloaded function.
instance() -> tango._tango.Util
Static method that gets the singleton object reference. If the class has not been initialised with it’s init method, this method prints a message and aborts the device server process.
- Returns:
the tango
Utilobject- Return type:
- Throws:
DevFailedinstead of aborting if exit is set to False
instance(exit: bool) -> tango._tango.Util
Static method that gets the singleton object reference. If the class has not been initialised with it’s init method, this method prints a message and aborts the device server process.
- is_auto_alarm_on_change_event(self: tango._tango.Util) bool#
Returns True if alarm events are automatically pushed to subscribers when a device pushes a change event, and the attribute quality has changed to or from alarm.
Can be configured in two ways:
via the
CtrlSystemfree Tango database propertyAutoAlarmOnChangeEvent(set to true or false),by calling the
tango.Util.set_auto_alarm_on_change_event().
Added in version 10.0.0.
- is_device_restarting(self: tango._tango.Util, dev_name: str) bool#
Check if the device is actually restarted by the device server process admin device with its DevRestart command
- Parameters:
dev_name – device name
- Rtype dev_name:
Added in version 8.0.0.
- is_svr_shutting_down(self: tango._tango.Util) bool#
Check if the device server process is in its shutting down sequence
Added in version 8.0.0.
- is_svr_starting(self: tango._tango.Util) bool#
Check if the device server process is in its starting phase
Added in version 8.0.0.
- orb_run(self: tango._tango.Util) None#
Run the CORBA event loop directly (EXPERT FEATURE!)
This method runs the CORBA event loop. It may be useful if the Util.server_run method needs to be bypassed. Normally, that method runs the CORBA event loop
- reset_filedatabase(self: tango._tango.Util) None#
Reread the file database
- server_cleanup(self: tango._tango.Util) None#
Release device server resources (EXPERT FEATURE!)
This method cleans up the Tango device server and relinquishes all computer resources before the process exits. It is unnecessary to call this, unless Util.server_run has been bypassed
- server_init(self: tango._tango.Util, with_window: bool = False) None#
Initialize all the device server pattern(s) embedded in a device server process.
- server_run(self: tango._tango.Util) None#
Run the CORBA event loop. This method runs the CORBA event loop. For UNIX or Linux operating system, this method does not return. For Windows in a non-console mode, this method start a thread which enter the CORBA event loop
- server_set_event_loop(self: tango._tango.Util, event_loop: object) None#
This method registers an event loop function in a Tango server. This function will be called by the process main thread in an infinite loop The process will not use the classical ORB blocking event loop. It is the user responsibility to code this function in a way that it implements some kind of blocking in order not to load the computer CPU. The following piece of code is an example of how you can use this feature.
_LOOP_NB = 1 def looping(): global _LOOP_NB print "looping", _LOOP_NB time.sleep(0.1) _LOOP_NB += 1 return _LOOP_NB > 100 def main(): util = tango.Util(sys.argv) # ... U = tango.Util.instance() U.server_set_event_loop(looping) U.server_init() U.server_run()
Added in version 8.1.0.
- set_auto_alarm_on_change_event(self: tango._tango.Util, value: bool) None#
Toggles if alarm events are automatically pushed - see
tango.Util.is_auto_alarm_on_change_event().This method takes priority over the value of the free property in the Tango database.
- Parameters:
enabled (bool) – if True - the alarm event will be emitted with change event, if there is quality change to or from alarm
Added in version 10.0.0.
- set_interceptors(self: tango._tango.Util, interceptors: tango._tango.Interceptors) None#
- set_polling_threads_pool_size(self: tango._tango.Util, thread_nb: SupportsInt | SupportsIndex) None#
Set the polling threads pool size.
- Parameters:
thread_nb (int) – the maximun number of threads in the polling threads pool
Added in version 7.0.0.
- set_serial_model(self: tango._tango.Util, ser: tango._tango.SerialModel) None#
Set the serialization model.
- Parameters:
ser (
SerialModel) – the new serialization model. The serialization model must be one of BY_DEVICE, BY_CLASS, BY_PROCESS or NO_SYNC
- set_server_version(self: tango._tango.Util, vers: str) None#
Set the device server version.
- Parameters:
vers (
str) – the device server version
- set_trace_level(self: tango._tango.Util, level: SupportsInt | SupportsIndex) None#
Set the new process trace level.
- Parameters:
level (int) – new trace level
- static set_use_db(arg0: bool) None#
Set the database use Tango::Util::_UseDb flag. Implemented for device server started without database usage.
Use with extreme care!
- trigger_attr_polling(self: tango._tango.Util, dev: tango._tango.DeviceImpl, name: str) None#
Trigger polling for polled attribute. This method send the order to the polling thread to poll one object registered with an update period defined as “externally triggerred”
- trigger_cmd_polling(self: tango._tango.Util, dev: tango._tango.DeviceImpl, name: str) None#
Trigger polling for polled command. This method send the order to the polling thread to poll one object registered with an update period defined as “externally triggerred”
- unregister_server(self: tango._tango.Util) None#
Unregister a device server process from the TANGO database. If the database call fails, a message is displayed on the screen and the process is aborted
Added in version 7.0.0.
SubDevDiag#
- class tango.SubDevDiag#
- get_associated_device(self: tango._tango.SubDevDiag) str#
Get the device name that is associated with the current thread of the device server
- get_sub_devices(self: tango._tango.SubDevDiag) list[str]#
Read the list of sub devices for the device server The returned strings are formated as:
‘device_name sub_device_name’
or
sub_device_name
when no associated device could be identified
- get_sub_devices_from_cache(self: tango._tango.SubDevDiag) None#
Read the list of sub devices from the database cache. The cache is filled at server sart-up
- register_sub_device(self: tango._tango.SubDevDiag, dev_name: str, sub_dev_name: str) None#
Register a sub device for an associated device in the list of sub devices of the device server
- remove_sub_devices(*args, **kwargs)#
Overloaded function.
remove_sub_devices(self: tango._tango.SubDevDiag) -> None
Remove all sub devices
remove_sub_devices(self: tango._tango.SubDevDiag, dev_name: str) -> None
Remove all sub devices for a device of the server
- set_associated_device(self: tango._tango.SubDevDiag, dev_name: str) None#
Set the device name that should be associated to a thread in the device server
- store_sub_devices(self: tango._tango.SubDevDiag) None#
Store the list of sub devices for the devices of the server. The sub device names are stored as a string array under the device property “sub_devices”. Sub device names without an associated device, will be stored under the name of the administration device.
Database access will only happen when the list of sub devices was modified and when the list is different from the list read into the db_cache during the server startup
ClientAddr#
- class tango.ClientAddr#
- get_client_hostname(self: tango._tango.ClientAddr) str#
Returns client host name, extracted from client ip.
- Returns:
client host name
- Return type:
- Throws:
ValueError