CETerm Scripting Guide for Version 5.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC Copyright Notice This document may not be reproduced in full, in part or in any form, without prior written permission of Naurtech Corporation. Naurtech Corporation makes no warranties with respect to the contents of this document and specifically disclaims any implied warranties of merchantability or fitness for any particular purpose.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC Table of Contents Copyright Notice .............................................................................................................................. 2 Trademarks...................................................................................................................................... 2 Software Version .............................................................................................................................
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC Methods.................................................................................................................................. 37 Properties ............................................................................................................................... 39 4.0 CETerm Script Events ............................................................................................................. 40 4.1 The OnBarcodeRead Event..........
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC 5.9 Debugging Scripts................................................................................................................ 64 5.9.1 Show Script Errors ........................................................................................................ 64 5.9.2 OS.Alert() ...................................................................................................................... 65 Appendix 1 - IDA Action Codes ...................
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC Preface All of us at Naurtech Corporation constantly strive to deliver the highest quality products and services to our customers. We are always looking for ways to improve our solutions. If you have comments or suggestions, please direct these to: Naurtech Corporation e-mail: support@naurtech.com Phone: +1 (425) 837.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC Additional Documentation Naurtech Scripting is an integral feature of Naurtech terminal emulation Smart Clients. Please refer to the User’s Manual for detailed installation and configuration information. The User’s Manual may be downloaded from the “Support” section of our website.
1.0 Introduction The Naurtech CETerm Smart Clients provide a robust and flexible environment for Terminal Emulation and Web based applications on a mobile device. Our Clients are available for most Windows CE platforms including CE .NET 4.2, Windows CE 5.0, Windows Mobile 2003, and Windows Mobile 5. Device tailored versions of our Clients are available for most industrial terminals.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC Document Object Model (DOM), and other aspects of Dynamic HTML if you are scripting web browser features. Please refer to the Naurtech User’s Manual for details on basic usage and configuration of the Naurtech clients. We hope that our Scripting features will enrich and extend the capabilities of your TE and browser applications. Explore a little deeper and we think you will be amazed at the possibilities for building powerful business applications. 1.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC • • • • • Workflow Automation. Scripts can be used to automate routine tasks. The task may be a simple login process or a complex set of steps in your host application. Event Activated Scripts. There are several events within CETerm that will run associated scripts.
2.0 Getting Started This section describes some common ways that scripting features can be used within CETerm. Here we describe the JavaScript engine in CETerm and show how to load and edit a script. We also show sample scripts which (1) handle scanner input, (2) auto-login a terminal emulation session, and (3) provide userspecified “hot-spots” on the screen. Only small code “snippets” are shown. For complete details see the later sections of this manual. 2.
2.2 ENABLING SCRIPTING AND EDITING SCRIPTS Scripting is disabled by default. To enable scripting, open the configuration dialog [Session]->[Configure]->[Options]->[Configure Scripting] General Settings On the General tab, check the Enable box and check Show Script Errors. You may also want to enable file and registry access permission or program launching if you need these features.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC After selecting a script slot and tapping the Edit button, an Edit Script dialog will appear. The edit dialog allows Import and Export of scripts. For initial script development it may be easier to edit on your desktop PC, copy the script to the device, and Import the script. Smaller changes are easily made on the device.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC statements or is a function call, it will simulate activating the script. In general, you do not want to use Test/Load for executable statements. Remember to tap Test/Load or Re-Initialize (with Load at Startup checked) after making changes to a script, if you want those changes loaded into the script engine. Also, Test/Load will not work if you have just checked Enable but not yet accepted the configuration changes.
2.3 CETERM AUTOMATION OBJECTS The CETerm Automation Objects provide access to the running CETerm application, session screens, the Windows CE operating system, and other features. For example the command CETerm.PostIDA( "IDA_SESSION_S1", 0 ); within a script would switch CETerm to Session 1 if another session was currently active. Automation Objects can give access to the browser Document Object Model (DOM) of connected web sessions and the text on terminal emulation sessions.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC /* OnBarcodeRead */ function OnBarcodeRead( session, data, source, type, date, time ) { // Manipulate barcode data here // Send barcode to emulator CETerm.SendText( data, session ); // Return 0 to handle barcode normally // Return 1 if handled data here return 1; } This handler simply passes the barcode data on to the current session using the “SendText” method.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC // Prefix zeros to short barcodes if (data.length == 8) { data = "000" + data; } // Send barcode to emulator CETerm.SendText( data, session ); // Return 1 if handled data here return 1; } The following OnBarcodeRead handler will split any barcode containing an ASCII Linefeed (LF = 0x0A) character and terminated with an ASCII ENQ (ENQ = 0x05) into two parts.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC // All scan data handled here return 1; } } // Handle scan data in normal way return 0; } The type argument to OnBarcodeRead contains the labeltype of the barcode. This labeltype is related to the barcode symbology but usually a little more informative. The values are dependent on the hardware manufacturer but for most devices are the same as the Symbol LABELTYPE.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC var mypassword = "secret"; var waittime = 8000; // Milliseconds waiting for each text // Only login session 1 if (session == 1) { // Look for "login" then "password" expect( session, waittime, "Login", myusername + "\r", "Password", mypassword + "\r" ); } } The expect arguments are session for the session index, waittime for the milliseconds waiting for each expected text, followed by pairs of expected text (prompt) and corresponding action(response).
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC 2.7 CUSTOM SCREEN HOT-SPOTS A “hot-spot” is an area on a terminal emulation screen that is activated by taping with your finger or the stylus. CETerm supports several pre-defined hot-spots for TE sessions. With scripting, it is possible to define custom hot-spot behaviors. Custom hot-spots use the “OnStylusDown” event handler. Browser sessions do not support the OnStylusDown event because equivalent behavior can be implemented in HTML.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC case case case case } 1: 2: 3: 4: IDA IDA IDA IDA = = = = "IDA_VT_PF1"; "IDA_VT_PF2"; "IDA_VT_PF3"; "IDA_VT_PF4"; break; break; break; break; // DEBUG: Uncomment next two lines for testing //OS.Alert( "row=" + row + " col=" + column + // " button=" + button + " IDA=" + IDA ); if (!IDA.match("IDA_NONE")) { // Send command CETerm.PostIDA( IDA, session ); } } } You may have noticed by now the use of PostIDA in some cases and SendIDA in other cases.
3.0 CETerm Automation Objects This section describes the Automation Objects available to the CETerm script engine. These objects provide access to the running CETerm application, TE session screens, the Windows CE operating system, and other features for developing rich applications. The automation objects are accessed in a hierarchical manner similar to the Document Object Model (DOM) of a webpage. The two top-level objects are CETerm and OS.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC AbortScript( ) Stops the currently executing script. ClearAllTimers( ) Clear all recurring interval timers and one-time timers. ClearInterval( intervalTimerID ) Clear the specified recurring interval timer. ClearTimeout( timerID ) Clear the specified one-time timer. value = GetProperty( propertyName ) Return the named property value. This may be a device property, application property, or session property.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC Multiple tone specifications can be concatenated. PlayTone( volume, frequency, duration ) (deprecated) Play a tone if supported by the handheld hardware. This method is provided for backward compatibility within the web browser. New application should use OS.Playtone() which provides the same functionality. volume – is the volume 00 -10 (0 is off, 10 is loudest) frequency – is the frequency in Hz. duration – is the duration in milliseconds.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC SendText( text, session ) SendText sends a text string to the specified session. Valid session values are 1-4. The special session value of 0 will send the command to the current session. This command is synchronous and CETerm will act on each character before this method returns. The text string may include IDA symbolic names between backslash characters ‘\’. The IDA codes will be interpolated as the text is sent.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC SetScriptTimeout( millisec ) Set the maximum script execution time. This value may be updated during a running script. If updated, the new timeout will apply starting at the time of the change. A value of 0 will disable the timeout. timeoutTimerID = SetTimeout( scriptExpression, delayMillisec ) Set a one-time timer to execute the scriptExpression after a delay of delayMillisec.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC Methods The Session object has no methods. Properties The Session object has several read only properties. Property Description Values Browser IsConnected Returns browser object. (read only) Returns true if session is connected. (read only) Returns screen object. (read only) object true, false Screen object 3.3 THE SCREEN OBJECT The Screen object gives access to a session terminal emulation screen.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC text = GetTextRect( startRow, startColumn, endRow, endColumn ) Return the requested rectangle of text. Each line fragment will be separated by the TextLineSeparator property value. If the session is not connected the JavaScript null value is returned. End coordinates of -1 will use the maximum valid value. Properties The Screen object has several read only properties. Property Description Rows Columns CursorRow Number of rows in screen.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC result = AddMetaItem( target, content ) Add a CETerm tag element to the current web page. This is typically used to add custom elements which define key mappings or other custom behaviors. See the Naurtech Web Browser Programming Guide for documentation on custom tags. Returns 0 for success, non-zero for failure. After adding META elements that change the values of information icons you may need to use CETerm.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC as tasks are completed, or it can run at a constant rate to show activity to the user. Methods The Message object has no methods. Properties The Message object is controlled through read-write properties. Setting a property will change the message dialog appearance. Property Description AbortButtonVisible If true, a script abort button is visible. Taping this button will abort the current script execution.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC Method Action GetInput Get input from the user result = GetInput( ) GetInput displays the user input dialog. Returns 1 for successful input, 0 if input is canceled by the user, and -1 if there was an error. A default response may be set in the Input property prior to calling GetInput. If no default is desired, be sure to clear Input prior to calling GetInput. Properties The TextInput has the following properties.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC MessageBox PlaySound PlayTone Sleep StopSound WaitForProcess Display a standard Windows MessageBox. Play a wave file on the device. Play a tone on the device. Pause the script execution. Stop an asynchronous playing PlaySound sound. Wait for the specified process to end. Alert( message ) Show the user a simple text message and wait for them to press OK. Beep( ) Sound the default Windows beep tone.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC PlaySound( sound, flags ) Play a wave file on the device. This PlaySound is not the same as the CETerm.PlaySound(). Use the complete file path if the wave file is not in the \Windows directory. The flags control the way the sound is played. See Appendix 4 for flag definitions. Returns true on success, false otherwise. PlayTone( volume, frequency, duration ) Play a tone if supported by the handheld hardware.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC Property Description Values LastError Returns the last Windows error related to the OS object. Returns the process ID of the last program started via Exec. (read only) Returns the Registry object. This object provides access to the Windows registry. (read only) Returns the current tick count from Windows. This provides a millisecond resolution time source.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC Use the File properties LastError or LastErrorMessge to get additional error information. status = CreateDirectory( newDirectory ) Create a new directory. Returns true for success, false for failure. Use the File properties LastError or LastErrorMessge to get additional error information. status = Delete( filename ) Delete an existing file. Returns true for success, false for failure.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC status = Move( existingFilename, newFileName ) Move or rename an existing file. Returns true for success, false for failure. Use the File properties LastError or LastErrorMessge to get additional error information. contents = Read( filename ) Read entire file and return as contents. The read is an atomic operation which opens the file, reads all contents and closes the file.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC Property Description LastError Returns the last error value associated with the File object. LastErrorMessage Returns a text message of the last error associated with the File object. (read only) Values unsigned integer text 3.9 THE REGISTRY OBJECT The Registry object provides access to the Windows registry. The registry is a form of database on Windows devices which holds the device configuration. The registry has a hierarchical structure.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC status = DeleteKey( keyname ) Deletes an existing key and all values. Returns 0 for success or non-zero for an error. Delete will fail if a key has sub-keys. status = DeleteValue( keyname, valuename ) Deletes the specified value in an existing key. Returns 0 for success or non-zero for an error. keylist = EnumerateKeys( keyname ) Return a list of sub-keys of the specified key. See Appendix 4 for key names and definitions.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC hexadecimal digits. MULTI_SZ strings are separated with the current StringSeparator property value. data = ReadValueVBArray( valuename ) Read the data from the specified value. Return the data as a Visual Basic array. Use a fully qualified value name that starts with a root key. It is usually best to use the ReadValue method and split the values using JavaScript. In rare circumstances a true array may be needed.
4.0 CETerm Script Events This section describes the script events within the CETerm script engine. These events provide ways to trigger event handlers when various conditions occur in CETerm. The event handlers are arbitrary scripts. The event model in CETerm uses specific event handler names to bind events to handlers. If the event handler function (e.g., “OnBarcodeRead”) is defined in the script engine, it will be executed when the event occurs.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC Example Several samples for OnBarcodeRead were given in Section 2.5. Following is an example that checks the RF connection before submitting the data to the host. This notifies the user that the barcode was not received by the host and instructs the user to return to RF coverage. /* OnBarcodeRead */ function OnBarcodeRead( session, data, source, type, date, time ) { // Check RF status var status = CETerm.GetProperty( "device.rf.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC Example This example shows how several META tags can be added to a web page. We will add a “PowerOn” handler, a key remapping, and information item tags to position the RF indicator at a special location. The “PowerOn” handler is often used to navigate to a specific page, such as a login page, when the device resumes.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC session – index of browser session which failed to navigate. params – navigation error parameters, including the error number and URL. The params argument is formatted as URL parameters and has the form: error=0x800C0005&url=http://192.168.1.20/application.exe?state=3&scan=0 Everything after url= in the params argument is the URL that failed to navigate, along with all the parameters of that URL.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC Example For Windows Mobile devices Handheld devices using Windows Mobile can use a different technique to pass on the params URL. For these devices, the parameters of a “file:” URL are available within the browser. The error parameters can simply be passed on to the static page without using a “User Text x” variable. /* OnNavigateError */ function OnNavigateError( session, params ) { // Navigate to static error page var b = CETerm.Session( session ).
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC /* OnNetCheckFailed */ function OnNetCheckFailed ( session, pendingURL ) { // Save pendingURL in text 3x where x is session index // This is required by CE 5.0 devices which do not pass // parameters to a "file:" URL. CETerm.SetProperty( "app.usertext.3" + session, pendingURL ); // Navigate to static error page var b = CETerm.Session( session ).Browser; b.Navigate( "file:///error.htm" ); } See the OnNavigateError example above for additional details.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC { // Look for "login" then "password" expect( session, waittime, "Login", myusername + "\r", "Password", mypassword + "\r" ); } } 4.6 THE ONSESSIONDISCONNECT EVENT The OnSessionDisconnect event is fired when a session is disconnected by a user action. The handler can be used to switch to another session, exit, or perform other cleanup tasks. Syntax function OnSessionDisconnect( session ) session – index of session which was disconnected by user.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC 4.7 THE ONSESSIONDISCONNECTED EVENT The OnSessionDisconnected event is fired when a terminal emulation (TE) session is disconnected by the remote host. The handler can be used to attempt to reconnect to the host or perform other cleanup tasks. Syntax function OnSessionDisconnected( session ) session – index of session which was disconnected by remote host. Example This example will check for RF coverage and attempt to reconnect if RF is detected.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC session – index of session which received data. count – count of bytes received. Example This example will check the screen content on line 24 looking for an error message. If found, the error is displayed as a popup message. /* OnSessionReceive */ function OnSessionReceive( session, count ) { // Get line of text var s = CETerm.Session( session ).Screen; var line = s.GetTextLine( 24 ); // Do a regular expression case-insensitive match if (line.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC function OnSessionSwitch( session, previousSession ) { var b = CETerm.Session( session ).Browser; if (b.DocLoaded) { var x = (session == 1) ? 195 : 10; var y = (session == 1) ? 10 : 100; b.AddMetaItem( "Battery", "x=" + x ); b.AddMetaItem( "Battery", "y=" + y ); CETerm.PostIDA( "IDA_INFO_REFRESH", 0 ); } } 4.10 THE ONSTYLUSDOWN EVENT The OnStylusDown event is fired when the user taps a terminal emulation screen with a stylus or finger.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC // Look for "scan" as case-insensitive match if (text.match( /scan/i )) { CETerm.PostIDA( "IDA_SCAN_TRIGGER", 0 ); } } 4.11 THE ONWAKEUP EVENT The OnWakeup event is fired when the device resumes after suspending. The handler can be used to perform any action, such as waiting for RF coverage or switching to a specific session. Syntax function OnWakeup( ) Example This example will wait for RF coverage to resume and sound a tone when it is available.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC { RFWakeupSoundContinue = 1; if (RFWakeupSoundTimerID != 0) { // Stop and clear any previous check CETerm.ClearTimeout( RFWakeupSoundTimerID ); RFWakeupSoundTimerID = 0; } RFWakeupSoundCount = 0; // Schedule first RF check RFWakeupSoundTimerID = CETerm.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC } } function RFWakeupSoundPlay() { // Select any wave file on device for notification. CETerm.PlaySound( "infbeg" ); } 5.0 Scripting Techniques and Tips This section describes ways that scripting can extend the capabilities of CETerm. Tips for script development are also presented. 5.1 EXPECT AND EXPECTMONITOR FOR AUTOMATING TASKS The “expect” script and “ExpectMonitor” class provide a general purpose “prompt-and-response” tool.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC { // Build array from arguments // This technique will accumulate any // number of expect/response pairs var TargetResponseArray = []; for (var i=2; i < arguments.length; i++) { TargetResponseArray.push( arguments[i] ); } // Create an ExpectMonitor class that manages the actions var EM = new ExpectMonitor( session, timeout, TargetResponseArray ); // Set optional ExpectMonitor behaviors //EM.silent = true; //EM.OnDone = function (success) { OS.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC this.state = 0; this.timer = null; this.checkCount = 0; this.totalCheckCount = 0; this.maxCheckCount = this.timeout / this.checkDelta; // Abort any existing object if (ExpectMonitor.Instances[this.session] != null) { ExpectMonitor.Instances[this.session].Abort(); } // Record this instance in the global array ExpectMonitor.Instances[this.session] = this; } function ExpectMonitor_Check() { // Clear timer id this.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC OS.Alert("Unknown action type for expect."); } } // Check if another match expected this.state +=2; target = this.args[this.state]; if (target != null) { // Schedule next check this.Schedule(); } else { // Done with this expect. // Run any post-execution actions if (typeof this.OnDone == "function") { this.OnDone( true ); } } } else { // No match, schedule again if (this.checkCount++ < this.maxCheckCount) { this.Schedule(); } else { if (!this.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC this.timer = CETerm.SetTimeout( script, this.checkDelta ); } function ExpectMonitor_Start() { // Cleanup first in case restarted this.Abort(); // Initialize state this.state = 0; this.checkCount = 0; this.Check(); } function ExpectMonitor_Abort() { // Stop any timer if (this.timer != null) { CETerm.ClearTimeout( this.timer ); this.timer = null; } // Set state to beyond reasonable range this.state = 1000; } // Method definitions ExpectMonitor.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC 5.1.3 Automating Tasks with Expect Any routine prompt-and-response task can be automated with “expect”. Examples may be navigating through a hierarchy of menus or closing an order for shipping. In any case, you identify text to find on the screen and the user input to take you to the next screen. Here is a simple menu traversal: // Traverse menu expect( CETerm.ActiveSession, 8000, "3. Applications", "3\r", "2. Inventory", "2\r", "2.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC m.IsVisible = true; You may want to update the progress bar directly while processing data. Here is an example. /* Update progress and message during processing */ var m = CETerm.Message; m.Text = "Processing data, please wait."; m.Timeout = 0; m.AbortButtonVisible = false; m.ProgressRunning = false; // Do some work m.Progress = 0; m.IsVisible = true; OS.Sleep( 2000 ); // Simulate work delay // Update m.Progress = 20; m.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC var s = t.GetInput(); if (s == 1) { OS.Alert( "Password is " + t.Input ); t.Input = ""; // Clear password } else { OS.Alert( "Failed to get password." ); } 5.4 RUNNING AN EXTERNAL PROGRAM It is possible to start an external program from the CETerm script engine. You can wait for the program to finish or allow it to run independently. Usually you will run a program then return to CETerm when it exits. Here is an example to start the stylus calibration.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC The following example will save data from memory to a flash file whenever a particular URL is loaded. /* OnDocumentDone */ function OnDocumentDone( session ) { var b = CETerm.Session( session ).Browser; if (b.Document.URL.match( /InventorySave/ )) { // Resume online inventory, and save cached // data to file in background. CETerm.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC var F = OS.File; // Check if file exists var attributes = F.GetAttributes( filename ); if (attributes != 0xFFFFFFFF) { var content = F.Read( filename ); status = F.Write( filename, content + addedContent ); } else { status = F.Write( filename, addedContent ); } return status; } 5.7 ACCESSING THE REGISTRY The registry on a Windows CE device is a form of database which contains most of the device configuration.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC // Check if can read value var readdata = R.ReadValue( fullyQualifiedKey ); if (readdata == valuedata) { status = true; } } if (!status) { OS.Alert( "Failed to confirm write of " + fullyQualifiedKey ); } return status; } NewRegistryDWORD may be used as follows. // Write a new value NewRegistryDWORD( "SOFTWARE\\Naurtech\\Test", "TestDword", 510 ); 5.8 WRITING EFFICIENT SCRIPTS Good programming practices should be used when developing scripts for CETerm.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC JavaScript engine in CETerm is not reset frequently like a browser JavaScript engine, it is more likely that poor programming practices could exhaust memory. 5.8.2 Encapsulate Code in Functions Whenever possible, put multiple script actions within a function. This should minimize compilations and make it easier to use local variables as described above. For example, the following actions could be in a script which is bound to a key-combination: CETerm.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC Do not disable the “Script Timeout” unless you are sure your script will not enter an infinite loop. 5.9 DEBUGGING SCRIPTS All but the most trivial script will require some degree of debugging. 5.9.1 Show Script Errors The first step is to enable “Show Script Errors”. This will enable a popup message for compilation and runtime errors. Compilation errors will usually be seen when new scripts are added or upon script engine startup.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC 5.9.2 OS.Alert() Because there is no JScript debugger on the Windows CE device, the tried-andtrue debugging tool is “OS.Alert( message )”. Experienced programmers will recognize this as the “write(6,100)”, “printf” or “MessageBox” technique. The basic idea is to sprinkle “OS.Alert()” calls through your code to track program flow and variable values. It can be tedious, but it’s easy to do and easy to remove the OS.
Appendix 1 - IDA Action Codes Many IDA codes apply only to a Terminal Emulation session. Some IDA codes can only be used in restricted circumstances, such as IDA_URL.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC Symbolic Name Friendly Name IDA_AT IDA_A IDA_B … IDA_Z @ A B … Z IDA_LEFT_BRACKET IDA_BACKSLASH IDA_RIGHT_BRACKET IDA_CARET IDA_UNDERSCORE IDA_BACKTICK IDA_a IDA_b … IDA_z [ \ ] ^ _ ` a b … z IDA_LEFT_BRACE IDA_PIPE IDA_RIGHT_BRACE IDA_TILDE IDA_DEL { | } ~ DEL C1 ASCII Controls IDA_IND IDA_NEL IDA_HTS IDA_RI IDA_SS2 IDA_SS3 IDA_DCS IDA_PU1 IDA_PU2 IDA_CSI IDA_ST IDA_OSC IDA_PM IDA_APC Index Next Line Horiz Tab Set Reverse Index Single Shift 2 S
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC Symbolic Name Friendly Name Description IDA_INHIBIT_UPDATE IDA_UNINHIBIT_UPDATE IDA_UPDATE IDA_INHIBIT_SEND IDA_UNINHIBIT_SEND IDA_SEND_PENDING Inhibit Update Uninhibit Update Update Inhibit Send Uninhibit Send Send Pending Chars Don’t update display Allow display update Force display update VT buffer characters VT stop buffering VT send buffered chars IDA_PROGRAM_ABOUT IDA_PROGRAM_EXIT IDA_PROGRAM_EXITSILENT IDA_PROGRAM_HELP Program About Program
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC Symbolic Name Friendly Name Description IDA_SESSION_S4 Session 4 Switch to session 4 IDA_TOOLBAND_HIDE IDA_TOOLBAND_TOGGLEHIDE IDA_KEYBAR_HIDE IDA_KEYBAR_TOGGLEHIDE IDA_KEYBAR_LEFT Hide ToolBar Toggle ToolBar Hide KeyBar KeyBar Toggle Prev KeyBar IDA_KEYBAR_RIGHT Next KeyBar Hide full Toolbar Toggle Toolbar visibility Hide KeyBar Toggle KeyBar visibility Switch to previous KeyBar Switch to next KeyBar IDA_KEYBAR_SEPARATOR IDA_KEYBAR_NONE IDA_H
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC Symbolic Name Friendly Name Description IDA_SLEEP_200 IDA_SLEEP_1000 IDA_SLEEP_5000 IDA_SLEEP_20000 IDA_SLEEP_100000 Sleep 200msec Sleep 1sec Sleep 5sec Sleep 20sec Sleep 100sec IDA_SCAN_RESUME IDA_SCAN_SUSPEND IDA_SCAN_TRIGGER Scan Resume Scan Suspend Scan Trigger Allow scanning Suspend scanning Soft trigger scanner IDA_MACRO_OPEN IDA_MACRO_CLOSE IDA_MACRO_TOGGLEHIDE Macro Show Macro Hide Macro Toggle IDA_MACRO_RECORD IDA_MACRO_STOP IDA_MACRO_
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC Symbolic Name Friendly Name IDA_IBM_HOME IDA_DELETE IDA_INSERT_ON IDA_INSERT_OFF IDA_INSERT_TOGGLE IDA_ATTN IDA_CLEAR IDA_CURSOR_SELECT IDA_DUP IDA_ERASE_EOF IDA_ERASE_INPUT IDA_FIELD_MARK IDA_NEWLINE IDA_PA1 IDA_PA2 IDA_PA3 IDA_RESET IDA_SYSREQ IBM Home Delete Insert On Insert Off Insert Toggle Attn Clear Cursor Select DUP Erase EOF Erase Input Field Mark Newline PA1 PA2 PA3 Reset Sys Request Description 5250 Specific Actions IDA_FIELD_EXIT IDA_FIE
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC Symbolic Name Friendly Name IDA_REMOVE IDA_SELECT IDA_VT_PF1 IDA_VT_PF2 IDA_VT_PF3 IDA_VT_PF4 IDA_VT_COMMA IDA_NUMPAD_0 IDA_NUMPAD_1 IDA_NUMPAD_2 IDA_NUMPAD_3 IDA_NUMPAD_4 IDA_NUMPAD_5 IDA_NUMPAD_6 IDA_NUMPAD_7 IDA_NUMPAD_8 IDA_NUMPAD_9 IDA_VT_ENTER IDA_VT_MINUS IDA_VT_PERIOD Remove Select VT PF1 VT PF2 VT PF3 VT PF4 Numpad Comma Numpad 0 Numpad 1 Numpad 2 Numpad 3 Numpad 4 Numpad 5 Numpad 6 Numpad 7 Numpad 8 Numpad 9 Numpad Enter Numpad Minus Numpad
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC Symbolic Name Friendly Name IDA_VT_CSI_Q IDA_VT_CSI_R IDA_VT_CSI_S IDA_VT_CSI_T VT CSI Q VT CSI R VT CSI S VT CSI T Description Windows App Keys IDA_APPKEY_K1 IDA_APPKEY_K2 … IDA_APPKEY_K16 App Key 1 App Key 2 … App Key 16 IDA_SCROLL_UPPERLEFT IDA_SCROLL_UPPERRGHT IDA_SCROLL_LOWERLEFT IDA_SCROLL_LOWERRGHT IDA_SCROLL_CENTER IDA_SCROLL_CURSOR_CENTER IDA_SCROLL_CURSOR_VISIBLE Scroll Upper Left Scroll Upper Right Scroll Lower Left Scroll Lower Right
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC Symbolic Name Friendly Name IDA_IM_KEYBOARD IDA_IM_LOCKED IM Keyboard IM Locked Description HTML Actions IDA_URL_HOME IDA_URL_BACK IDA_URL URL Home URL Back URL Defines start of URL Special Actions IDA_VIBRATE_100 IDA_VIBRATE_200 IDA_VIBRATE_500 IDA_VIBRATE_1000 IDA_VIBRATE_2000 IDA_VIBRATE_5000 Vibrate 100ms Vibrate 200ms Vibrate 500ms Vibrate 1sec Vibrate 2sec Vibrate 5sec IDA_BEEP_OK IDA_BEEP_WARN IDA_BEEP_LOUD Beep Beep Warn Beep Loud IDA
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC Appendix 2 - Properties The properties listed in this appendix may be accessed via the GetProperty and SetProperty methods on the CETerm object. Properties marked (RO) are readonly and may not be set with SetProperty. The symbol T/F indicates a true or false value. APPLICATION PROPERTIES Property Name Description app.buildid (RO) app.name (RO) app.script.NN app.session.active (RO) app.usertext.NN app.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC Property Name device.rf.status (RO) device.serialnumber (RO) Description -1 – unknown RF status -1 – unknown, 0 – unassociated, 1 – poor, 2 – fair, 3 – good, 4 – very good, 5 – excellent Device serialnumber SESSION PROPERTIES Session properties begin with “sessionX” where X is 1 through 4. For example “session4.connection.host”. If no ‘X’ value is found, the currently active session number is used. Property Name Description sessionX.connection.
SCANNER PROPERTIES Scanner properties are unique for each session. Scanner properties begin with “sessionX.scanner” where X is 1 through 4. For example “session4.scanner.enabled”. If no ‘X’ value is found, the currently active session number is used. We use the name “scanner” for all types of barcode readers, including laser scanners and imagers. If a hardware vendor is listed, the property is specific to barcode readers made by that vendor.
COMMON SYMBOLOGY PROPERTIES Symbology properties are unique for each session. Symbology properties begin with “sessionX.scanner.SSS” where X is 1 through 4 and SSS represents a symbology name and may be 3 or more characters long. For example “session4.scanner.upca.enabled”. If no ‘X’ value is found, the currently active session number is used. See the Symbology Names table below for SSS values. NOTE: If you are changing the scanner properties for the currently activesession, you must call CETerm.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC CODABAR SYMBOLOGY PROPERTIES Codabar specific symbology properties are unique for each session. Symbology properties begin with “sessionX.scanner.codabar” where X is 1 through. For example “session4.scanner.codabar.clsiediting”. If no ‘X’ value is found, the currently active session number is used. NOTE: If you are changing the symbology properties for the currently active session, you must call “CETerm.
CODE39 SYMBOLOGY PROPERTIES Code 39 specific symbology properties are unique for each session. Symbology properties begin with “sessionX.scanner.code39” where X is 1 through. For example “session4.scanner.code39.clsiediting”. If no ‘X’ value is found, the currently active session number is used. NOTE: If you are changing the symbology properties for the currently active session, you must call “CETerm.PostIDA( “IDA_SCAN_APPLYCONFIG”, 0 ) for the changes to take effect.
CODE 128 SYMBOLOGY PROPERTIES Code 128 specific symbology properties are unique for each session. Symbology properties begin with “sessionX.scanner.code128” where X is 1 through. For example “session4.scanner.code128.ISBT”. If no ‘X’ value is found, the currently active session number is used. NOTE: If you are changing the symbology properties for the currently active session, you must call “CETerm.PostIDA( “IDA_SCAN_APPLYCONFIG”, 0 ) for the changes to take effect.
UPC-EAN GENERAL SYMBOLOGY PROPERTIES UPC-EAN general symbology properties are unique for each session. Symbology properties begin with “sessionX.scanner.upc-ean” where X is 1 through. For example “session4.scanner.upc-ean.bookland”. If no ‘X’ value is found, the currently active session number is used. NOTE: If you are changing the symbology properties for the currently active session, you must call “CETerm.PostIDA( “IDA_SCAN_APPLYCONFIG”, 0 ) for the changes to take effect.
SYMBOLOGY NAMES Symbology properties begin with “sessionX.scanner.SSS” where X is 1 through 4 and SSS represents a symbology name and may be 3 or more characters long. The following table lists all available symbology names. WARNING: Not all symbologies are applicable to all hardware. Different devices may use different names to refer to similar symbologies, e.g., upce and upce0. You should look at the symbologies available in the CETerm configuration dialogs to determine the correct name.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC Symbology Name Description maxicode mesa micropdf msi pdf pdf417 pharma39 planet plessey posicode postnet qrcode rss rss14 rssexp rsslim rssltd telepen tlc39 trioptic39 ukpostal upca upce upce0 upce1 upc-ean usplanet uspostnet usps4cb Maxicode Mesa Micro PDF MSI PDF 417 PDF 417 Pharma 39 Planet Plessey Posicode Postnet QR Code RSS 14 RSS 14 RSS Expanded RSS Limited RSS Limited Telepen TLC 39 Trioptic 39 British (UK) Postal UPC-A UPC-E UPC-E0 UPC-E1 UP
Appendix 3 – Symbology LabelTypes This appendix contains a list of symbology labeltypes that are returned in the “type” argument of OnBarcodeRead. These are also available to a ScannerNavigate META tag handler. Please note that not all hardware devices return these values. You may need to test scan a known barcode to find the labeltype value for that barcode.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC LabelType Character Hexadecimal Value @ A B C D E F G H I J K L M N 0x40 0x41 0x42 0x43 0x44 0x45 0x46 0x47 0x48 0x49 0x4A 0x4B 0x4C 0x4D 0x4E PDF 417 ISBT 128 Trioptic 39 Coupon Code Bookland Micro PDF Code 32 Macro PDF Maxicode Datamatrix QR Code Macro Micro PDF RSS-14 RSS Limited RSS Expanded V W X 0x56 0x57 0x58 Composite AB Composite C TLC 39 a b c d e f g 0x61 0x62 0x63 0x64 0x65 0x66 0x67 US Postnet US Planet UK (British) Postal Japan Po
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC Appendix 4 - Constants This appendix contains various constants that are used by CETerm Automation Objects. Many of these constants are a direct representation of the equivalent values from the Windows CE system APIs and constants. These constants are presented as JavaScript variables for direct inclusion in scripts. MESSAGEBOX CONSTANTS // MessageBox flags // See Microsoft SDK for documentation.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC var PLAYSOUND_FLAG_LOOP = 0x00000008; // Repeat play, needs ASYNC. var PLAYSOUND_FLAG_NOSTOP = 0x00000010; // Don’t stop current sound var PLAYSOUND_FLAG_NOWAIT = 0x00002000; // Don’t play if driver busy FILE ATTRIBUTE CONSTANTS // File attirbute flags // See Microsoft SDK for documentation.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC var var var var var REGISTRY_BAD_KEYNAME REGISTRY_BAD_DATATYPE REGISTRY_BAD_VALUE REGISTRY_BAD_VALUEFORMAT REGISTRY_OUTOFMEMORY = = = = = -3; -4; -5; -6; -7; BROWSER ERROR CONSTANTS // Navigate Error HRESULT status codes // See Microsoft SDK for documentation. // // URL string is not valid. var INET_E_INVALID_URL = 0x800C0002; // No session found. var INET_E_NO_SESSION = 0x800C0003; // Unable to connect to server.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC var INET_E_TERMINATED_BIND = 0x800C0018; // Permission to download is declined. var INET_E_CODE_DOWNLOAD_DECLINED = 0x800C0100; // Result is dispatched. var INET_E_RESULT_DISPATCHED = 0x800C0200; // Cannot replace a protected SFP file.
Glossary Automation Objects Objects internal to CETerm that provide access to device, application, and session features from the script engine. CEBrowseX A Naurtech ActiveX control which provides access to the CETerm Automation Objects from a Windows Mobile device. external This is the name of an internal object in the DOM of the Windows CE 5.0 browser that gives access to the CETerm Automation Objects.
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC Index A AbortScript · 22, 23 AddMetaItem · 28, 29, 42, 49 Alert · 32 B Beep · 32 Browser object · 28 C CETerm object · 22, 24, 26, 75 ClearAllTimers · 22, 23 ClearInterval · 22, 23, 25 ClearTimeout · 22, 23, 26, 51, 56 Copy · 34 CreateDirectory · 34, 35 GetInput · 31, 59 GetOpenFileName · 34, 35 GetProperty · 22, 23, 41, 43, 47, 51, 75 GetSaveFileName · 34, 35 GetText · 27, 28, 54 GetTextLine · 20, 27, 48, 49 GetTextRect · 27, 28 GetValueType · 37, 38
NAURTECH SMART CLIENTS FOR W INDOWS CE AND POCKET PC P PlaySound · 20, 22, 23, 32, 33, 51, 52, 87 PlayTone · 22, 23, 24, 32, 33, 63 PostIDA · 24 R Read · 36 ReadValue · 37, 38, 39, 62 ReadValueVBArray · 37, 39 Registry object · 34, 37, 39 RemoveDirectory · 34, 36 RunScript · 22, 24, 28, 29, 42 SendText · 16, 17, 19, 22, 24, 25, 41, 54 Session object · 25, 26, 27 SetAttributes · 34, 36 SetInterval · 22, 25 SetProperty · 25, 75 SetScriptTimeout · 26 SetTimeout · 22, 26, 51, 56, 59, 60 Sleep · 32, 33, 58, 6