Reading Bytes from Serial Ports
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Reading Bytes from Serial Ports

Hybrid View

  1. #1
    Join Date
    Apr 2014
    Posts
    4

    Reading Bytes from Serial Ports

    Good day to all,
    Please I need your guide and support on how to use this function:
    Code:
    ftStatus = myFtdiDevice.Read(readData, numBytesAvailable,ref numBytesRead);
    to read byte from the serial port.This function is part of the DLL that came with the chip(FT2232D) I am using on my board.I want to use the function to read a byte from the serial port and then send the value to the Graphic user interface.Unfortunately I was unable to get the expected value on my GUI.If I send for instance 40,what I get on the GUI are letters instead of the number 40 or at times the GUI will not even respond.Below are my lines of code I used to read the byte from the serial port:

    The following instructions are executed whenever the CHECKBOX is checked

    Code:
    private
    void checkBox1_CheckedChanged(object sender, EventArgs e)
    
             {
    
                 
     
    UInt32 numBytesRead = 0;
    
                 
    UInt32 numBytesAvailable = 1;
    
                 ftStatus = myFtdiDevice.Read(readData, numBytesAvailable, ref numBytesRead);
     
    
                 label11.Text =Convert.ToString(ftStatus);
    
    
    
      
      
     
      
    
             }
    Below is the definition of the function from the supplied library:
    Code:
      Read data from an open FTDI device.
    
            
    //
    
            
    // Parameters:
    
            
    //   dataBuffer:
    
            
    //     An array of bytes which will be populated with the data read from the device.
    
            
    //
    
            
    //   numBytesToRead:
    
            
    //     The number of bytes requested from the device.
    
            
    //
    
            
    //   numBytesRead:
    
            
    //     The number of bytes actually read.
    
            
    //
    
            
    // Returns:
    
            
    //     FT_STATUS value from FT_Read in FTD2XX.DLL
    
            
    publicFTDI.FT_STATUS Read(byte[] dataBuffer, uint numBytesToRead, refuint numBytesRead);
    Your guide and assistance will be highly appreciated in this regard.
    Best regards.

  2. #2
    Join Date
    Apr 2014
    Location
    in northeast ohio
    Posts
    71

    Re: Reading Bytes from Serial Ports

    ok im not expert on this ,maybe someone here is, i do find it interesting
    so in effort to help and looking into it , i did find some interesting examples that use it
    even a open source library or example using ftdi stuff

    additionally what i think you want to send to be displayed is not the status
    (i think that value is more about return codes that describe the data in readData)
    ftStatus = myFtdiDevice.Read(readData, numBytesAvailable, ref numBytesRead);
    label11.Text =Convert.ToString(ftStatus);
    but instead if i understand right it should be something more like
    ftStatus = myFtdiDevice.Read(readData, numBytesAvailable, ref numBytesRead);
    label11.Text =Convert.ToString(readData); // were readdata actually contains the serial data bytes
    either way have a look at the examples below

    hopefully some of these links will help

    a similar question on stack overflow with a working example
    http://stackoverflow.com/questions/1...ead-all-buffer
    this above appears to have been using the dll from this FTDI site below but im not sure
    http://www.ftdichip.com/Support/Soft...les/CSharp.htm

    open source library
    a example on git hub open source that reads a ftdi device this is the program source code
    https://github.com/DVDPT/DigitalData...ack/Program.cs
    this is the full github downloadable / clonable project
    https://github.com/DVDPT/DigitalDataLogger
    Last edited by willmotil; June 8th, 2014 at 03:34 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center