Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I use two FT232RL (FTDI) USB to Serial adapters to utilize UART communication with RTS/CTS flow control between 2 PCs. My hardware configuration: TX<-->RX; RX<-->TX; CTS<-->RTS; RTS<-->CTS; GND<-->GND.

I enable RTS signal of one adapter and want to get the CTS state of the other adapter. I used SerialDevice.PinChanged event to catch this change. My app in computer B calls PinChanged handler whenever I enable/disable RTS signal of computer A and I could verify that CTS signal of computer B is changed (by checking the value of PinChangedEventArgs.PinChange). However, the value of SerialDevice.ClearToSendState is always false. Therefore, I could not determine whether other device(computer B) is ready to receive data or not.

I used following code to configure serial device and handle event:
C#
private async void ConnectDevice(string entryId)
{
    try
    {
        // serialPort is a private variable of MainPage
        serialPort = await SerialDevice.FromIdAsync(entryId);

        // Configure serial settings
        serialPort.WriteTimeout = TimeSpan.FromMilliseconds(1000);
        serialPort.ReadTimeout = TimeSpan.FromMilliseconds(1000);
        serialPort.BaudRate = 9600;
        serialPort.Parity = SerialParity.None;
        serialPort.StopBits = SerialStopBitCount.One;
        serialPort.DataBits = 8;
        serialPort.Handshake = SerialHandshake.RequestToSend;
        serialPort.PinChanged += SerialPort_PinChanged;

        // Listien to incomming data
        Listen();
    }
    catch (Exception ex)
    {
        status.Text = ex.Message;
    }
}

private async void SerialPort_PinChanged(SerialDevice sender, PinChangedEventArgs args)
{
    switch (args.PinChange)
    {
        case SerialPinChange.ClearToSend:
            // If device is ready, write data
            if (serialPort.ClearToSendState)
                await WriteAsync();
            break;
        default:
            break;
    }
}


Is my implementation correct? How could I use RTS/CTS flow control in a UWP app?

What I have tried:

I tried to set SerialDevice.Handshake as SerialHandshake.None and use another type of adapter. But it still does not work.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900