SerialPort.ErrorReceived 事件

定義

表示在 SerialPort 物件所代表的連接埠上已發生錯誤。Indicates that an error has occurred with a port represented by a SerialPort object.

public:
 event System::IO::Ports::SerialErrorReceivedEventHandler ^ ErrorReceived;
public event System.IO.Ports.SerialErrorReceivedEventHandler ErrorReceived;
member this.ErrorReceived : System.IO.Ports.SerialErrorReceivedEventHandler 
Public Custom Event ErrorReceived As SerialErrorReceivedEventHandler 
Public Event ErrorReceived As SerialErrorReceivedEventHandler 

事件類型

SerialErrorReceivedEventHandler

備註

錯誤事件可能是列舉中的任何專案所造成 SerialErrorError events can be caused by any of the items in the SerialError enumeration. 因為作業系統會決定是否要引發此事件,所以不會報告所有的同位檢查錯誤。Because the operating system determines whether to raise this event or not, not all parity errors may be reported.

PinChangedDataReceivedErrorReceived 事件可能會依序呼叫,而且當基礎資料流程報告錯誤時,以及當執行事件處理常式時,可能會有稍微延遲的時間。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 code can when the event handler is executed. 一次只能執行一個事件處理常式。Only one event handler can execute at a time.

如果資料流程的尾端位元組發生同位錯誤,則會將額外的位元組新增至輸入緩衝區,並將其值設為126。If a parity error occurs on the trailing byte of a stream, an extra byte will be added to the input buffer with a value of 126.

ErrorReceived從物件接收到錯誤時,會在次要執行緒上引發事件 SerialPortThe ErrorReceived event is raised on a secondary thread when an error is received from the SerialPort object. 因為這個事件是在次要執行緒上引發,而不是在主執行緒上引發,所以嘗試修改主執行緒中的某些元素(例如 UI 元素)可能會引發執行緒例外狀況。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. 如果需要修改 main 或中的元素 Form Control ,請使用 post 變更要求 Invoke ,這會在適當的執行緒上執行工作。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.

如需處理事件的詳細資訊,請參閱 處理和引發事件For more information about handling events, see Handling and Raising Events.

適用於