Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i want to read and write the data using FT232rl module in c#. i made a connection but didnot get access to read and write the data.please help!!!!!!!!!!!

What I have tried:

 //for connection
 private void Button1_Click(object sender, EventArgs e)
        {

            try
            {
                ftStatus = myFtdiDevice.GetNumberOfDevices(ref devcount);
            
            }
            catch
            {
                commentbox.Text = "Driver not loaded";

             
            }

            ftStatus = myFtdiDevice.OpenByIndex(0);

            // Update the Status text line
            if (ftStatus == FTDI.FT_STATUS.FT_OK)
            {
                DeviceOpen = true;
                commentbox.Text = "FT232RL 通信しました";
            }
            else
            {
                DeviceOpen = false;
                commentbox.Text = "FT232RL 通信出来ないです";
            }

            Update();
            Application.DoEvents();


           
        }
//Read data
 private void ReadData_Click(object sender, EventArgs e)
        {
            if (DeviceOpen == true)
            {
                ftStatus = myFtdiDevice.GetRxBytesAvailable(ref numBytesAvailable);
                if (ftStatus != FTDI.FT_STATUS.FT_OK)
                {
                    Console.WriteLine("Failed to get number of bytes available to read (error " + ftStatus.ToString() + ")");
                    Console.ReadKey();
                    return;
                }

                string readData = "";
                UInt32 numBytesRead = 0;
                byte[] dataBuffer = new byte[1024];

                // TODO: check so you don't over your buffer.
                ftStatus = myFtdiDevice.Read(out readData, numBytesAvailable, ref numBytesRead);

                Console.WriteLine(readData);

                Thread.Sleep(10000);
            }
            else
            {
                commentbox.Text = "not open";
            }
Posted
Comments
[no name] 20-Jul-22 9:41am    
You didn't check the contents of "bytes available". You don't even display it.
Maciej Los 22-Jul-22 4:52am    
I'd strongly recommend to read this: C# Examples - FTDI[^]

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