Xeryon C++ Library

Controlling our stages in C++ is very easy thanks to our C++ library. This library handles all of the communication between the computer and the controller. It also provides simple functions to control our different stages. The library is compact and easy to use. Let’s have a look.

In this guide we will explain the basic functions of the library. All the code used in this guide is available with the library and can be downloaded here: https://xeryon.com/downloads/

Download C++ files

Using the library


An example usage can be found in main.cpp.

Xeryon * controller = new Xeryon("COM3", 115200);

The first line as can be seen above initializes a controller object where you can specify the baudrate and com-port for the communication with the controller.

Axis * axisX = controller->addAxis('X', &XLS_312);

The second line adds an axis to the system. This line adds the X-axis, which in this case has an XLS-312 stage connected to it. This axis can be referred to by calling the object axisX.
It’s very easy to use multiple stages, just select the correct stage resolution and axis letter.
All available stages are listed up in the file Stage.cpp.

System Startup

Now the initialization of the system is done and we can move on to starting up the communication.
This can be done with only one line:


Find index

One last thing to do before the stages can be used is to find the index for each axis. Finding the index makes sure that the encoder knows at which position it is located.


Finding the index has to be executed for every stage that is connected.
Now the setup is done and the system can be used.

Basic Control

Controlling the stages is very easy. If you want to move an axis to a specific position (= the desired position called DPOS) just type the following and the stage will start moving:


The stage will now move to +5 mm. You can easily change to different units:


The controller sends feedback back to the computer.
It can, for example, send the encoder position “EPOS”.
To read the data, just type:

printf("EPOS: %lf\n", (double)axisX->getEPOS());
printf("DPOS: %lf\n", (double)axisX->getDPOS());

The library also provides the function: step( value ). The name explains itself, it steps a certain amount of units.
By running the code below, the stage will first do a step of 5 mu and followed by a step of -10 mu.


Speed control

Controlling the speed of the stage is also very easy with our library.
The command below will set the speed for this stage to 10 mu/s.



Scanning is continuously moving with a fixed speed.
Scanning can be done continuously, until there is a stop command:

axisX->startScan(-1); // Scan in the negative direction
std::this_thread::sleep_for(std::chrono::milliseconds(1000)); // Wait 1 second
axisX->stopScan(); // Stop the scan

It is also possible to scan for a certain amount of seconds:

axisX->startScan(1, 2);

That command searches in the positive direction for two seconds.


Check if the correct COM port is selected in main.cpp.

Linux / MacOS

To compile the program in a Linux/MacOS environment execute the following commands:

mkdir build
cd build
cmake ..


If you want to use the command-line approach, you have to open up a “Developer Command Prompt” and enter the following commands:

mkdir build
cd build
cmake .. -G"NMake Makefile"

If you want to use the Visual Studio solution, you have to open up a “Developer Command Prompt”
and enter the following commands:

mkdir build
cd build
cmake .. -G"Visual Studio 16 2019" -AWin64
-- or --
cmake .. -G"Visual Studio 15 2017 Win64"

This will generate a Xeryon.sln file in the build directory which can be opened by Visual Studio.
To be able to run the example, right-click on “ALL-BUILD” in the Solution Explorer, click “Properties”, select “Debugging” and change “Command” to the Xeryon_bin.exe file.


To close the program, run the controller.stop() command. This will reset the stage to it’s home position and shut down the communication.

An overview of the most used functions:

Class Xeryon:

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.

Class Axis:

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.