locked
fOutxCtsFlow in SerialPort class RRS feed

  • Question

  • I am porting a Win32 application to .NET, and I am having difficulty replacing the functionality of the fOutxCtsFlow member of the DCB structure.  My connected device disables CTS when its buffers begin to fill, and the PC needs to stop transmitting.  I have tried setting the Handshake member of the serial port object to Handshake.RequestToSend, but the serial port object continues to write bytes after CTS goes inactive.  I would hate to have to poll the CtsHolding property while calling the Write method.  What is the proper way to enforce CTS flow control on the outgoing data stream?
    Monday, March 20, 2006 2:49 PM

Answers

  • Setting SerialPort.Handshake to Handshake.RequestToSend or Handshake.RequestToSendXOnXOff will set fOUtxCtsFlow and will cause Write methods to block after CTS goes inactive. I wrote the following sample to demonstrate this. This sample assumes that there is a null modem cable between COM1 and COM2:

    public static void Main()
    {
        SerialPort com1 = new SerialPort("COM1");
        SerialPort com2 = new SerialPort("COM2");

        com1.Open();
        com2.Open();

        com1.Handshake = Handshake.RequestToSend;
        com1.WriteTimeout = 1000;

        com2.RtsEnable = true;
        com1.WriteLine("Hello");

        com2.RtsEnable = false;
        try {
            com1.WriteLine("World");
            Console.WriteLine("ERROR: Write method should have timed out.");
        }
        catch(TimeoutException) { }

        com1.Close();
        com2.Close();
    }

    Ryan Byington [MS]

    Tuesday, April 18, 2006 5:43 PM