SerialPort.Handshake Propiedad

Definición

Obtiene o establece el protocolo de enlace para la transmisión de datos a través del puerto serie desde Handshake.

public:
 property System::IO::Ports::Handshake Handshake { System::IO::Ports::Handshake get(); void set(System::IO::Ports::Handshake value); };
public System.IO.Ports.Handshake Handshake { get; set; }
[System.ComponentModel.Browsable(true)]
public System.IO.Ports.Handshake Handshake { get; set; }
member this.Handshake : System.IO.Ports.Handshake with get, set
[<System.ComponentModel.Browsable(true)>]
member this.Handshake : System.IO.Ports.Handshake with get, set
Public Property Handshake As Handshake

Valor de propiedad

Handshake

Uno de los valores de Handshake. De manera predeterminada, es None.

Atributos

Excepciones

El puerto tiene un estado no válido.

o bien Se ha producido un error al intentar establecer el estado del puerto subyacente. Por ejemplo, los parámetros que se han pasado desde este objeto SerialPort no eran válidos.

El valor pasado no es un valor válido de la enumeración Handshake.

Ejemplos

En el ejemplo de código siguiente se muestra el uso de la SerialPort clase para permitir que dos usuarios chateen desde dos equipos independientes conectados por un cable de módem nulo. En este ejemplo, se solicita a los usuarios la configuración del puerto y un nombre de usuario antes de chatear. Este ejemplo de código forma parte de un ejemplo de código más grande proporcionado para la SerialPort clase .

public:
    static void Main()
    {
        String^ name;
        String^ message;
        StringComparer^ stringComparer = StringComparer::OrdinalIgnoreCase;
        Thread^ readThread = gcnew Thread(gcnew ThreadStart(PortChat::Read));

        // Create a new SerialPort object with default settings.
        _serialPort = gcnew SerialPort();

        // Allow the user to set the appropriate properties.
        _serialPort->PortName = SetPortName(_serialPort->PortName);
        _serialPort->BaudRate = SetPortBaudRate(_serialPort->BaudRate);
        _serialPort->Parity = SetPortParity(_serialPort->Parity);
        _serialPort->DataBits = SetPortDataBits(_serialPort->DataBits);
        _serialPort->StopBits = SetPortStopBits(_serialPort->StopBits);
        _serialPort->Handshake = SetPortHandshake(_serialPort->Handshake);

        // Set the read/write timeouts
        _serialPort->ReadTimeout = 500;
        _serialPort->WriteTimeout = 500;

        _serialPort->Open();
        _continue = true;
        readThread->Start();

        Console::Write("Name: ");
        name = Console::ReadLine();

        Console::WriteLine("Type QUIT to exit");

        while (_continue)
        {
            message = Console::ReadLine();

            if (stringComparer->Equals("quit", message))
            {
                _continue = false;
            }
            else
            {
                _serialPort->WriteLine(
                    String::Format("<{0}>: {1}", name, message) );
            }
        }

        readThread->Join();
        _serialPort->Close();
    }

    static void Read()
    {
        while (_continue)
        {
            try
            {
                String^ message = _serialPort->ReadLine();
                Console::WriteLine(message);
            }
            catch (TimeoutException ^) { }
        }
    }
public static void Main()
{
    string name;
    string message;
    StringComparer stringComparer = StringComparer.OrdinalIgnoreCase;
    Thread readThread = new Thread(Read);

    // Create a new SerialPort object with default settings.
    _serialPort = new SerialPort();

    // Allow the user to set the appropriate properties.
    _serialPort.PortName = SetPortName(_serialPort.PortName);
    _serialPort.BaudRate = SetPortBaudRate(_serialPort.BaudRate);
    _serialPort.Parity = SetPortParity(_serialPort.Parity);
    _serialPort.DataBits = SetPortDataBits(_serialPort.DataBits);
    _serialPort.StopBits = SetPortStopBits(_serialPort.StopBits);
    _serialPort.Handshake = SetPortHandshake(_serialPort.Handshake);

    // Set the read/write timeouts
    _serialPort.ReadTimeout = 500;
    _serialPort.WriteTimeout = 500;

    _serialPort.Open();
    _continue = true;
    readThread.Start();

    Console.Write("Name: ");
    name = Console.ReadLine();

    Console.WriteLine("Type QUIT to exit");

    while (_continue)
    {
        message = Console.ReadLine();

        if (stringComparer.Equals("quit", message))
        {
            _continue = false;
        }
        else
        {
            _serialPort.WriteLine(
                String.Format("<{0}>: {1}", name, message));
        }
    }

    readThread.Join();
    _serialPort.Close();
}

public static void Read()
{
    while (_continue)
    {
        try
        {
            string message = _serialPort.ReadLine();
            Console.WriteLine(message);
        }
        catch (TimeoutException) { }
    }
}
Public Shared Sub Main()
    Dim name As String
    Dim message As String
    Dim stringComparer__1 As StringComparer = StringComparer.OrdinalIgnoreCase
    Dim readThread As New Thread(AddressOf Read)

    ' Create a new SerialPort object with default settings.
    _serialPort = New SerialPort()

    ' Allow the user to set the appropriate properties.
    _serialPort.PortName = SetPortName(_serialPort.PortName)
    _serialPort.BaudRate = SetPortBaudRate(_serialPort.BaudRate)
    _serialPort.Parity = SetPortParity(_serialPort.Parity)
    _serialPort.DataBits = SetPortDataBits(_serialPort.DataBits)
    _serialPort.StopBits = SetPortStopBits(_serialPort.StopBits)
    _serialPort.Handshake = SetPortHandshake(_serialPort.Handshake)

    ' Set the read/write timeouts
    _serialPort.ReadTimeout = 500
    _serialPort.WriteTimeout = 500

    _serialPort.Open()
    _continue = True
    readThread.Start()

    Console.Write("Name: ")
    name = Console.ReadLine()

    Console.WriteLine("Type QUIT to exit")

    While _continue
        message = Console.ReadLine()

        If stringComparer__1.Equals("quit", message) Then
            _continue = False
        Else
            _serialPort.WriteLine([String].Format("<{0}>: {1}", name, message))
        End If
    End While

    readThread.Join()
    _serialPort.Close()
End Sub

Public Shared Sub Read()
    While _continue
        Try
            Dim message As String = _serialPort.ReadLine()
            Console.WriteLine(message)
        Catch generatedExceptionName As TimeoutException
        End Try
    End While
End Sub

Comentarios

Cuando se usa el protocolo de enlace, se indica al dispositivo conectado al SerialPort objeto que detenga el envío de datos cuando haya al menos (ReadBufferSize-1024) bytes en el búfer. Se indica al dispositivo que vuelva a enviar datos cuando haya 1024 o menos bytes en el búfer. Si el dispositivo envía datos en bloques que tienen más de 1024 bytes, esto puede provocar que el búfer se desborde.

Si la Handshake propiedad se establece RequestToSendXOnXOff en y CtsHolding se establece falseen , no se enviará el carácter XOff. Si CtsHolding se establece trueen , se deben enviar más datos antes de que se envíe el carácter XOff.

Se aplica a