Skip to main content
.NET Framework Class Library
StopBits Enumeration

Updated: August 2010

Specifies the number of stop bits used on the SerialPort object.

Namespace: System.IO.Ports
Assembly: System (in System.dll)
Syntax
Public Enumeration StopBits
public enum StopBits
public enum class StopBits
type StopBits
Members
Member nameDescription
NoneNo stop bits are used. This value is not supported by the StopBits property.
OneOne stop bit is used.
TwoTwo stop bits are used.
OnePointFive1.5 stop bits are used.
Remarks

You use this enumeration when setting the value of the StopBits property on the SerialPort class. Stop bits separate each unit of data on an asynchronous serial connection. They are also sent continuously when no data is available for transmission.

The SerialPort class throws an ArgumentOutOfRangeException exception when you set the StopBits property to None.

Examples

The following example shows how to set the StopBits property to One.


Dim mySerialPort As New SerialPort("COM1")

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


SerialPort mySerialPort = new SerialPort("COM1");

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


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

mySerialPort->BaudRate = 9600;
mySerialPort->Parity = Parity::None;
mySerialPort->StopBits = StopBits::One;
mySerialPort->DataBits = 8;
mySerialPort->Handshake = Handshake::None;

The following code example displays the possible values of the StopBits enumeration to the console, then prompts the user to choose one. This code example is part of a larger code example provided for the SerialPort class.


Public Shared Function SetPortStopBits(ByVal defaultPortStopBits As StopBits) As StopBits
    Dim newStopBits As String

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

    Console.Write("Stop Bits({0}):", defaultPortStopBits.ToString())
    newStopBits = Console.ReadLine()

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

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


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

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

    Console.Write("Stop Bits({0}):", defaultPortStopBits.ToString());
    stopBits = Console.ReadLine();

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

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


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("Stop Bits({0}):", defaultPortStopBits.ToString());
    stopBits = Console::ReadLine();

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

    return (StopBits)Enum::Parse(StopBits::typeid, stopBits);
}

Version Information

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Platforms

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Change History

Date

History

Reason

August 2010

Added example that shows how to set the StopBits property; corrected information about supported members.

Customer feedback.