Casio Naurtech CETerm Ver.5.5 Scripting Guide Bedienungsanleitung Seite 117

  • Herunterladen
  • Zu meinen Handbüchern hinzufügen
  • Drucken
  • Seite
    / 164
  • Inhaltsverzeichnis
  • LESEZEICHEN
  • Bewertet. / 5. Basierend auf Kundenbewertungen
Seitenansicht 116
NAURTECH WEB BROWSER AND TERMINAL EMULATION FOR WINDOWS CE AND WINDOWS MOBILE
CETerm Scripting Guide Page 117
5.8.5 Using Single Byte Reads
One pattern which often works well for handling serial port data is to read a
single byte at a time and to accumulate data until a “complete message” can be
processed. Your application and peripheral device will define what a “complete
message” contains, but often messages are terminated by special characters
such as ASCII ETX. When using single-byte reads, you can keep read timeouts
short and optimize responsiveness.
To use this pattern, you would use WaitForEvent with the EV_RXCHAR event
and process the data within your handler. Here is a template for a single byte
read handler
// Serial port data handler
var responseData = [];
var responseState = "PRE_STX";
function MyReadAndProcess( portIndex )
{
var c;
var readTries = 4;
var sp = Device.SerialPort( portIndex );
while (responseState !== "DONE" &&
readTries > 0)
{
c=sp.ReadByte();
if (c < 0)
{
// Read error, try again
OS.Sleep( 20 );
--readTries;
continue;
}
// Reset tries after successful read
readTries = 4;
switch(c)
{
case ASCII_STX:
// Start of response.
responseState = "DATA";
responseData = [];
break;
case ASCII_ETX:
// End of content
responseState = "DONE";
break;
Seitenansicht 116
1 2 ... 112 113 114 115 116 117 118 119 120 121 122 ... 163 164

Kommentare zu diesen Handbüchern

Keine Kommentare