JavaScript Programming Guide - Code Corporation

Transcription

JavaScript Programming GuideCR1500, CR1100, CR2700, CR8x7x, and CR5200January 2021D028868 05 CR1500 CR1100 CR2700 CR8x7x CR5200 JavaScript Programming Guide User ManualThe Code Corporation 434 West Ascension Way Suite 300, Salt Lake City, UT 84123 1 (801) 495-2200 FAX 1 (801) 495-0280Page 1 of 43

Copyright 2014 - 2021 Code Corporation.All Rights Reserved.The software described in this manual may only be used in accordance with the terms of its license agreement.No part of this publication may be reproduced in any form, or by any means, without written permission from CodeCorporation. This includes electronic or mechanical means, such as photocopying or recording in information storage andretrieval systems.NO WARRANTY. This technical documentation is provided AS-IS. Further, the documentation does not represent acommitment on the part of 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 theright to make changes in specifications and other information contained in this document without prior notice. The readershould consult Code Corporation to determine whether any changes have been made. Code Corporation shall not be liablefor technical or editorial errors or omissions contained herein; nor for incidental or consequential damages resulting fromthe furnishing, performance, or use of this material. Code Corporation does not assume any product liability arising outof, or in connection with, the application or use of any product or application described herein.NO LICENSE. No license is granted, either by implication, estoppel, or otherwise under any intellectual property rights ofCode Corporation. Any use of hardware, software, and/or technology of Code Corporation is governed by its ownagreement.The following are trademarks or registered trademarks of Code Corporation:CodeXML , Maker, QuickMaker, CodeXML Maker, CodeXML Maker Pro, CodeXML Router, CodeXML Client SDK,CodeXML Filter, HyperPage, CodeTrack, GoCard, GoWeb, ShortCode, GoCode , Code Router, QuickConnect Code, RuleRunner , Cortex , CortexRM, CortexMobile, Code, Code Reader, CortexAG, CortexStudio, CortexTools, CortexTools2 ,Affinity , CortexDecoder, CortexJPOS, CR8200 Utility, CR8200 Utility2, and CortexOPOS.All other product names mentioned in this manual may be trademarks of their respective companies and are herebyacknowledged.For patent information, please refer to http://codecorp.com/legal/patents.php.The Code reader software implements the Mozilla SpiderMonkey JavaScript illa/Projects/SpiderMonkey/Releases/1.8, which is distributedunder the terms of the Mozilla Public License.The Code reader software is based in part on the work of the Independent JPEG Group.Code Corporation, 434 West Ascension Way, Suite 300, Salt Lake City, UT 84123. www.codecorp.comD028868 05 CR1500 CR1100 CR2700 CR8x7x CR5200 JavaScript Programming Guide User ManualThe Code Corporation 434 West Ascension Way Suite 300, Salt Lake City, UT 84123 1 (801) 495-2200 FAX 1 (801) 495-0280Page 2 of 43

Table of Contents13.1Reader Object . 10Callback Properties . 10reader.onDecodes(Decode Object Array decodes) . 10reader.onEvent(Event Object event) (CR1100, CR1500) . 11reader.onRawData(data, len) . 11reader.onConfigure(string config) . 11reader.onPowerChange(int mode) . 12reader.onBatteryChange(void) . 12reader.onTrigger(triggerButton, buttonAction)(CR2700) . 12reader.onDecodeAttempt(count) . 13reader.periodic(void) . 13reader.tick1Hz(void) . 13Informational Properties . 13reader.charging . 14reader.green . 14reader.amber . 14reader.red . 14reader.black . 14reader.softwareVersion . 14reader.baseModel . 14reader.model . 14reader.readerId . 15reader.hardwareVersion . 15reader.cabled . 15reader.locked. 15reader.debug . 15D028868 05 CR1500 CR1100 CR2700 CR8x7x CR5200 JavaScript Programming Guide User ManualThe Code Corporation 434 West Ascension Way Suite 300, Salt Lake City, UT 84123 1 (801) 495-2200 FAX 1 (801) 495-0280Page 3 of 43

reader.decodes . 16reader.bdAddr . 16Reader Methods . 16reader.runScript . 16reader.configure . 16reader.beep . 16reader.vibrate . 17reader.indicateGoodRead . 17reader.indicateError . 17reader.shiftJisToUnicode . 17reader.unicodeToShiftJis . 17reader.indicateData . 17reader.indicateWireless . 18reader.indicateBattery . 18reader.getKeyboardStatus . 18reader.getLastImage. 18Reader Decodes Object . 18decodes[i].decoderType . 18decodes[i].valid . 18decodes[i].x . 18decodes[i].y. 19decodes[i].bounds . 19decodes[i].time . 19decodes[i].symbology . 19decodes[i].quality percent . 20decodes[i].aimSymbology . 20decodes[i].symbologyModifier . 20decodes[i].aimModifier . 20decodes[i].linkage. 20decodes[i].saPosition . 21decodes[i].saTotal . 21decodes[i].saParity . 21decodes[i].isConfig . 21decodes[i].decodeOutputFormat . 21decodes[i].data (type string) . 2213.2Storage Object . 22Informational Properties . 22storage.isFull . 22storage.fullness percent . 22Storage Methods . 22storage.read . 23storage.write . 23storage.append . 23storage.rename. 23storage.erase . 23storage.uploadFile . 23storage.defragment . 23storage.findFirstInternal . 24storage.findNextInternal . 24storage.findFirst . 24storage.findNext . 24storage.size . 24storage.getHeader . 24D028868 05 CR1500 CR1100 CR2700 CR8x7x CR5200 JavaScript Programming Guide User ManualThe Code Corporation 434 West Ascension Way Suite 300, Salt Lake City, UT 84123 1 (801) 495-2200 FAX 1 (801) 495-0280Page 4 of 43

