Casio Naurtech CETerm Ver.5.5 Scripting Guide User Manual

Page 115

Advertising
background image

N

AURTECH

W

EB

B

ROWSER AND

T

ERMINAL

E

MULATION FOR

W

INDOWS

CE

AND

W

INDOWS

M

OBILE




CETerm Scripting Guide

Page 115


var sp = Device.SerialPort( portIndex );

// Port configuration
sp.EventMask = EV_RXCHAR | EV_DSR;

sp.XOFFOutputFlowControl = false;
sp.XOFFInputFlowControl = false;

// See Appendix 4 for contants
sp.BaudRate = CBR_9600;
sp.DataBits = 8;
sp.StopBits = ONESTOPBIT;
sp.ParityMode = NOPARITY;

// Set read timeouts
sp.ReadTotalTimeoutConstant = 100;
sp.ReadIntervalTimeout = 50;
sp.ReadTotalTimeoutMultiplier = 10;

// Set write timeouts
sp.WriteTotalTimeoutConstant = 100;
sp.WriteTotalTimeoutMultiplier = 0;

// Open port
return sp.Open( GENERIC_READ | GENERIC_WRITE );
}


5.8.4 Using WaitForEvent to Detect Data and State Changes

Section 4.0 describes why scripts cannot run continuously within CETerm. While
a script is blocking on a SerialPort.Read command waiting for data, CETerm
cannot respond to user input or perform other actions. Because of this, you must
keep read timeouts short to maintain a responsive program. Although you could
“poll” the serial port frequently to read newly arrived data, this is an inefficient
technique. The better technique is to use the SerialPort.WaitForEvent
method to run an event handler when data arrives or other states change.

To use WaitForEvent, you first configure the types of events you want to
detect. These are set as flag values in the EventMask property. For example,
to report events for the arrival of data and a change of the DSR state you would
use

var portIndex = 5;
var sp = Device.SerialPort( portIndex );
sp.EventMask = EV_RXCHAR | EV_DSR; // See Appendix 4

Advertising
This manual is related to the following products: