4 running an external program, 5 using timers to run scripts – Casio Naurtech CETerm Ver.5.5 Scripting Guide User Manual
Page 109
N
AURTECH
W
EB
B
ROWSER AND
T
ERMINAL
E
MULATION FOR
W
INDOWS
CE
AND
W
INDOWS
M
OBILE
CETerm Scripting Guide
Page 109
5.4
R
UNNING AN
E
XTERNAL
P
ROGRAM
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. Often you will
run a program then return to CETerm when it exits. The Process object allows
you to manage running processes. The Event object can be used to schedule a
script to run when a process exits.
Here is an example to start the stylus calibration. Note that the arguments
depend on whether your device is Window CE or Windows Mobile.
/* Stylus Calibration */
// TODO: Uncomment the lines for your device
// For Windows CE 5.0 devices
OS.Process.ExecuteAction ( "\\Windows\\ctlpnl.exe",
"cplmain.cpl,9,1", "open" );
// For Windows Mobile 5 devices
//OS.Process.ExecuteAction ( "\\Windows\\ctlpnl.exe",
// "cplmain.cpl,7,0", "open" );
5.5
U
SING
T
IMERS TO
R
UN
S
CRIPTS
Script execution timers are useful for several tasks. They can be used to:
1. Defer an action which is not possible in an event handler.
2. Perform an action periodically.
3. Provide an asynchronous script execution.
4. Split up a long running task.
We have already shown how the timer is used with the ExpectMonitor class and
task automation in Section 5.1. Event handlers should be limited to a small
amount of processing. If more processing is needed, it is best to schedule that
processing with SetTimeout() and allow the event handler to exit.
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/ ))