Serial Port Complete - Latest Microcontroller projects

(lily) #1
Network Programming

 internal bool acceptData;
internal int myAddress = (int)'h';


private void ErrorReceived( object sender, SerialErrorReceivedEventArgs e )
{

SerialError SerialErrorReceived1 = 0;
SerialErrorReceived1 = e.EventType;

switch ( SerialErrorReceived1 )
{
case SerialError.RXParity:

if ( ( SelectedPort.ReadChar() == myAddress ) )
{
acceptData = true;
}
else
{
acceptData = false;
}
break;
}
}
A DataReceived event can check the state of acceptData before deciding what
to do with new received data. Chapter 10 showed how to assign a method to
the DataReceived event.

 Friend Sub DataReceived _
(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs)


Dim newReceivedData As String

newReceivedData = selectedPort.ReadExisting

If acceptData Then

' The received address matches our address.

End If

End Sub
Free download pdf