StopBits Enum
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Specifies the number of stop bits used on the SerialPort object.
public enum class StopBits
public enum StopBits
type StopBits =
Public Enum StopBits
- Inheritance
Fields
Name | Value | Description |
---|---|---|
None | 0 | No stop bits are used. This value is not supported by the StopBits property. |
One | 1 | One stop bit is used. |
Two | 2 | Two stop bits are used. |
OnePointFive | 3 | 1.5 stop bits are used. |
Examples
The following example shows how to set the StopBits property to 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
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.
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
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.
Applies to
.NET