VWorks Software User Guide : Setting up and using the Watcher tool : Creating the script that Watcher will run
Creating the script that Watcher will run
About this topic
This topic assumes that you know how to write programs in JavaScript or have basic programming knowledge.
For a full description of the JavaScript language, see the Mozilla Developer Center at http://www.mozilla.org/js/.
Guidelines for creating your script
In addition to using good script-writing practices, follow these guidelines when creating a script for Watcher to run:
Define the JavaScript function correctly. The function that Watcher will run, for example WatcherMain, must take one parameter:
 
Parameter
Type
Description
input_file
string
The file path to the input file.
The name of the function in the script must match the function name in the Watcher configuration file (.ini).
Identify or create any other scripts that your script will call. Agilent has JavaScript files with predefined objects and functions that you may use, including:
 
Script file name
Description
DeviceArbitration.js
Enables device pooling in JavaScript.
FileUtilities.js
Provides the following functions:
isFileExist(filename)
DeleteFile(filename)
StripPath(full_path) //for example, changes "c:/mydir/mysubdir/myfile.ext” to “myfile.ext”
ForwardToBackSlashes(full_path)
//for example, changes "c:/mydir/mysubdir/myfile.ext" to "c:\mydir\mysubdir\myfile.ext"
ProtocolEditor.js
Provides various functions for editing a protocol.
StopGo.js
Provides a way to create stop and go tasks using JavaScript, which is useful when stop and go should be scripted based on instance number.
VIN_handling.js
Provides a way to assign virtual instance numbers (VIN) to plates. This is useful if instance numbers:
Must be passed from process to spawned process.
Require an out-of-order assignment, for example, if rejecting some plates, sequential [virtual] instance numbers can be assigned to the plates that remain.
XMLKeyValueLookup.js
XMLKeyValueLookup
SampleData.xml
Script and sample data for mapping one string to another string, where the definition is in XML format. For example, you might use this script to translate an alias into a final file name.
XML_files.js and
Formatter.xml
Provides script for opening XML files, validation against schemas, and saving. Uses MSXMLDOM ActiveX, which requires Msxml2.DOMDocument.6.0 and Msxml2.XMLSchemaCache.6.0.
File_operations.js
Provides functions for various file operations, such as creating, reading, writing to, and debugging files.
plateDB_HowTOUse.js
Provides examples on how to use the VWorks plateDB object, which can be accessed by a script. For a description of the plateDB object, see plateDB object.
Define any required global variables, such as folder paths. You should define the folder paths where processed files will be stored, such as the VWorks folder, the working folder, and an output folder, if applicable. For example, you might define the following:
var VWorksFolder    = “C:/VWorks Workspace/”
var WorkingFolder   = VWorksFolder + “WorkingFolder/”
var OutputFolder    = VWorksFolder + “Output/”
Include code at the end of the script to delete the input file from the monitored folder, if applicable. To prevent repeated processing of files upon restarting Watcher, the script should delete the input file or move it into a processed folder or output folder after processing the file.
Example script:
print("deleting input file: [" + input_file_name + "]")
DeleteFile(input_file_name);
Script example—Creating data-driven working protocols from a template protocol
This section provides example script for scenario 2 in Description. In this scenario, Watcher monitors a folder for new input files, each of which specifies the attributes of a single protocol run. When a new input file appears in the folder, Watcher runs a script to create a working protocol based on a template protocol and an input file, and then schedules the protocol.
The following script example shows a hypothetical WatcherMain function, which does following:
1 Verifies that the input file exists.
2 Reads the input file.
3 Opens the template protocol.
4 Modifies the template protocol to create a working protocol.
5 Saves the input file and the modified protocol (working protocol) to the working folder.
6 Schedules the working protocol as part of a runset.
7 Deletes the input file from the monitored folder.
To accomplish some of these tasks, the WatcherMain function includes calls to other predefined JavaScript functions, such as inputParser and protocolEditor.
 
WatcherMain function example
function WatcherMain(input_file_name){
print("Starting WatcherMain...with input file: [" + input_file_name + "]")
print("OutputFolder : [" +OutputFolder+"]")
 
if(!isFileExist(input_file_name))
 Print("input file does not exist");
 
var inputParser = new InputParser();
inputParser.Open(input_file_name);
 
var protocol_file_name = inputParser.getOrderAttribute("protocol")
print("\n protocol file: " + protocolKey);
 
print("\n protocol_file_name: " + protocol_file_name);
 
var time_string = getTimeString()
 
var protocolEditor = new ProtocolEditor();
protocolEditor.Open(protocol_file_name);
 
var working_input_filename = WorkingFolder + time_string + "_" + StripPath(input_file_name)
print("saving working input file to: ["+working_input_filename+"]")
inputParser.Save(working_input_filename)
print("success")
 
print("modifying protocol")
ModifyProtocol(inputParser, protocolEditor, working_input_filename);
print("success")
 
var working_protocol_filename= WorkingFolder + time_string + "_" + StripPath(protocol_file_name)
print("saving working protocol to: ["+working_protocol_filename+"]")
protocolEditor.Save(working_protocol_filename);
print("success")
 
runset.appendProtocolFileToRunset(working_protocol_filename, 1, "this is a note: blah", false)
 
 
print("deleting input file: [" + input_file_name + "]")
DeleteFile(input_file_name);
 
}
Related information
 
For information about...
See...
Configuring the Watcher feature
Creating the JavaScript
Turning on or off the Watcher feature