none
clear buffer

All replies

  • is there way to do that ?
    Monday, June 21, 2010 8:54 PM
  • Try the help file for "SerialPort".
    Monday, June 21, 2010 9:24 PM
  • what help file for SerialPort?

    and does it say how to clear the buffer ?

    Monday, June 21, 2010 9:29 PM
  • You should have a button labelled "Help" on the Standard menu bar in your IDE.  Place your mouse cursor on top of it and press and release the left mouse button.  On the Menu that appears, place your mouse cursor on top of "Index" and press and release the left mouse button. In the "Look for:" box that appears, type SerialPort.  In the items that appear, place your mouse cursor on top of "all members" from the "SerialPort class"and press and release the left mouse button.  The right pane will contain help on the SerialPort.

    Monday, June 21, 2010 9:51 PM
  • so will

    DiscardInBuffer()

    that work ?

    Tuesday, June 22, 2010 3:38 AM
  • ok that did not work
    Tuesday, June 22, 2010 4:27 AM
  • ok that did not work


    Replace the line DiscardInBuffer() with these lines:

          int bytesBefore = serialPort1.BytesToRead;
          serialPort1.DiscardInBuffer();
          
    int bytesAfter = serialPort1.BytesToRead;
          
    Console.WriteLine("Before = " + bytesBefore + 
                          
    ", bytesAfter = " + bytesAfter);

    and post what is written.

    Tuesday, June 22, 2010 5:18 AM
  • Hello, Riten

    Could you give John some feedback? This could help John diagnose the issue.

     DiscardInBuffer() should works. If you are not back I will mark John's reply as an answer.

    Thanks

    Chao

    Friday, June 25, 2010 7:52 AM
  • sorry it took so long.

    c# application: done  Before = 1, BytesAfter = 0m Before = 4, BytesAfter = 0h Before = 3, BytesAfter = 0:e Before = 0, BytesAfter = 0 1  Before = 1, BytesAfter = 0

    ok then I sent the char '2'

    c# application:

    0r Before = 4, BytesAfter = 0n  Before = 2, BytesAfter = 0nd
    :e Before = 1, BytesAfter = 0n
     me Before = 0, BytesAfter = 0mu
      Before = 0, BytesAfter = 0nu
     me Before = 0, BytesAfter = 0enu
     m Before = 5, BytesAfter = 0n me Before = 0, BytesAfter = 0
     menu Before = 0, BytesAfter = 0u
     men Before = 0, BytesAfter = 0menu  
      Before = 0, BytesAfter = 0e
     menu
     m Before = 0, BytesAfter = 0
     menunu Before = 0, BytesAfter = 0
     
     menu Before = 0, BytesAfter = 0enu
     m m Before = 1, BytesAfter = 0enu
     m Before = 0, BytesAfter = 0
     menu nu Before = 0, BytesAfter = 0
     menu
     men Before = 6, BytesAfter = 0 nu Before = 0, BytesAfter = 0
     menu
     m Before = 6, BytesAfter = 0u men Before = 0, BytesAfter = 0
     menu
     Before = 1, BytesAfter = 0enu
     menum Before = 0, BytesAfter = 0
     menu
      Before = 5, BytesAfter = 0n
     me Before = 0, BytesAfter = 0
    u
     menu  Before = 0, BytesAfter = 0 m menu
     Before = 0, BytesAfter = 0uenu
     men Before = 0, BytesAfter = 0u
     
     men Before = 0, BytesAfter = 0menu
     me Before = 6, BytesAfter = 0nu e Before = 0, BytesAfter = 0 me
     menu
     Before = 0, BytesAfter = 0
     menunu Before = 0, BytesAfter = 0  
     menu
     Before = 0, BytesAfter = 0enu
     menu m Before = 0, BytesAfter = 0
     menu
      Before = 8, BytesAfter = 0uen Before = 0, BytesAfter = 0enu
     
     m Before = 0, BytesAfter = 0enu
     menm Before = 0, BytesAfter = 0
     menu
     u Before = 0, BytesAfter = 0enu
     menm Before = 0, BytesAfter = 0nu u
     me Before = 0, BytesAfter = 0 menu
     
     Before = 0, BytesAfter = 0u
    menu
     men Before = 0, BytesAfter = 0 menu
     me Before = 8, BytesAfter = 0u
     Before = 6, BytesAfter = 0n
     me Before = 0, BytesAfter = 0 u
     menu
     Before = 0, BytesAfter = 0umenu
     men Before = 0, BytesAfter = 0
     menu
       Before = 0, BytesAfter = 0u menu
     men Before = 0, BytesAfter = 0
     menu
     men Before = 7, BytesAfter = 0mu
      Before = 0, BytesAfter = 0 enu
     men Before = 1, BytesAfter = 0
     menu
     me Before = 2, BytesAfter = 0e
     menu
      Before = 1, BytesAfter = 0mnu
     menu
      Before = 0, BytesAfter = 0
     enu
     menu  Before = 0, BytesAfter = 0 menu
     menu Before = 0, BytesAfter = 0
     me
     menu Before = 1, BytesAfter = 0
     menu
     u  Before = 0, BytesAfter = 0 menu
     menu Before = 0, BytesAfter = 0
     men
     menu Before = 0, BytesAfter = 0eu
     menu
     m Before = 0, BytesAfter = 0u
    nu
     men Before = 0, BytesAfter = 0u menu
     men Before = 0, BytesAfter = 0nu
     
     Before = 3, BytesAfter = 0menu
     menn Before = 1, BytesAfter = 0 menu
      Before = 0, BytesAfter = 0menu
     m
     Before = 0, BytesAfter = 0nu
     men  Before = 0, BytesAfter = 0
     menu
    m Before = 0, BytesAfter = 0 menu
     mene Before = 0, BytesAfter = 0u
     menu
      Before = 1, BytesAfter = 0 menu
     me
     Before = 1, BytesAfter = 0nu e Before = 1, BytesAfter = 0menu
     menu
     m Before = 3, BytesAfter = 0menu  Before = 0, BytesAfter = 0
     menu
     Before = 0, BytesAfter = 0enu
     m  Before = 0, BytesAfter = 0enu
     menum Before = 0, BytesAfter = 0
     menu
     me Before = 1, BytesAfter = 0nu
     menu  Before = 0, BytesAfter = 0
     menu
     mn Before = 6, BytesAfter = 0u
     ????@??n Before = 0, BytesAfter = 0??<n?u Before = 0, BytesAfter = 0  Before = 0, BytesAfter = 0
     Before = 0, BytesAfter = 0  Before = 12, BytesAfter = 0n Before = 3, BytesAfter = 0  Before = 0, BytesAfter = 0m Before = 0, BytesAfter = 0e Before = 0, BytesAfter = 0n Before = 0, BytesAfter = 0u Before = 0, BytesAfter = 0  Before = 0, BytesAfter = 0  Before = 4, BytesAfter = 0n Before = 0, BytesAfter = 0u Before = 0, BytesAfter = 0  Before = 0, BytesAfter = 0
     Before = 0, BytesAfter = 0  Before = 0, BytesAfter = 0m Before = 0, BytesAfter = 0  Before = 1, BytesAfter = 0  Before = 1, BytesAfter = 0n Before

    Friday, June 25, 2010 12:22 PM
  • ok it seem to be working

    but what I did not get is if the buffer is empty ... where it is getting  the sting "menu "

    because  my microprocessor only sends menu one time then it

    sent other data

    please look that this post

    http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/b45b2009-8bf2-438a-ba25-fb63ea7fca15

    and you can see what my microprocessor  should be sending to the c# application...

    I run my  pic18f4525 ( microprocessor) on Hyper Terminal so that is how I know that that is working right...

    I post that run on that link....

    yeah so if the buffer is empty where are the other chars coming from ???

    Friday, June 25, 2010 12:31 PM
  • this is my code


             void mySp_DataReceived(object sender, SerialDataReceivedEventArgs e)
            {

                string msg = mySp.ReadExisting();

                 // If the com port has been closed, do nothing
                if (!mySp.IsOpen) return;

                // This method will be called when there is data waiting in the port's buffer

                // Determain which mode (string or binary) the user is in
                  
                    // Read all the data waiting in the buffer
                int bytesBefore = mySp.BytesToRead;
                get2.BeginInvoke(new EventHandler(delegate
                    {
                        get2.Text += mySp.ReadExisting();
                        get2.SelectionFont = new Font(get2.SelectionFont, FontStyle.Bold);
                        get2.ScrollToCaret();
                        get2.SelectedText = string.Empty;
                        get2.AppendText(msg);
                      

                    }));

                    // Display the text to the user in the terminal

               // int bytesBefore = mySp.BytesToRead;
                mySp.DiscardInBuffer();
                int bytesAfter = mySp.BytesToRead;
                get2.BeginInvoke(new EventHandler(delegate
                    {
                        get2.Text += " Before = " + bytesBefore +
                            ", BytesAfter = " + bytesAfter;
                    }));

    Friday, June 25, 2010 12:34 PM