Casio Naurtech CETerm Ver.5.5 Scripting Guide User Manual
Page 116
N
AURTECH
W
EB
B
ROWSER AND
T
ERMINAL
E
MULATION FOR
W
INDOWS
CE
AND
W
INDOWS
M
OBILE
CETerm Scripting Guide
Page 116
You must also define an OnSerialPortEvent handler that will be called when
the event occurs. Here is a sample handler:
// Serial port event handler
function OnSerialPortEvent( portIndex, eventMask )
{
if (portIndex === 5)
{
if (eventMask & EV_RXCHAR)
{
// Data is available, read and process
MyReadAndProcess( portIndex );
}
if (eventMask & EV_DSR)
{
// DSR state changed. Device entered sleep
MyCloseAndReopen( portIndex );
}
}
else if (portIndex === 3)
{
// Do something different for port 3
DoPort3Actions( eventMask );
}
}
This sample is just a template. It shows that there is only one
OnSerialPortEvent handler for all serial ports, and that you must further
direct the event to your own processing routines depending on the port signaling
the event. The event handler may be very complex. Some rich examples are
available on our website or through Naurtech Support.
After your handler is defined and the port opened, you call
SerialPort.WaitForEvent when you are ready to handle events. This
enables an event listener for the port. If the event is signaled by the port, the
event handler OnSerialPortEvent is invoked. The event handler is invoked
only once for each call of WaitForEvent, but the handler parameters may
indicate multiple event conditions. Within the OnSerialPortEvent handler, or
other helper routines, a common pattern is to schedule the next
SerialPort.WaitForEvent. Although they share a common handler
function, you must call WaitForEvent separately for each port, each time you
want to enable events for that port.
To cancel an active event listener use SerialPort.CancelWaitForEvent.