In this example first line of the script creates an axis-type object with the variable name "x", which tries to use controller with the
serial number "123". If this controller is not connected, then the script will return an error and terminate. The second line of the script
sends a "move to position 50" command to this controller.
New file object creation
XILab scripts can read from and write to files. To do this you need to create a "file" object, passing desired filename in its constructor.
File object has the following functions:
return_type
Function_name
Description
bool open()
Opens the file. File is opened in read-write mode if possible, in read-only mode otherwise.
void close()
Closes the file.
Number size()
Returns file size in bytes.
bool
seek(Number
pos)
Sets current position in file to pos bytes
.
bool
resize(Number
size)
Resizes the file to size bytes. If size is less than current file size, then the file is truncated, if it is greater than
current file size, then the file is padded with zero bytes.
bool remove()
Removes the file.
String read(Number
maxsize)
Reads up to maxsize bytes from the file and returns result as a string. Data is read in utf-8 Unicode encoding.
Number write(String
s, Number maxsize)
Writes up to maxsize btyes to the file from the string. Data is written in utf-8 unicode encoding, end-of-line
character should be set by user. Returns amount of written bytes or -1 if an error occurred.
All file functions which return bool type, return "true" on success and "false" on failure.
Use "/" symbol as path separator, this works on all systems (Windows/Linux/Mac).
1
Seeking beyond the end of a file: If the position is beyond the end of a file, then seek() shall not immediately extend the file. If a
write is performed at this position, then the file shall be extended. The content of the file between the previous end of file and the
newly written data is UNDEFINED and varies between platforms and file systems.
Example:
var
winf = new_file(
"
C:/file.txt
"
);
// An example of file name and path on Windows
var
linf = new_file(
"
/home/user/Desktop/file.txt
"
);
// An example of file name and path on Linux
var
macf = new_file(
"
/Users/macuser/file.txt
"
);
// An example of file name and path on Mac
var
f = winf;
// Pick a file name
if
(f.open()) {
// Try to open the file
f.write(
"
some text
"
);
// If successful, then write desired data to the file
f.close();
// Close the file
}
else
{
// If file open failed for some reason
log(
"
Failed opening file
"
);
// Log an error
}
Creation of calibration structure
new_calibration(double A, int Microstep) function takes as a parameter a floating point number A, which sets the ratio of user units to
motor steps, and microstep division mode, which was either read earlier from MicrostepMode field of get_engine_settings() return
type, or set by a
constant. This function returns calibration_t structure, which should be passed to calibrated
get_/set_ functions to get or set values in user units. The following two forms are functionally equivalent:
// create calibration: type 1
var
calb = new_calibration(c1, c2);
// create calibration: type 2
var
calb =
new
Object();
calb.A = c1;
calb.MicrostepMode = c2;
Get next serial
Page 270 / 345
Page 270 / 345
Summary of Contents for 8SMC5-USB
Page 30: ...Linux Page 30 345 Page 30 345 ...
Page 83: ...Connection of magnetic brake to one axis or two axis systems Page 83 345 Page 83 345 ...
Page 87: ...Scheme of buttons connection to the HDB 26 connector Page 87 345 Page 87 345 ...
Page 99: ...Page 99 345 Page 99 345 ...
Page 167: ...Vertical load capacity the maximum vertical load on the stage Page 167 345 Page 167 345 ...
Page 186: ...Click Next Click Continue anyway Page 186 345 Page 186 345 ...
Page 188: ...Page 188 345 Page 188 345 ...
Page 190: ...Page 190 345 Page 190 345 ...
Page 193: ...Page 193 345 Page 193 345 ...
Page 201: ...Select the XILab application in the Programs block Start it Page 201 345 Page 201 345 ...
Page 274: ...7 Files 1 Configuration files 2 Software Page 274 345 Page 274 345 ...
Page 331: ...Motorized Iris Diaphragms 8MID98 Motorized Iris Diaphragm Page 331 345 Page 331 345 ...
Page 338: ...8 Related products 1 Ethernet adapter Page 338 345 Page 338 345 ...
Page 339: ...8 1 Control via Ethernet 1 Overview 2 Administration Page 339 345 Page 339 345 ...