/*
 * Move and wait script
 *
 * Description of the script:
 *  The script reads the next coordinate and the delay time from the csv file,
 *  after which it moves to the specified coordinate with a subsequent delay,
 *  and so on until the end of reading the entire file.
 * 	The script can be useful if you are using the system to scan an area and/or capture frames
 *
 * Important:
 *  To run the script, upload it to the mDrive Direct Control software
 */

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("./scripts/simple_scripts/move_and_wait.csv"); // Choose a file name and path; this script uses a file from examples 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