Macro Server overview

The Macro Server object is the sardana server object which manages all high level sardana objects related to macro execution, namely doors, macro libraries and macros themselves.

The main purpose of the Macro Server is to run macros. Macros are just pieces of Python code (functions or classes) which reside in a macro library (Python file). Macros can be written by anyone with knowledge of Python.

The Macro Server is exposed on the sardana server as a Tango device. Through configuration, the Macro Server can be told to connect to a Pool device. This is the most common configuration. You can, however, tell the Macro Server to connect to more than one Pool device or to no Pool devices at all.

When connected to a Pool device(s), the Macro Server uses the Pool device introspection API to discover which elements are available. The existing macros will be able to access these elements (through parameters passed to the macro or using the macro API) and act on them.

In order to be able to run macros, you must first connect to the Macro Server entry point object called Door. A single Macro Server can have many active Doors at the same time but a Door can only run one macro at a time. Each Door is exposed on the sardana server as a Tango device.

You are not in any way restricted to the standard macros provided by the sardana system. You can write as many macros as you need. Writing your own macros is easy. The macro equivalent of Python's Hello, World! example:

from sardana.macroserver.macro import macro

def hello_world(self):
    self.output("Hello, World!")

Here is a simple example of a macro to move any moveable element to a certain value:

from sardana.macroserver.macro import macro, Type

@macro([ ["moveable", Type.Moveable, None, "moveable to move"],
         ["position", Type.Float, None, "absolute position"] ])
def my_move(self, moveable, position):
    """This macro moves a moveable to the specified position"""

    self.output("%s is now at %s", moveable, moveable.getPosition())

Information on how to write your own sardana macros can be found here.

The complete macro API can be found here.