StopBits Wyliczenie

Definicja

Określa liczbę bitów zatrzymania używanych w SerialPort obiekcie.

public enum class StopBits
public enum StopBits
type StopBits = 
Public Enum StopBits
Dziedziczenie
StopBits

Pola

None 0

Nie są używane żadne bity zatrzymania. Ta wartość nie jest obsługiwana StopBits przez właściwość .

One 1

Używany jest jeden bit zatrzymania.

OnePointFive 3

Używane są bity zatrzymania 1.5.

Two 2

Używane są dwa bity zatrzymania.

Przykłady

W poniższym przykładzie pokazano, jak ustawić StopBits właściwość na One.

SerialPort^ mySerialPort = gcnew SerialPort("COM1");

mySerialPort->BaudRate = 9600;
mySerialPort->Parity = Parity::None;
mySerialPort->StopBits = StopBits::One;
mySerialPort->DataBits = 8;
mySerialPort->Handshake = Handshake::None;
mySerialPort->RtsEnable = true;
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

Poniższy przykład kodu wyświetla możliwe wartości StopBits wyliczenia do konsoli, a następnie monituje użytkownika o wybranie go. Ten przykład kodu jest częścią większego przykładu kodu udostępnionego SerialPort dla klasy.

static StopBits SetPortStopBits(StopBits defaultPortStopBits)
{
    String^ stopBits;

    Console::WriteLine("Available Stop Bits options:");
    for each (String^ s in Enum::GetNames(StopBits::typeid))
    {
        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(StopBits::typeid, stopBits);
}
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

Uwagi

To wyliczenie jest używane podczas ustawiania wartości StopBits właściwości w SerialPort klasie. Zatrzymaj bity oddzielają każdą jednostkę danych w asynchronicznym połączeniu szeregowym. Są one również wysyłane stale, gdy żadne dane nie są dostępne do transmisji.

Klasa SerialPort zgłasza ArgumentOutOfRangeException wyjątek podczas ustawiania StopBits właściwości na None.

Dotyczy