Click here to Skip to main content
15,509,916 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am trying to read the sd card data which is connected to renesas microcintroller. microcontroller is serially connected with FT232RL module. i am using c# apps to read the data but the data is not received in application.
i need help!

What I have tried:

//connect button
 private void Button1_Click(object sender, EventArgs e)
        {
            
           

            if (ftStatus == FTDI.FT_STATUS.FT_OK)
            {
               
                commentbox.Text = "Number of FTDI devices: " + ftdiDeviceCount;
            }
            else
            {
                // Wait for a key press
               
                commentbox.Text = "Failed to get number of devices error " + ftStatus;
                return;
            }

            if (ftdiDeviceCount == 0)
            {
                // Wait for a key press
              
                commentbox.Text = "Failed to get number of devices error " + ftStatus;
                return;
            }
            FTDI.FT_DEVICE_INFO_NODE[] ftdiDeviceList = new FTDI.FT_DEVICE_INFO_NODE[ftdiDeviceCount];

            // Populate our device list
            ftStatus = myFtdiDevice.GetDeviceList(ftdiDeviceList);

            if (ftStatus == FTDI.FT_STATUS.FT_OK)
            {
                for (UInt32 i = 0; i < ftdiDeviceCount; i++)
                {

                    richTextBox1.Text = "Device Index: " + i.ToString() + "\n" + "Flags: " + String.Format("{0:x}", ftdiDeviceList[i].Flags) + "\n" + "Type: "
                        + ftdiDeviceList[i].Type.ToString() + "\n" + "ID: " + String.Format("{0:x}", ftdiDeviceList[i].ID) + "\n" + "Location ID: " + String.Format("{0:x}", ftdiDeviceList[i].LocId) + "\n"
                        + "Serial Number: " + ftdiDeviceList[i].SerialNumber.ToString() + "\n" + "Description: " + ftdiDeviceList[i].Description.ToString() 
                       /* + "Serial Port: " + comstr*/;
                        

                }
            }
            ftStatus = myFtdiDevice.OpenBySerialNumber(ftdiDeviceList[0].SerialNumber);
            if (ftStatus != FTDI.FT_STATUS.FT_OK)
            {
                // Wait for a key press
                //Console.WriteLine("Failed to open device (error " + ftStatus.ToString() + ")");
                //Console.ReadKey();
                commentbox.Text = "Failed to open device error " + ftStatus;

                return;
            }
         
            myFtdiDevice.GetCOMPort(out comstr);
            //listBox3.Items.Add("Com Port: " + comstr);
           // ftStatus = myFtdiDevice.Close();
            comboBox1.Text =  comstr;
         
            // Set up device data parameters
            // Set Baud rate to 9600
            ftStatus = myFtdiDevice.SetBaudRate(9600);
            if (ftStatus != FTDI.FT_STATUS.FT_OK)
            {

                commentbox.Text = "Failed to set Baud rate error " + ftStatus;

                return;
            }

            // Set data characteristics - Data bits, Stop bits, Parity
            ftStatus = myFtdiDevice.SetDataCharacteristics(FTDI.FT_DATA_BITS.FT_BITS_8, FTDI.FT_STOP_BITS.FT_STOP_BITS_1, FTDI.FT_PARITY.FT_PARITY_NONE);
            if (ftStatus != FTDI.FT_STATUS.FT_OK)
            {

                commentbox.Text = "Failed to set data characteristics error " + ftStatus;

                return;
            }

            // Set flow control - set RTS/CTS flow control
            ftStatus = myFtdiDevice.SetFlowControl(FTDI.FT_FLOW_CONTROL.FT_FLOW_RTS_CTS, 0x11, 0x13);
            if (ftStatus != FTDI.FT_STATUS.FT_OK)
            {

                commentbox.Text = "Failed to set flow control error " + ftStatus;

                return;
            }

            // Set read timeout to 5 seconds, write timeout to infinite
            ftStatus = myFtdiDevice.SetTimeouts(5000, 0);
            if (ftStatus != FTDI.FT_STATUS.FT_OK)
            {

                commentbox.Text = "Failed to set timeouts error " + ftStatus;

                return;
            }
           

        }
<pre>  private void ReadData_Click(object sender, EventArgs e)
        {
           UInt32 numBytesAvailable = 0;
            do
            {
                ftStatus = myFtdiDevice.GetRxBytesAvailable(ref numBytesAvailable);
                if (ftStatus != FTDI.FT_STATUS.FT_OK)
                {
                    // Wait for a key press

                    commentbox.Text = "Failed to get number of bytes available to read error " + ftStatus.ToString();
                    return;
                }
                Thread.Sleep(10);

            }
            while (numBytesAvailable <= 0);

            {
                // Now that we have the amount of data we want available, read it
                string readData = "";

                UInt32 numBytesRead = 0;
                if (readData == "")
                {
                    ftStatus = myFtdiDevice.Read(out readData, numBytesAvailable, ref numBytesRead);
                    richTextBox1.Text = readData;

                }
                // Note that the Read method is overloaded, so can read string or byte array data
                //  ftStatus = myFtdiDevice.Read(out readData, numBytesAvailable, ref numBytesRead);
                if (ftStatus != FTDI.FT_STATUS.FT_OK)
                {
                    // Wait for a key press
                    //Console.WriteLine("Failed to read data (error " + ftStatus.ToString() + ")");
                    //Console.ReadKey();
                    commentbox.Text = "Failed to read data error " + ftStatus.ToString();
                    return;
                }
                // Console.WriteLine(readData);
                commentbox.Text = readData;
                // Close our device
                ftStatus = myFtdiDevice.Close();

                // Wait for a key press

                Console.WriteLine("Press any key to continue.");
                Console.ReadKey();
                return;
            }
        }
Posted
Updated 21-Jul-22 4:00am
Comments
CHill60 21-Jul-22 8:51am    
Definitely not received or just not handled by your code?

1 solution

I don't know where you're getting your code from; I used the vendor's code.

https://ftdichip.com/wp-content/uploads/2020/08/D2XX_Programmers_GuideFT_000071.pdf

// 1. This sample shows how to read all the data currently available.
FT_HANDLE ftHandle;
FT_STATUS ftStatus;
DWORD EventDWord;
DWORD TxBytes;
DWORD RxBytes;
DWORD BytesReceived;
char RxBuffer[256];
ftStatus = FT_Open(0, &ftHandle);
if(ftStatus != FT_OK) {
// FT_Open failed
return;
}
FT_GetStatus(ftHandle,&RxBytes,&TxBytes,&EventDWord);
if (RxBytes > 0) {
ftStatus = FT_Read(ftHandle,RxBuffer,RxBytes,&BytesReceived);
if (ftStatus == FT_OK) {
// FT_Read OK
}
else {
// FT_Read Failed
}
}
FT_Close(ftHandle);
 
Share this answer
 

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