Xeryon Python Library
Controlling our stages in Python is very easy thanks to our Python library. This library handles all of the communication between the computer and the controller. It also provides simple functions to control different stages. The library is compact and easy to use. Let’s have a look.
The first step is to initialise the system and import the library:
>> from Xeryon import *
>> controller = Xeryon("COM11", 115200) # Setup serial communication (COM-port, baudrate)
>> axisX = controller.addAxis(Stage.XLS_312) # Add all axis and specify the correct stage.
It’s very easy to use multiple stages, just select the correct stage resolution.
The second step is to start the system. This command initiates the communication between the computer and the controller and configures the correct settings.
The last step of the setup is finding the index for each axis which is an obligatory step. Finding the index makes sure that the encoder knows at which position it is located.
Do you have multiple axes? It is easy to send commands to all the axis in the system by looping through them:
>> for axis in controller.getAllAxis():
Now the setup is done and the system can be used.
It is really easy to control the system. If you want to move an axis to a specific position (= the desired position DPOS) just type the following and the stage will start moving:
But what does “position 10” mean? All the positions and speeds in this library are expressed in the “current selected units”. By default, these units are in mm. So setDPOS(10) moves the stage to position “10 mm from the index point”.
Changing the units is very easy, just type:
>> axisX.setUnits( Units.mu )
This changes the units to micrometers. Notice that the units are specific for each axis.
By running the following command, the stage will position itself to -5 micrometer.
The controller sends feedback back to the computer. It can, for example, send the encoder position “EPOS”. The library reads incoming data and converts it into the current units. This all happens in the background. To read the data, just type:
The library also provides the function: step( value ). The name explains itself, it steps a certain amount of units. This function also just works wth the current units, so in this case it will be micrometers. By running the code below, the stage will first do a step of 5 mu and followed by a step of -10 mu.
Controlling the speed is very easy:
This command will set the speed for this stage to 10 mu/s. Notice that the given value is always expressed in the current units.If you want to change the current units to mm and set the speed of the stage to 10 mm/s, use the following command:
Scanning is continuously moving with a fixed speed. Scanning can be done continuously, until there is a stop command:
>> axisX.startScan(-1) # The argument takes a negative or positive value, to control the direction.
>> time.sleep(1) # Sleep 1 second.
>> axisX.stopScan() # Stop scanning.
But it is also possible to scan for a certain amount of seconds:
>> axisX.startScan(1, 2) # Scan for 2 seconds.
The controller gives a lot of feedback. All this data is processed in the background, and always accessible. For example, the controller always sends a status (“STAT”) back. The definition of these status bits are explained in the datasheet.
All the status bits are simple Boolean functions in our library:
The biggest advantage of using our Python library is the ease with which you can capture and process data. Just use the function
The function stopLogging() returns all the collected data.
To close the program, run the controller.stop() command. This will reset the stage to its home position and shut down the communication.
The code below is an example usage of these functions. It starts by defining the correct units and resetting the stage to its home position. Then it increases the speed to 120 mm/s and starts logging the data. The stage will then make a very small movement of 0.01 mm and stops collecting the data. Finally the stage will go back to home with its initial speed.
>> logs = axisX.endLogging()
The variable ‘logs’ contains all the collected data. A simple way to represent that data is by using the library ‘matplotlib’ and making a graph of the data. Notice that the data given back is always in encoder positions. Don’t worry, just use the following function to convert encoder units into mm:
>> axis.convertEncoderUnitsToUnits( value, Units.mm)
The reverse function also exists.
>> from matplotlib import pyplot as plt
>> unit_converted_epos =  >> for index in range(0, len(logs["EPOS"])):
The result is a simple graph of the encoder position throughout the movement of 0.01 mm with a speed of 120 mm/s.
An overview of the most used functions:
- Start the communication, read the settings file and send the settings to the controller.
- Move all the stages to their home position and close the communication.
- Move all the stages to their home position and resend the settings.
- Return al list containing all the axis objects.
- Find the index of the stage..
- setDPOS( value )
- Set the desired position to a specific value.
- Return the current DPOS in the current units.
- Return the current EPOS in the current units.
- Specify the units this stage now works in.
- Return the units the axis is currently working in.
- step( value )
- Step a certain amount of units.
- Start logging (capturing) data.
- End logging (capturing) data and return the captured data.
- setSetting(tag, value)
- Set a specific setting. Tag’s and values can be found in the controller datasheet.
- startScan( direction )
- Move continuously with a constant speed in a specified direction (-1 or 1)
- startScan( dir. , time )
- Move a specific amount of seconds with a constant speed in a specified direction (-1 or 1).
- Stop scanning.
- setSpeed( value )
- Set speed in current units.
Prefer to work in Matlab? No problem!
Our python library also works within Matlab so everything explained above is exactly the same in Matlab. We include an example program in Matlab, so you can start experimenting right away.