Parity 列舉
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
指定 SerialPort 物件的同位位元。
public enum class Parity
C#
public enum Parity
type Parity =
Public Enum Parity
- 繼承
名稱 | 值 | Description |
---|---|---|
Even | 2 | 設定同位檢查位元,以便位元集計數為偶數。 |
Mark | 3 | 將同位檢查位元集保持為 1。 |
None | 0 | 不發生同位檢查。 |
Odd | 1 | 設定同位檢查位元,以便位元集計數為奇數。 |
Space | 4 | 將同位檢查位元集保持為 0。 |
下列程式代碼範例會顯示列舉對控制台的 Parity 可能值,然後提示使用者選擇一個。 此程式代碼範例是針對 類別提供的較大程式碼範例的 SerialPort 一部分。
static Parity SetPortParity(Parity defaultPortParity)
{
String^ parity;
Console::WriteLine("Available Parity options:");
for each (String^ s in Enum::GetNames(Parity::typeid))
{
Console::WriteLine(" {0}", s);
}
Console::Write("Enter Parity value (Default: {0}):", defaultPortParity.ToString());
parity = Console::ReadLine();
if (parity == "")
{
parity = defaultPortParity.ToString();
}
return (Parity)Enum::Parse(Parity::typeid, parity);
}
C#
// Display PortParity values and prompt user to enter a value.
public static Parity SetPortParity(Parity defaultPortParity)
{
string parity;
Console.WriteLine("Available Parity options:");
foreach (string s in Enum.GetNames(typeof(Parity)))
{
Console.WriteLine(" {0}", s);
}
Console.Write("Enter Parity value (Default: {0}):", defaultPortParity.ToString(), true);
parity = Console.ReadLine();
if (parity == "")
{
parity = defaultPortParity.ToString();
}
return (Parity)Enum.Parse(typeof(Parity), parity, true);
}
' Display PortParity values and prompt user to enter a value.
Public Shared Function SetPortParity(defaultPortParity As Parity) As Parity
Dim parity As String
Console.WriteLine("Available Parity options:")
For Each s As String In [Enum].GetNames(GetType(Parity))
Console.WriteLine(" {0}", s)
Next
Console.Write("Enter Parity value (Default: {0}):", defaultPortParity.ToString(), True)
parity = Console.ReadLine()
If parity = "" Then
parity = defaultPortParity.ToString()
End If
Return CType([Enum].Parse(GetType(Parity), parity, True), Parity)
End Function
設定序列埠連線的屬性時, Parity 請使用這個列舉。
同位是一種錯誤檢查程式,其中 1s 的數位必須一律相同,不論是偶數還是奇數,都是傳輸而沒有錯誤的每個位群組。 在數據機對數據機對數據機通訊中,同位通常是傳送方和接收方必須同意的其中一個參數,才能進行傳輸。
產品 | 版本 |
---|---|
.NET Framework | 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |