Previous topic

The Tango Encoded Python API

Next topic

Exception Handling

This Page

The Utilities API

PyTango.server_run(classes, args=None, msg_stream=<open file '<stderr>', mode 'w' at 0x4025f0d0>, verbose=False, util=None)

Provides a simple way to run a tango server. It handles exceptions by writting a message to the msg_stream.

The classes parameter can be either a sequence of Device classes or a dictionary where:

  • key is the tango class name

  • value is either:
    1. a Device class or
    2. a a sequence of two elements DeviceClass, DeviceImpl

Example 1: registering and running a PowerSupply inheriting from Device:

from PyTango import server_run
from PyTango.api2 import Device, DeviceMeta

class PowerSupply(Device):
    __metaclass__ = DeviceMeta
    
server_run((PowerSupply,))

Example 2: registering and running a MyServer defined by tango classes MyServerClass and MyServer:

import PyTango

class MyServer(PyTango.Device_4Impl):
    pass
    
class MyServerClass(PyTango.DeviceClass):
    pass

PyTango.server_run({"MyServer": (MyServerClass, MyServer)})
Parameters:
  • classes (sequence or dict) – a sequence of Device classes or a dictionary where keyword is the tango class name and value is a sequence of Tango Device Class python class, and Tango Device python class
  • args (list) – list of command line arguments [default: None, meaning use sys.argv]
  • msg_stream – stream where to put messages [default: sys.stderr]
  • util (Util) – PyTango Util object [default: None meaning create a Util instance]
Returns:

The Util singleton object

Return type:

Util

New in version 8.0.0.

Changed in version 8.0.3: Added util keyword parameter. Returns util object

class PyTango.utils.EventCallBack(format='{date} {dev_name} {name} {type} {value}', fd=<open file '<stdout>', mode 'w' at 0x4025f078>, max_buf=100)

Useful event callback for test purposes

Usage:

>>> dev = PyTango.DeviceProxy(dev_name)
>>> cb = PyTango.utils.EventCallBack()
>>> id = dev.subscribe_event("state", PyTango.EventType.CHANGE_EVENT, cb, [])
2011-04-06 15:33:18.910474 sys/tg_test/1 STATE CHANGE [ATTR_VALID] ON

Allowed format keys are:

  • date (event timestamp)
  • reception_date (event reception timestamp)
  • type (event type)
  • dev_name (device name)
  • name (attribute name)
  • value (event value)

New in PyTango 7.1.4

get_events()

Returns the list of events received by this callback

Returns:the list of events received by this callback
Return type:sequence<obj>
push_event(evt)

Internal usage only

PyTango.utils.is_scalar_type(tg_type)

Tells if the given tango type is a scalar

Parameters:tg_type (PyTango.CmdArgType) – tango type
Returns:True if the given tango type is a scalar or False otherwise
Return type:bool
PyTango.utils.is_array_type(tg_type)

Tells if the given tango type is an array type

Parameters:tg_type (PyTango.CmdArgType) – tango type
Returns:True if the given tango type is an array type or False otherwise
Return type:bool
PyTango.utils.is_numerical_type(tg_type, inc_array=False)

Tells if the given tango type is numerical

Parameters:
  • tg_type (PyTango.CmdArgType) – tango type
  • inc_array (bool) – (optional, default is False) determines if include array in the list of checked types
Returns:

True if the given tango type is a numerical or False otherwise

Return type:

bool

PyTango.utils.is_int_type(tg_type, inc_array=False)

Tells if the given tango type is integer

Parameters:
  • tg_type (PyTango.CmdArgType) – tango type
  • inc_array (bool) – (optional, default is False) determines if include array in the list of checked types
Returns:

True if the given tango type is integer or False otherwise

Return type:

bool

PyTango.utils.is_float_type(tg_type, inc_array=False)

Tells if the given tango type is float

Parameters:
  • tg_type (PyTango.CmdArgType) – tango type
  • inc_array (bool) – (optional, default is False) determines if include array in the list of checked types
Returns:

True if the given tango type is float or False otherwise

Return type:

bool

PyTango.utils.obj_2_str(obj, tg_type)

Converts a python object into a string according to the given tango type

Parameters:
Returns:

a string representation of the given object

Return type:

str

PyTango.utils.seqStr_2_obj(seq, tg_type, tg_format=None)

Translates a sequence<str> to a sequence of objects of give type and format

Parameters:
Returns:

a new sequence

PyTango.utils.get_home()

Find user’s home directory if possible. Otherwise raise error.

Returns:user’s home directory
Return type:str

New in PyTango 7.1.4