A script which scans and writes data to the file
var start = 0; // Starting coordinate in steps
var step = 10; // Shift amount in steps
var end = 100; // Ending coordinate in steps
var speed = 300; // maximum movement speed in steps / second
var accel = 100; // acceleration value in steps / second^2
var decel = 100; // deceleration value in steps / second^2
var delay = 100;
var m = get_move_settings(); // read movement settings from the controller
m.Speed = speed; // set movement speed
m.Accel = accel; // set acceleration
m.Decel = decel; // set deceleration
set_move_settings(m); // write movement settings into the controller
var f = new_file("C:/a.csv"); // Choose a file name and path
f.open(); // Open a file
f.seek( 0 ); // Seek to the beginning of the file
command_move(start); // Move to the starting position
command_wait_for_stop(delay); // Wait until controller stops moving
while (get_status().CurPosition < end) {
f.write( get_status().CurPosition + "," + get_chart_data().Pot + "," + Date.now() + "\n" ); // Get curren
t position, potentiometer value and date and write them to file
command_movr(step); // Move to the next position
command_wait_for_stop(delay); // Wait until controller stops moving
}
f.close(); // Close the file
A script which moves the controller through the list of positions with pauses
var axis = new_axis(get_next_serial(0)); // Use first available controller
var x; // A helper variable, represents coordinate
var ms; // A helper variable, represents wait time in milliseconds
var f = new_file("./move_and_sleep.csv"); // Choose a file name and path; this script uses a file from exam
ples in the installation directory
f.open(); // Open a file
while ( str = f.read(4096) ) { // Read file contents string by string, assuming each string is less than 4
KiB long
var ar = str.split(","); // Split the string into substrings with comma as a separator; the result is an
array of strings
x = ar[0]; // Variable assignment
ms = ar[1]; // Variable assignment
log( "Moving to coordinate " + x ); // Log the event
axis.command_move(x); // Move to the position
axis.command_wait_for_stop(100); // Wait until the movement is complete
log( "Waiting for " + ms + " ms" ); // Log the event
msleep(ms); // Wait for the specified amount of time
}
log ( "The end." );
f.close(); // Close the file
move_and_sleep.csv - a sample file for use with the above example
A script which enumerates all available axes and gets their coordinates
var i = 0; // Declare loop iteration variable
var serial = 0; // Declare serial number variable
var axes = Array(); // Declare axes array
while (true) { // The loop
serial = get_next_serial(serial); // Get next serial
if (serial == 0) // If there are no more controllers then...
break; // ...break out of the loop
var a = new Object(); // Create an object
a.serial = serial; // Assign serial number to its "serial" property
a.handle = new_axis(serial); // Assign new axis object to its "handle" property
axes[i] = a; // Add it to the array
i++; // Increment counter
}
for (var k=0; k < axes.length; k++) { // Iterate through array elements
log ( "Axis with S/N " + axes[k].serial + " is in position " + axes[k].handle.get_status().CurPosition );
// For each element print saved axis serial and call a get_status() function
}