Parity 列舉

定義

指定 SerialPort 物件的同位位元。

public enum class Parity
public enum Parity
type Parity = 
Public Enum Parity
繼承

欄位

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);
}
// 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 的數目必須一律相同,不論是偶數還是奇數,都會是傳輸而沒有錯誤的每一組位。 在數據機對數據機通訊中,同位通常是傳送方和接收者必須同意的其中一個參數,才能進行傳輸。

適用於