共用方式為


StopBits 列舉

定義

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

public enum class StopBits
public enum StopBits
type StopBits = 
Public Enum StopBits
繼承
StopBits

欄位

名稱 Description
None 0

不使用止點位。 這個價值並不由該 StopBits 物業支持。

One 1

使用一級位。

Two 2

使用兩個止點位。

OnePointFive 3

使用1.5個停止位。

範例

以下範例說明如何將屬性設定 StopBitsOne

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;
Dim mySerialPort As 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 的一部分。

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);
}
' Display StopBits values and prompt user to enter a value.

Public Shared Function SetPortStopBits(defaultPortStopBits As StopBits) As StopBits
    Dim stopBits As String

    Console.WriteLine("Available StopBits options:")
    For Each s As String In [Enum].GetNames(GetType(StopBits))
        Console.WriteLine("   {0}", s)
    Next

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

    If stopBits = "" Then
        stopBits = defaultPortStopBits.ToString()
    End If

    Return CType([Enum].Parse(GetType(StopBits), stopBits, True), StopBits)
End Function

備註

你在設定類別SerialPort屬性值StopBits時會使用這個列舉。 停止位元在非同步串列連線中分隔每個資料單位。 當沒有資料可供傳輸時,這些訊息也會持續傳送。

當你將屬性設StopBits為 None 時,類別SerialPortArgumentOutOfRangeException拋出例外。

適用於