SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 46 | Next

Jan Axelson

"Serial Port Complete: COM Ports, USB Virtual COM Ports, and Ports for Embedded Systems"

There are two ways for program code to
detect these events.
One way is to jump to a routine when an event occurs. The code responds
quickly to port activity without having to waste time checking only to learn
that no activity has occurred. This type of programming is called event driven
because an external event can break in at any time and cause the program??™s execution
to branch to a routine to handle the event.
The .NET Framework??™s SerialPort class includes the DataReceived, Pin-
Changed, and ErrorReceived events. Handler routines can execute when a software
buffer??™s count reaches a trigger value, when the state of a flow-control or
status pin changes, and when an error or timeout occurs. Many microcontrollers
have hardware interrupts that can perform similar functions.
The other approach to detecting events is to poll the port by periodically reading
properties, signal states, or registers to find out if an event has occurred.
This type of programming doesn??™t use a port??™s hardware interrupts. The code
has to poll often enough to detect all data and events in time to prevent lost dat
or other problems. The needed frequency of polling depends on buffer size, the
amount of data expected, and whether the code must respond quickly to events.
For example, a device that has a 16-byte buffer and polls the port once per second
can receive no more than 16 bytes per second or the buffer might overflow
and data will be lost.


Pages:
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58