FTDI Community

Please login or register.

Login with username, password and session length.
Advanced Search  

News:



Welcome to the FTDI Community!

Please read our Welcome Note

Technical Support enquires
please contact the team
@ FTDI Support


Author Topic: FTDI 232R Communication with windows C# application  (Read 1190 times)

sachin0005

  • Newbie
  • *
  • Posts: 1
    • View Profile
FTDI 232R Communication with windows C# application
« on: January 04, 2018, 04:52:56 AM »

Hi there,

I am trying to develop a windows application with C# language for communication with a device containing FTDI chip 232R UART.

I am using FTD2XX_NET class.

This class is showing that device is connected properly but i am unable to write my command and read response from it.

I tried to use C# Loop back sample code existing in FTDI website but the same code is not working for me.

I tried many times and one time i got the result but after that i am still trying and did not get any response from the device.


Please help and give sample code how to write command and read response with a FTDI device using C#.

Thanks in advance

Below is my code


public class FTDI
{
public FTDI myFtdiDevice;

public string command="?I_SCAN";

private void writecommand()
{

      ftStatus = myFtdiDevice.Write(command,command.length, ref numBytesWritten)
                if (ftStatus != FTDI.FT_STATUS.FT_OK)
                {
                    MessageBox.Show("Failed to write to device (error " + ftStatus.ToString() + ")", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return false;
                }

                numBytesAvailable = 0;

                do
                {
                    ftStatus = myFtdiDevice.GetRxBytesAvailable(ref numBytesAvailable);
                    myFtdiDevice.GetLineStatus(ref data);
                    var st = Encoding.ASCII.GetString(new byte[] { data });
                    if (ftStatus != FTDI.FT_STATUS.FT_OK)
                    {
                        MessageBox.Show("Failed to get number of bytes available to read (error " + ftStatus.ToString() + ")", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return false;
                    }
                    Thread.Sleep(16);
                } while (numBytesAvailable < FTDICommands.GETNUMBEROFSCAN.Length);
}
Logged

FTDI Community

  • Administrator
  • Full Member
  • *****
  • Posts: 154
    • View Profile
Re: FTDI 232R Communication with windows C# application
« Reply #1 on: January 05, 2018, 01:31:41 PM »

Hello,

Thanks for your question.

Can you describe the device you are implementing this code for? is it a cable? what is it trying to communicate with?

Are you implementing the Flow Control lines, I believe the loopback code example requires these.


Best Regards,

FTDI Community
Logged