Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

SerialPort.DataReceived Event

Represents the method that will handle the data received event of a SerialPort object.

Namespace: System.IO.Ports
Assembly: Microsoft.SPOT.Hardware (in microsoft.spot.hardware.dll)

public event SerialDataReceivedEventHandler DataReceived

Serial received events can be caused by any of the items in the SerialData enumeration. Because the operating system determines whether to raise this event or not, not all parity errors may be reported.

PinChanged, DataReceived, and ErrorReceived events may be called out of order, and there may be a slight delay between when the underlying stream reports the error and when the event handler is executed. Only one event handler can execute at a time.

The DataReceived event is not gauranteed to be raised for every byte received. Use the BytesToRead property to determine how much data is left to be read in the buffer.

The DataReceived event is raised on a secondary thread when data is received from the SerialPort object. Because this event is raised on a secondary thread, and not the main thread, attempting to modify some elements in the main thread, such as UI elements, could raise a threading exception. If it is necessary to modify elements in the main Form or Control, post change requests back using Invoke, which will do the work on the proper thread.

Available in the .NET Micro Framework versions 3.0, 4.0, and 4.1.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.