Set up a simulated beamline
In this lesson you will start your own Sardana server, populate it with a set of simulated motors and counters (the sar_demo environment), and connect to it with Spock. At the end you will have a complete, hardware-free “beamline” that the rest of the tutorials build upon.
Prerequisites
Sardana installed with the Spock dependencies (see First steps with Sardana).
A running Tango database, with
TANGO_HOSTpointing at it.
Start the Sardana server
The Sardana server executable is called, unsurprisingly, Sardana. It
takes one argument: the instance name of your system. We will use demo1
throughout the tutorials (if you pick another name, adapt the element and
door names accordingly).
Type in a terminal:
Sardana demo1
The first time you run it, the server is not yet registered in the Tango
database, so it offers to register itself. Just answer y:
$ Sardana demo1
demo1 does not exist. Do you wish to create a new one (Y/n) ? y
That’s it – you now have a running Sardana server containing an empty Pool
and a MacroServer with one door, named Door_demo1_1. Leave it running in
this terminal.
Note
Sardana also provides a modern sardanactl command which groups
several utilities as subcommands (sardanactl spock,
sardanactl macroexecutor, …). Run sardanactl --help to see what
is available in your installation. With the separately distributed
sardana-config package it also offers sardanactl config for
managing the whole system configuration from a YAML file.
Connect with Spock
Open a second terminal and start the client:
spock
(sardanactl spock is equivalent.) Spock organizes its settings in
IPython profiles. On the first run it offers to create the default
spockdoor profile and asks which door to connect to. Answer y and
select your door:
$ spock
Profile 'spockdoor' does not exist. Do you want to create one now ([y]/n)? y
Available Door devices from localhost:10000 :
Door_demo1_1 (a.k.a. Door/demo1/1) (running)
Door name from the list? Door_demo1_1
Storing ipython_config.py in /home/homer/.ipython/profile_spockdoor... [DONE]
Spock 3.7.1-alpha -- An interactive laboratory application.
help -> Spock's help system.
object? -> Details about 'object'. ?object also works, ?? prints more.
IPython profile: spockdoor
Connected to Door_demo1_1
Door_demo1_1 [1]:
You are now sitting at a Sardana command line. Anything you type is either a macro (executed in the server) or plain Python (executed locally by IPython).
Populate the demo environment
A freshly created Sardana system is empty – it has no motors or counters
yet. Sardana ships a macro called sar_demo that creates a set of
simulated (dummy) elements so you can play without any hardware. Run it from
Spock:
Door_demo1_1 [1]: sar_demo
Creating motor controller motctrl01 ...
Creating motor mot01 ...
Creating motor mot02 ...
Creating motor mot03 ...
Creating motor mot04 ...
Creating counter controller ctctrl01 ...
Creating counter channel ct01 ...
Creating counter channel ct02 ...
Creating counter channel ct03 ...
Creating counter channel ct04 ...
...
Creating measurement group mntgrp01 ...
Setting mntgrp01 as ActiveMntGrp
Creating instruments: /slit, /mirror and /monitor ...
Assigning elements to instruments...
DONE!
(The output above is abridged – the macro also creates simulated 0D/1D/2D channels, pseudo motors for a slit, trigger elements and I/O registers.)
Look around
Sardana provides a family of ls* macros to inspect the system. Most of
them accept an optional regular expression filter. List the motors (without
the filter, lsm also lists the pseudo motors created by the demo):
Door_demo1_1 [1]: lsm mot.*
Name State Type Controller Axis
------ ------ ------ ----------- -----
mot01 ON Motor motctrl01 1
mot02 ON Motor motctrl01 2
mot03 ON Motor motctrl01 3
mot04 ON Motor motctrl01 4
Other useful list macros: lsa lists all elements, lsctrl the
controllers, lsmeas the measurement groups and lsdef the available
macros.
To see where the motors currently are, use wa (where all, filtered
here the same way):
Door_demo1_1 [1]: wa mot.*
Current positions (user, dial) on 2026-06-10 17:32:01.552777
mot01 mot02 mot03 mot04
0.0000 0.0000 0.0000 0.0000
0.0000 0.0000 0.0000 0.0000
And move a (simulated) motor with umv (update move, which shows the
position while moving):
Door_demo1_1 [1]: umv mot01 5
mot01
5.0000
Hint
If you ever want to remove everything created by the demo, execute the
clear_sar_demo macro.
Next steps
Your simulated beamline is up and running. Continue with Write your first macro to extend it with your own procedure. For a complete tour of the Spock interface (stopping macros, magic commands, editing macros, …), see the Spock documentation.