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);
}