基本屬性:
serialPort.PortName //可用的COM端口號serialPort.BaudRate //波特率
serialPort.DataBits //數據位
serialPort.StopBits //停止位
serialPort.Parity //奇偶校驗
serialPort.BytesToRead //獲取接收緩衝區的字節數
serialPort.BytesToWrite //獲取發送緩衝區的字節數
常用的方法:
DiscardInBuffer //丟棄接收緩存區的內容
DiscardOutBuffer //丟棄發送緩衝區的內容
Open //打開串口
read //從輸入緩衝區讀取
write(string) //將制定的字符串寫入串行端口
常用事件:
DataReceived //數據接收事件的方法
從 serialPort 對象接收數據時,將在輔助線程上引發DataReceived 事件,只要接收緩衝區有數據就觸發。