閱讀英文版本

分享方式:


StopBits 列舉

定義

指定在 SerialPort 物件上使用的停止位元數目。

C#
public enum StopBits
繼承
StopBits

欄位

名稱 Description
None 0

未使用停止位元。 StopBits 屬性不支援這個值。

One 1

使用一個停止位元。

OnePointFive 3

使用 1.5 個停止位元。

Two 2

使用兩個停止位元。

範例

下列範例示範如何將 屬性設定 StopBitsOne

C#
SerialPort mySerialPort = new SerialPort("COM1");

mySerialPort.BaudRate = 9600;
mySerialPort.Parity = Parity.None;
mySerialPort.StopBits = StopBits.One;
mySerialPort.DataBits = 8;
mySerialPort.Handshake = Handshake.None;
mySerialPort.RtsEnable = true;

下列程式代碼範例會顯示主控台列舉的 StopBits 可能值,然後提示使用者選擇一個。 此程式代碼範例是提供給 類別之較大程式碼範例的 SerialPort 一部分。

C#
public static StopBits SetPortStopBits(StopBits defaultPortStopBits)
{
    string stopBits;

    Console.WriteLine("Available StopBits options:");
    foreach (string s in Enum.GetNames(typeof(StopBits)))
    {
        Console.WriteLine("   {0}", s);
    }

    Console.Write("Enter StopBits value (None is not supported and \n" +
     "raises an ArgumentOutOfRangeException. \n (Default: {0}):", defaultPortStopBits.ToString());
    stopBits = Console.ReadLine();

    if (stopBits == "" )
    {
        stopBits = defaultPortStopBits.ToString();
    }

    return (StopBits)Enum.Parse(typeof(StopBits), stopBits, true);
}

備註

在類別上SerialPort設定 屬性的值StopBits時,您可以使用這個列舉。 停止位會分隔異步序列連接上每個數據單位。 當沒有數據可供傳輸時,它們也會持續傳送。

當您將 StopBits 屬性設定為 None 時,類別SerialPortArgumentOutOfRangeException擲回例外狀況。

適用於

產品 版本
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1