storage.listFiles . 25Data in Code Reader Local Storage . 2513.3Comm Object . 25Informational Properties . 25comm.isConnected . 25Comm methods . 26comm.connect . 26comm.disconnect . 26comm.sendPacket . 26comm.sendText . 26comm.sendData . 26comm.sendMessage . 27comm.getSendStatus . 27comm.sendUsbScanCode . 27comm.sendUsbScanCodes . 27comm.sendHidReport . 2813.4Shell Functions. 28help([name]) . 28include(name) . 28print (string) – see reader.print(string) . 28gc() . 28sleep ms(time ms) . 28format(string format, .) . 28wdt pet() . 29logMessage(string) . 2913.5Pre-defined Scripts . 29.jseLib.js library functions . 29storage.findFirst(regex) . 29storage.findNext() . 29reader.setInterval (func, interval) . 30reader.clearInterval(intervalId) . 30reader.setTimeout (func, delay) . 30reader.clearTimeout(timeoutId) . 30reader.tick1Hz() – default implementation . 30reader.now() (CR5200) . 30checkSAV(decode) (CR5200) . 30This implementation is used to manage the internal “interval” timers.cra.js . 31reader.onEvent(event) . 31reader.onDecodeAttempt(count) . 31reader.onDecode(decode) . 31reader.onDecodes(decodes) . 31reader.onConfigure(data) . 31.codeRules.js . 31rules onDecodes . 31rules onDecodeAttempt . 32rules onDecode . 32rules onEvent . 32rules onConfgure(data) . 33Optional Global variables . 33.setttings.js . 33jsSettings.def(param, val) . 34jsSettings.put(param, val) . 34D028868 05 CR1500 CR1100 CR2700 CR8x7x CR5200 JavaScript Programming Guide User ManualThe Code Corporation 434 West Ascension Way Suite 300, Salt Lake City, UT 84123 1 (801) 495-2200 FAX 1 (801) 495-0280Page 5 of 43

jsSettings.set(param, val). 34jsSettings.reset(param) . 34jsSettings.get(param) . 3414.1Sending Keystrokes (CodeXml) . 3614.2Glossary and Acronyms . 3814.3Encrypting a JavaScript file . 3914.4Supported JavaScript Core. 3914.5Symbology Identifier Values . 4014.6onDecode(s) Return Value Matrix. 4314.7onDecode(s) Compatibility Matrix . 43D028868 05 CR1500 CR1100 CR2700 CR8x7x CR5200 JavaScript Programming Guide User ManualThe Code Corporation 434 West Ascension Way Suite 300, Salt Lake City, UT 84123 1 (801) 495-2200 FAX 1 (801) 495-0280Page 6 of 43

IntroductionCode Corporation (Code) designs, develops, and manufactures image-based readers and software tools for datacollection applications. With expertise in software development, optics, imaging, and Bluetooth wirelesstechnology, Code is an innovative leader in the Auto ID and Data Collection Industries.Many Code readers combine bar code reading with an easy-to-use JavaScript- based application development.This user manual is applicable for the CR1100, CR1500 and CR2700 series readers.Document PurposeThis manual describes the JavaScript application programming interface (API) for the Code readers (CR1100,CR1500 and CR2700). It is assumed the user has programming knowledge and familiarity with the JavaScriptlanguage. Code readers read barcodes and can be programmed to transmit code data over a selectedcommunications link, or to store data in reader memory (batch mode when available). The programming environment provides interfaces to:oooooRead and manipulate data in reader memoryAccess data sent by hostTransmit data to a host computer, via communication linkSelect type of communication linkSet, change, and retrieve reader configuration settingsDocument AudienceThis document is designed to guide Code reader users and Developers that wish to customize the behavior ofthe reader. The commands outlined are targeted at manipulating data, such as removing characters, translatingone 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.Document and Coding ConventionsThis document employs the following conventions to aid in readability: Words that are part of the application development description use the Courier New font Code examples use the bold Courier New font in blue Variable names that must be supplied by the programmer are: Courier New font and areenclosed in relational signs; for example: variable name .The Code reader JavaScript library uses the following naming conventions: Identifiers: Mixed-case with a capital letter, where words join (soCalledCamelCase), e.g.,nasaSpaceShuttle, httpServer, codeXml Acronyms and other initialisms are capitalized like words, e.g., CIMCE, CPU Variables and Properties: Initial lower case, e.g., thisIsAVariable, thatIsAProperty Classes (i.e., constructors): Initial capital, e.g., AClassIsCapitalizedCamelCase Functions: Initial lower case, similar to variables and propertiesD028868 05 CR1500 CR1100 CR2700 CR8x7x CR5200 JavaScript Programming Guide User ManualThe Code Corporation 434 West Ascension Way Suite 300, Salt Lake City, UT 84123 1 (801) 495-2200 FAX 1 (801) 495-0280Page 7 of 43

Unit of measure: Suffix to name, separated from name by underscore, using correct case when it’ssignificant, e.g., offset pixels, width mm, power mW, powerRatio dBRelated DocumentsCode readers are controlled by a large set of configuration settings that define the behavior of the reader. Thesesettings are described in Code document D027153 (CR8200 CR950 CR1500 CR1100 CR2700 CRA-A271Configuration Control Document). Please familiarize yourself wit

D028868_05 CR1500 CR1100 CR2700 CR8x7x CR5200 JavaScript Programming Guide User Manual Page 7 of 43 The Code Corporation 434 West Ascension Way Suite 300, Salt Lake City, UT 84123 1 (801) 495-2200 FAX 1 (801) 495-0280 Introduction Code Corporation (Code) designs, develops, and man