D028868 CR1500 CR1100 CR2700 JavaScript Programming Guide User Manual Page 10 of 41
The Code Corporation
12393 South Gateway Park Place, Suite 600, Draper, UT 84020
+1 (801) 495-2200
FAX +1 (801) 495-0280
Code JavaScript Objects
JavaScript objects have properties and methods. Code uses the properties to allow user customization of the
JavaScript implementation on the reader. Methods, on the other hand, provide communication between the
JavaScript engine and the reader firmware. All of the custom reader object properties and methods are
described in the following sections:
13.1 Reader Object
The reader object provides application software access to selected Code reader functionality and
information.
Callback Properties
Callback properties are functions that are provided by JavaScript assignments. Most callback
properties have default behavior defined in .cra.js.
reader.onDecodes(Decode Object Array decodes)
The reader.onDecodes function provides processing control to the application program
at the completion of a decode action. The reader.onDecodes(decodes) argument “decodes” is
an array of Decode Objects.
Example:
reader.onDecodes = function(decodes)
{
for(var i = 0; i < decodes.length ; ++i)
comm.sendText(decodes[i].data); // send decoded data to the
host
return true;
}
reader.onEvent(Event Object event) (CR1100, CR1500)
The onEvent property of the reader object provides a way for the user to issue and handle
simulated key press, release, and hold events, which will be processed by JavaScript. onEvent
has an event object passed to it, which has two properties: event.type, and
event.input. Values for type are PRES(1), HOLD(2), and RELS(3), and the values for input
are TRIG(0), WAKE(1), STND(2), INP0(3), and INP1(4).
Example:
const TRIG = 0;
const PRES = 1;
reader.onEvent = function(event)
{
if(event.type == PRES)
reader.beep();
return true;
}