StopBits Výčet

Definice

Určuje počet bitů zastavení použitých u objektu SerialPort .

public enum class StopBits
public enum StopBits
type StopBits = 
Public Enum StopBits
Dědičnost
StopBits

Pole

None 0

Nepoužívají se žádné zarážky. Vlastnost tuto hodnotu nepodporuje StopBits .

One 1

Používá se jeden zarážka.

OnePointFive 3

Používá se 1,5 zarážky.

Two 2

Používají se dva zarážky.

Příklady

Následující příklad ukazuje, jak nastavit StopBits vlastnost 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

Následující příklad kódu zobrazí možné hodnoty výčtu StopBits konzoly a pak vyzve uživatele k výběru. Tento příklad kódu je součástí většího příkladu kódu, který je k dispozici pro SerialPort třídu.

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

Poznámky

Tento výčet použijete při nastavení hodnoty StopBits vlastnosti ve SerialPort třídě. Stop bity oddělují každou jednotku dat v asynchronním sériovém připojení. Odesílají se také nepřetržitě, když nejsou k dispozici žádná data pro přenos.

Třída SerialPort vyvolá ArgumentOutOfRangeException výjimku, když nastavíte StopBits vlastnost None.

Platí pro