D028868 CR1500 CR1100 CR2700 JavaScript Programming Guide User Manual Page 28 of 41
The Code Corporation
12393 South Gateway Park Place, Suite 600, Draper, UT 84020
+1 (801) 495-2200
FAX +1 (801) 495-0280
Example:
{
var myString = “”;
format(“This is an int %d and this is a string %s”, 274,
“Two hundred seventy four”, &myString);
print(myString);
}
wdt_pet()
Long processes may require the firmware watchdog to be petted during the operation. If the
watchdog times out during a processor-intensive operation, the reader will reboot and an error will be
logged in the error log. To prevent the reader from rebooting during a processor-intensive section, the
firmware watchdog timer needs to be petted. wdt_pet() takes a single argument indicating the
number of seconds before the watchdog timer times out.
Example:
wdt_pet(1);
logMessage(string)
The logMessage function writes the given string into the log.
Example:
logMessage(“Writing to log”);
13.5 Pre-defined Scripts
The Code reader core JavaScript application provides a simple method for handling the most common
tasks. This method will allow people with minimal programming knowledge to customize the product to
their needs, using a subset of JavaScript and Regular Expressions. Regular Expressions, combined with
JavaScript String methods, such as .match and .replace become powerful data manipulators.
When JavaScript is enabled, the reader first loads the default library file “.jseLib.js”. JavaScript then loads
“.startup.js”, which contains the include statement “include(.default.js);”. The default “.default.js” file will
“include(.cra.js)”. These files provide the basic JavaScript functionality for the reader.
.jseLib.js library functions
storage.findFirst(regex)
The implementation of storage.findFirst(regex) is to scan all files looking for a
regex match and stop on the first match.
storage.findNext()
The implementation of storage.findNext() is to scan all remaining files from the
previous storage.findFirst() / storage.findNext() looking for a regex match
established in the storage.findFirst(regex) and stop on the next match.