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


New Bridgetek Community is now open

Please note that we have created the Bridgetek Community to discuss all Bridgetek products e.g. EVE, MCU.

Please follow this link and create a new user account to get started.

Bridgetek Community

Author Topic: FTDI 232R Communication with windows C# application  (Read 1956 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
  • Sr. Member
  • *****
  • Posts: 255
    • 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

tomg

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: FTDI 232R Communication with windows C# application
« Reply #2 on: January 31, 2019, 07:06:42 PM »

sachin0005,

I use the FTD2XX_NET library with .NET 4.5.2 and use the Write() and GetRxBytesAvailable() functions without problem.

Apologies, but a basic question up front.  Have you opened the FTDI device?   Your example code does not indicate that you have.

            UInt32 numDevs = 0;
            FTDI.FT_STATUS ftStatus = ftdi.GetNumberOfDevices(ref numDevs);
            FTDI.FT_DEVICE_INFO_NODE[] deviceList = new FTDI.FT_DEVICE_INFO_NODE[numDevs];
            ftStatus = ftdi.GetDeviceList(deviceList);
            foreach (FTDI.FT_DEVICE_INFO_NODE node in deviceList)
            {
                    ftStatus = ftdi.OpenByDescription(node.Description);
                    string comPort;
                    ftStatus = ftdi.GetCOMPort(out comPort);

                    //.....
             }
???
tom
Logged