StopBits 枚举

定义

指定在 SerialPort 对象上使用的停止位的数目。

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

字段

None 0

不使用停止位。 StopBits 属性不支持此值。

One 1

使用一个停止位。

OnePointFive 3

使用 1.5 个停止位。

Two 2

使用两个停止位。

示例

下面的示例演示如何将 StopBits 属性设置为 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

下面的代码示例显示枚举到控制台的 StopBits 可能值,然后提示用户选择一个。 此代码示例是为 SerialPort 类提供的大型代码示例的一部分。

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

注解

在类上SerialPort设置属性的值StopBits时,可以使用此枚举。 停止位分隔异步串行连接上每个数据单元。 当没有数据可供传输时,它们也会持续发送。

将属性设置为 StopBits None 时,类SerialPortArgumentOutOfRangeException引发异常。

适用于