Sardana migration guide¶
This chapter describes how to migrate different sardana components between the different API versions.
How to migrate your macro code¶
API v0 -> v1¶
This chapter describes the necessary steps to fully migrate your macros from API v0 ( sardana 0.x ) to API v1 ( sardana 1.x )
Mandatory changes¶
The following are the 2 necessary changes to make your macros work in sardana API v1:
from:
from macro import Macro, Type, Table, List
to:
from sardana.macroserver.macro import Macro, Type, Table, List
Parameter type
Type.Motor
should be changedType.Moveable
. In v0 the Motor meant any motor (including physical motor, pseudo motor). In v1, for consistency, Motor means only physical motor and Moveable means all moveable elements (including physical motor, pseudo motor).
New features in API v1¶
This chapter is a summary of all new features in API v1.
- Macros can now be functions(see Writing macros).
How to migrate your controller code¶
API v0 -> v1¶
This chapter describes the necessary steps to fully migrate your controller from API v0 ( sardana 0.x ) to API v1 ( sardana 1.x )
Mandatory changes¶
The following are the 2 necessary changes to make your controller work in sardana API v1:
from:
import pool from pool import <ControllerClass>/PoolUtil
to:
from sardana import pool from sardana.pool import PoolUtil from sardana.pool.controller import <ControllerClass>
change contructor from:
def __init__(self, inst, props): code
to:
def __init__(self, inst, props, *args, **kwargs): MotorController.__init__(self, inst, props, *args, **kwargs) code
(and don’t forget to call the super class constructor also with args and kwargs).
The following change is not mandatory but is necessary in order for your controller to be recognized by the pool to be a API v1 controller:
_log member changed from
logging.Logger
totaurus.core.util.Logger
. This means that you need to change code from:self._log.setLevel(logging.INFO)
to:
self._log.setLogLevel(logging.INFO)
or:
self._log.setLogLevel(taurus.Info)
since taurus.Info == logging.INFO.
Optional changes¶
The following changes are not necessary to make your controller work. The API v1 supports the API v0 on these matters.
- class members:
- from:
class_prop
to:ctrl_properties
- from:
ctrl_extra_attributes
to:axis_attributes
- new feature in API v1:
ctrl_attributes
data types:
StateOne()
return type: PreviouslyStateOne()
had to return a member ofPyTango.DevState
. Now it can instead return a member ofState
. This eliminates the need to importPyTango
.- In API v0 class member (like
ctrl_extra_attributes
) value for key type had to be a string (like ‘PyTango.DevString’ or ‘PyTango.DevDouble’). Now they can be a python type (like str or float). Please check Data Type definition for more information.
generic controller method names:
- from:
GetPar()
to:GetAxisPar()
- from:
SetPar()
to:SetAxisPar()
- from:
GetExtraAttributePar()
to:GetAxisExtraPar()
- from:
SetExtraAttributePar()
to:SetAxisExtraPar()
- new feature in API v1:
GetCtrlPar()
,SetCtrlPar()
- new feature in API v1:
AbortAll()
(has default implementation which callsAbortOne()
for each axis)
- from:
pseudo motor controller method names:
- from:
calc_pseudo()
to:CalcPseudo()
- from:
calc_physical()
to:CalcPhysical()
- from:
calc_all_pseudo()
to:CalcAllPseudo()
- from:
calc_all_physical()
to:CalcAllPhysical()
- new feature in API v1:
GetMotor()
- new feature in API v1:
GetPseudoMotor()
- from:
New features in API v1¶
This chapter is a summary of all new features in API v1.
New controller features:
All Controllers now have a
ctrl_attributes
class member to define extra controller attributes (and new methods:GetCtrlPar()
,SetCtrlPar()
)For
ctrl_properties
,axis_attributes
andctrl_extra_attributes
:- new (more pythonic) syntax. Old syntax is still supported:
- can replace data type strings for python type (‘PyTango.DevDouble’ -> float)
- Default behavior. Example: before data access needed to be described explicitly. Now it is read-write by default.
- support for 2D
- new keys ‘fget’ and ‘fset’ override default method calls
no need to import
PyTango
(StateOne()
can return sardana.State.On instead of PyTango.DevState.ON)PseudoMotorController has new
GetMotor()
andGetPseudoMotor()
new
AbortAll()
(with default implementation which callsAbortOne()
for each axis)new
StopOne()
(with default implementation which callsAbortOne()
)new
StopAll()
(with default implementation which callsStoptOne()
for each axis)- new
GetAxisAttributes()
allows features like: - per axis customized dynamic attributes
- Basic interface (example: motor without velocity or acceleration)
- Discrete motor (declare position has an integer instead of a float). No need for IORegisters anymore
- new
- New
MotorController
constants:
- New
New acquisition features:
- Measurement group has a new Configuration attribute which contains the full description of the experiment in JSON format
New Tango API features:
- Controllers are now Tango devices
- Pool has a default PoolPath (points to <pool install dir>/poolcontrollers)
- Create* commands can receive JSON object or an old style list of parameters
- new CreateElement command (can replace CreateMotor, CreateExpChannel, etc)
- Pool Abort command: aborts all elements (non pseudo elements)
- Pool Stop command: stops all elements (non pseudo elements)
- Controller Abort command: aborts all controller elements
- Controller Stop command: stops all controller elements
- Controllers have a LogLevel attribute which allows remote python logging management
Others:
- Pool device is a python device :-)
- many command line parameters help logging, debugging