2010-10-19 49 views

回答

1

對於SerialPort類,即Baudrate = 2400,Parity = None,DataBits = 8,StopBits = One。只有波特率具有非默認設置。

+0

奇怪的downvote。任何事實上這個答案都是錯誤的,愛聽聽它可能是什麼。 – 2010-10-19 22:13:33

+0

奇偶校驗=無,StopBits = 1 ...這是事實錯誤。應該是奇偶校驗= Parity.None和StopBits = StopBits.One,這個以及你沒有提供直接引用SerialPort類的任何信息的事實,除了最寬鬆的條款之外。 OP要求C#... – ocodo 2010-10-19 22:26:44

+0

感謝您的反饋@slo,當然有一個隱含的假設,OP將使用設計器來設置這些屬性。屬性窗口對於那些尚未掌握將設置字符串轉換爲代碼的技巧的程序員來說非常方便。當然,它不會打擾枚舉類型。很明顯,OP對答案很滿意,不太確定是否有理由不同意這一點。在您發佈的線索中對答案進行降壓也是相當有效的。你的回答應該獨立,無需操縱。它看起來並不需要幫助。 – 2010-10-19 22:44:35

5

使用下面的例子...:

您將需要此using

using System.IO.Ports; 

並在代碼...

SerialPort comPort = new SerialPort("port", 2400, Parity.None, 8, StopBits.One); 
// This is one of 7 possible method overloads. 

您還可以更改的設置SerialPort實例使用這些屬性。

comPort.PortName = "port"; //PortName (string) 
comPort.DataBits = 8; //DataBits (int) 5..8 

comPort.BaudRate = 2400; //BaudRate (int) 
        // Default is 9600, can be up to the maximum permitted by the hardware. 

comPort.StopBits = StopBits.One; //StopBits 
        // (StopBits.One, StopBits.None, StopBits.None, StopBits.Two, StopBits.OnePointFive) 

comPort.Parity = Parity.None; //Parity 
       // (Parity.Odd, Parity.Even, Parity.None, Parity.Mark, Parity.Space)