Serial Port Complete - Latest Microcontroller projects

(lily) #1

Chapter 12


 internal void DataReceived( object sender, SerialDataReceivedEventArgs e )
{
string newReceivedData = null;


newReceivedData = SelectedPort.ReadExisting();

if ( acceptData )
{
// The received address matches our address.
}
}
Using events to detect received data and addresses assumes that the events are
raised in the order they occur. However, .NET doesn’t guarantee that the
DataReceived and ErrorReceived events will fire in order. For example, if the
transmitting computer sends an address immediately followed by data, the
DataReceived event might fire before the ErrorReceived event and cause the
receiving computer to think the data is for a different address. To prevent prob-
lems, the transmitting computer can insert a delay either before or after chang-
ing parity. The delay allows time for the receiving computer to process an
address before the data arrives and time to process received data before another
address arrives.
To simplify the programming, a primary/secondary network can use the address
bit only when the primary node transmits to a secondary node. If the secondary
nodes transmit only in response to received communications, the primary node
can assume that any incoming data is from the node most recently addressed.
The other secondary nodes ignore data sent by the other secondary nodes
because a matching address wasn’t detected.
Free download pdf