get_next_serial(int serial) function takes as a parameter an integer number and returns the smallest serial from a sorted list of opened
controller serials which is strictly greater than the parameter. If there are no such serials a zero is returned.
This function is a convenient shortcut for automatic creation of "axis" type objects without hardcoded serial numbers.
Example:
var first_serial = get_next_serial(0);
var x = new_axis(first_serial);
var y = new_axis(get_next_serial(first_serial));
In this example in the first line we obtain a serial, in the second line an axis-type object is created, in the third line we get the next
serial and create an axis for it.
Function usage example.
Wait for stop
The command_wait_for_stop(int refresh period) script function waits until the controller stops movement, that is, until the
MVCMD_RUNNING bit in the MvCmdSts member of the structure returned by the get_status() function becomes unset.
command_wait_for_stop script function uses command_wait_for_stop libximc function and takes as a paramater an integer denoting
time delay in milliseconds between successive queries of controller state.
This function is also present as a method of an "axis"-type object.
Function usage example.
libximc library functions
Libximc library functions with "get_" prefix read settings from the controller and return the corresponding settings structure. Libximc
library functions with "set_" prefix take as a parameter a settings data structure and write these settings to the controller. There are
two ways to set data structure contents:
1. call the corresponding get-function and modify required fields
// set settings: type 1
var m = get_move_settings();
m.Speed = 100;
set_move_settings(m);
2. create an Object and set all of its properties that are present as members of the data structure (case-sensitive).
// set settings: type 2
var m = new Object;
m.Speed = 100;
m.uSpeed = 0;
m.Accel = 300;
m.Decel = 500;
m.AntiplaySpeed = 10;
m.uAntiplaySpeed = 0;
set_move_settings(m);
Please note, that in the first case controller receives an additional command (sent by the get-function before the set-). In the second
case one should initialize all object properties corresponding to structure members. Any missing property will be initialized with zero.
Any property that does not match a structure member name will be ignored. Any property with non-matching type will be typecast
according to EcmaScript rules. All data structures are described in Communication protocol specification chapter of the manual.
Function usage example.
Examples
This section contains examples of typical tasks which can be easily automated by XILab scripts.
Cyclic movement script
var first_border = -10; // first border coordinate in mm
var second_border = 10; // second border coordinate in mm
var mm_per_step = 0.005; // steps to distance translation coefficient
var delay = 100; // delay in milliseconds
var calb = new_calibration(mm_per_step, get_engine_settings().MicrostepMode); // create calibration structu
re
command_stop(); // send STOP command (does immediate stop)
command_zero(); // send ZERO command (sets current position and encoder value to zero)
while (1) { // infinite loop
command_move_calb(first_border, calb); // move towards one border
command_wait_for_stop(delay); // wait until controller stops moving
command_move_calb(second_border, calb); // move towards another border
command_wait_for_stop(delay); // wait until controller stops moving
}