Page 1
JavaScript Programming Guide CR1500, CR1100, and CR2700 July 2019 Page 1 of 41 D028868 CR1500 CR1100 CR2700 JavaScript Programming Guide User Manual The Code Corporation 12393 South Gateway Park Place, Suite 600, Draper, UT 84020 +1 (801) 495-2200...
Page 2
Code Corporation. Code Corporation does not warrant that the information is accurate, complete, or error- free. Any use of the technical documentation is at the risk of the user. Code Corporation reserves the right to make changes in specifications and other information contained in this document without prior notice. The reader should consult Code Corporation to determine whether any changes have been made.
........................... 14 reader.cabled ..............................14 reader.locked..............................15 reader.debug ..............................15 Page 3 of 41 D028868 CR1500 CR1100 CR2700 JavaScript Programming Guide User Manual The Code Corporation 12393 South Gateway Park Place, Suite 600, Draper, UT 84020...
Page 4
..............................23 storage.size ................................ 23 storage.getHeader ............................. 24 storage.listFiles ..............................24 Page 4 of 41 D028868 CR1500 CR1100 CR2700 JavaScript Programming Guide User Manual The Code Corporation 12393 South Gateway Park Place, Suite 600, Draper, UT 84020...
Page 5
..........................33 jsSettings.set(param, val) ........................... 33 jsSettings.reset(param) ............................33 jsSettings.get(param) ............................33 Page 5 of 41 D028868 CR1500 CR1100 CR2700 JavaScript Programming Guide User Manual The Code Corporation 12393 South Gateway Park Place, Suite 600, Draper, UT 84020...
Page 6
14.4 Supported JavaScript Core........................38 14.5 Symbology Identifier Values ........................39 Page 6 of 41 D028868 CR1500 CR1100 CR2700 JavaScript Programming Guide User Manual The Code Corporation 12393 South Gateway Park Place, Suite 600, Draper, UT 84020...
Page 7
Set, change, and retrieve reader configuration settings Document Audience This document is designed to guide Code reader users and Developers that wish to customize the behavior of the reader. The commands outlined are targeted at manipulating data, such as removing characters, translating one set of characters to another, and providing different types of output, based on the type of barcode read, appending characters, tabs or new lines, etc.
Page 8
Related Documents Code readers are controlled by a large set of configuration settings that define the behavior of the reader. These settings are described in Code document D027153 (CR8200 CR950 CR1500 CR1100 CR2700 CRA-A271 Configuration Control Document).
Page 9
Installing and Running a .codeRules.js script on the Code Reader The Code-supplied JavaScript file .cra.js is written to check for and include a Code Rules file located on the reader. The file name must conform to the following regular expression: /^\.codeRules*\.js/ The purpose for Code Rules files is primarily to provide override functions for decode attempt, decode, and onEvent.
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 onConfigure property of the Code reader calls the specified function when the reader: Receives a configuration command from a communication port Decodes a configuration command from a code read by the Code reader The application uses this property as an event handler to: ...
It takes in an integer that represents the number of successful decodes that happened during the decode attempt. Example: reader.onDecodeAttempt = function(mode) Page 12 of 41 D028868 CR1500 CR1100 CR2700 JavaScript Programming Guide User Manual The Code Corporation...
The reader.amber property is not yet implemented. reader.red The reader.red property is not yet implemented. Page 13 of 41 D028868 CR1500 CR1100 CR2700 JavaScript Programming Guide User Manual The Code Corporation 12393 South Gateway Park Place, Suite 600, Draper, UT 84020...
XX: “ + hwVersion); reader.cabled The cabled property of the reader object contains a read-only Boolean value, which indicates whether the reader is cabled or wireless. CR1100 and CR1500 will return true, and CR2700 will return false. Page 14 of 41 D028868 CR1500 CR1100 CR2700 JavaScript Programming Guide User Manual ...
Reader Methods reader.runScript The runScript method instructs the Code reader to schedule the load, compile, and execution of the specified JavaScript. The Code reader schedules execution of the script immediately after the currently executing event handler or main script completes. The runScript method does not include a mechanism to return to the calling script.
Example: reader.configure(“CDOPPR2”) // Sets maximum 2 barcode decodes per read reader.beep The beep method causes the Code reader to beep. The user can call the command with one (required) to four arguments, which are as follows: reader.beep(numberOfBeeps, beepOnTime, beepOffTime, delayBeforeBeep).
The decoder marks decoded data as valid or not valid. This flag can be used to signal to the system that data has already been handled or ignore it. Example: var validDecode = decodes[i].valid; Page 17 of 41 D028868 CR1500 CR1100 CR2700 JavaScript Programming Guide User Manual The Code Corporation...
The decode.time property is a read-only property that defines the amount of time, in milliseconds, it took the decode engine to decode the barcode that was just analyzed. Example: var decTime = decodes[i].time; Page 18 of 41 D028868 CR1500 CR1100 CR2700 JavaScript Programming Guide User Manual The Code Corporation...
The decode.symbology property is a read-only property that contains the symbology index assigned by Code Corporation. Valid values for symbology are defined in Appendix 5.3. Example: var symbology = decodes[i].symbology; decodes[i].quality_percent The decode quality percent property is a read-only property that defines an internally-defined image quality value determined by the decode engine, while analyzing the captured image.
The position index of the symbol within the set of QR Code symbols in the structured append format and is an integer between 1 and 16 (including the boundaries) in string format.
Note: Names of files can be up to 200 printable ASCII characters. For compatibility with host file systems, Code recommends you do not use characters that are reserved by host operating systems: /, \, :, ?, *, [, ], ', ", etc.
The storage.write method writes a file to storage. If the file does not exist, the Code reader creates it. If there was an existing file of the same name, it is replaced. If the file contains multi-byte characters, it must be encoded in UTF-8.
The storage.size method returns the size of a file in bytes. Example: var fileSize = storage.size(“timeCard57); Page 23 of 41 D028868 CR1500 CR1100 CR2700 JavaScript Programming Guide User Manual The Code Corporation 12393 South Gateway Park Place, Suite 600, Draper, UT 84020...
Data is maintained in storage as named objects called files. CortexTools2 can transfer host data into a Code reader file. The Code reader application can also store data in files. The name of a Code reader file may contain any printable ASCII characters.
Note: Not applicable to wired products comm.sendPacket The sendPacket method instructs the Code reader to send a data packet to the host, via the communications port currently specified by the active Code reader communication settings. The Code reader creates a packet formatted according to the active Code reader packet protocol configuration setting.
‘0’ representing a key release. Example: comm.sendUsbScanCodes(2,0,0,0,0,0,0,0,2,0,4,0,0,0,0,0, 0,0,0,0,0,0,0,0); Page 26 of 41 D028868 CR1500 CR1100 CR2700 JavaScript Programming Guide User Manual The Code Corporation 12393 South Gateway Park Place, Suite 600, Draper, UT 84020...
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.
– default implementation This implementation is used to manage the internal “interval” timers.cra.js Code provides default reader behavior by implementing special features in JavaScript. These special features are in “.cra.js”. reader.onEvent(event) This function checks for a function variable “rules_onEvent” and if it is not “null”, it will call that function.
The decodes array object (Section 13.1.4) is passed into the function and may be returned by the function. If a Boolean false is returned by the function, the reader will prevent further processing of the decode. The Code reader will initially indicate a good read as soon as a bar code is found.
In the example below, the reader is first set to intercept a button press. The reader will then send a codeXml enter keypress over the comm port. See the CR8200 CCD, Code Document Number D026160 for more information.
.setttings.js Code provides the ability to store persistent user settings by including “.settings.js” to an application or rules file. Configuration barcodes may be created and must match the following format: <JS Identifier> JSUP <P | S | R | G> <PP> <Val>, where <JS Identifier>:...
P0_intervalDelay_sec); rules_onConfigure = function(data) if( jsSettings.parseUserParams ) return jsSettings.parseUserParams(data); return false; Page 33 of 41 D028868 CR1500 CR1100 CR2700 JavaScript Programming Guide User Manual The Code Corporation 12393 South Gateway Park Place, Suite 600, Draper, UT 84020...
Page 34
P0_last = P0_intervalDelay_sec; // Trigger a decode on the interval defined by user parameter P0 var intervalId = reader.setInterval(triggerDecodeNormal, P0_intervalDelay_sec); Page 34 of 41 D028868 CR1500 CR1100 CR2700 JavaScript Programming Guide User Manual The Code Corporation...
The Code reader products are often connected to a PC using keyboard input. The data contained in the bar code is simply “typed” into the PC application. It is also often required to send a certain key to the application, such as an “enter” key. Please note that an “enter” key is not the same as an ASCII carriage return (0x13).
Page 36
"modifying" the key's keystroke. For example, to send just the "a" character using scan codes requires sending the scan code for the "a" key (0x04) with no modifier (0x00); however, to send the "A" character requires sending the "a" key's scan code with a "Shift" modifier (0x02 (left Shift) or 0x20 (right Shift)).
The USB scan codes for the "5" and "e" keys, which are in the same keyboard key position on both the English and Italian keyboards, are 0x22 and 0x08, respectively. The USB modifier scan code for the Italian AltGr key position, which is also the right Alt key position on the English keyboard, is 0x40.
Code 39 Full ASCII (Checksum checked and stripped ) Code 128 (standard) Code 128 (FNC1 in first character position) Code 128 (FNC1 in second character position) (aka UCC/EAN 128) UCC/EAN 128 (aka Code 128 (FNC1 in second character position)) Codabar (checksum not checked)
Page 40
Codablock 256: FNC1 not used (not supported by CD) Codablock 256: FNC1 in first char position (unsupported by CD) Codablock F: FNC1 not used Page 40 of 41 D028868 CR1500 CR1100 CR2700 JavaScript Programming Guide User Manual ...
Page 41
Code 49 (FNC1 in 2nd character position) Code 49 (FNC2 in 1st character position) Grid Matrix Applies to battery powered readers only. Page 41 of 41 D028868 CR1500 CR1100 CR2700 JavaScript Programming Guide User Manual The Code Corporation...
Need help?
Do you have a question about the CR1500 and is the answer not in the manual?
Questions and answers