Arduino Serial <--> PC Transfer Data problem

Hi all
I am trying Serial library currently, and there is a problem.
My setting
1.Baud rate = 115200bps
2.Transfer packet size from pc to arduino= 34 bytes
3.Every "3ms" send packet (sniffer by Accessport Serial monitor)
4.Serial buffer size = 128bytes

If I sending packets continually , it works about 2 seconds , and than Serial port will stop any action.
sniffer a "purge" action from Serial monitor.

Here is my question.
In my concept. 115200bps = 11520bytes/s = 11.52bytes/ms

[]------------->口
/\ 34bytes

PC arduino

Process cannot handling the data which transfer so fast , so that put the data into the Serial buffer.
waiting Process to execute. Finally the Process will keep working.

To prove of my concept. I stop the data sending from PC. Even through I stop Sending data .
Arduino Serial interface don't haveany action. Unless I reset the Arduino.

I have been thinking during two days. and try to see the file "HardwareSerial.cpp" , because my C language not good enough to understand the code.....

But I still have some thought to trouldshootings.

  1. In code file "HardwareSerial.cpp" , path is
    /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino
int HardwareSerial::read(void)
{
  // if the head isn't ahead of the tail, we don't have any characters
  if (_rx_buffer_head == _rx_buffer_tail) {
    return -1;
  } else {
    unsigned char c = _rx_buffer[_rx_buffer_tail];
    _rx_buffer_tail = (rx_buffer_index_t)(_rx_buffer_tail + 1) % SERIAL_RX_BUFFER_SIZE;
    return c;
  }
}

if (_rx_buffer_head == _rx_buffer_tail)
In buffer ring structure , we have to condition in "_rx_buffer_head == _rx_buffer_tail"
First, ring is empty
Second, ring is full
Is any possible....the Serial API think the buffer is empty because sending to fast, therefore Serial have no any action?

  1. atmega16u2 USB to Serial cannot handling?

  2. My expect is even PC sending data too fast the process can drop or ignore , or anyway to workaround.
    Process stop is unacceptable.

Here is my Serial read code.

void Attenuator_c::Get_string2int(){
    int clear;

    while(Serial.available()>0 && rotary_or_serial == true){
        
        inByte=Serial.read();
        
        if(inByte == 'a' || inByte == 't' || inByte == ' ' || inByte == 'e' || inByte == 'n' ||
           inByte == 's' || inByte == 'g' || inByte == 'I' || inByte == 'D' || inByte == 'N' ||
           inByte == '*' || inByte == 'r' || inByte == '?' ||
           (inByte >= 48 && inByte <=57) && rotary_or_serial == true){
            
            command.concat(inByte);
        }
        
        else if(inByte == '\n' || inByte == '\r' && rotary_or_serial == true){
            //orignal code
            //command.toCharArray(carry,20);
            
#ifdef DEBUG
            //Serial.println(carry); //echo what u type
#endif
            
            /* orignal code
            switch (inByte) {
                case '\n':
                    find_address_value();
                    clear = Serial.read();
                    break;
                
                case '\r':
                    find_address_value();
                    clear = Serial.read();
                    break;
            }
            */
            Serial.println(command);
            
            tmp[0] = strtok(&command[0], " ");
            while( tmp[string_index] != NULL){
                //Serial.println(tmp[string_index]);
                string_index=string_index+1;
                
                tmp[string_index] = strtok(NULL, " ");
            }
            //Serial.println(tmp[0]);
            
            
            if(strcmp(tmp[0], "atten") == 0){
                
                if(strcmp(tmp[1], "set") == 0){
                    
                    //Serial.println("Go into Address and Value");
                    
                    for (_string_index=2; _string_index < string_index ; _string_index=_string_index+2 ) {
                        
                        Address_int=atoi(tmp[_string_index]); //_string_index=0
                    
                        value_int=atoi(tmp[_string_index+1])/10;
                        
                        compare_result=Compare_string_int(Address_int,value_int);
                    }
                    
                }
                else if(strcmp(tmp[1], "get") == 0){
                    
                
                    p("CH0 = %d dBm \n" , Arduino_Att[0][0]>>1);
                    p("CH1 = %d dBm \n" , Arduino_Att[1][0]>>1);
                    p("CH2 = %d dBm \n" , Arduino_Att[2][0]>>1);
                    p("CH3 = %d dBm \n" , Arduino_Att[3][0]>>1);
                    
                    //Serial.printf("CH3 = %d dBm \n"), Attenuator[3]);
                    
                    //Serial.println("On working, get function");
                    
                }
                
                
                else
                {
                    Serial.println("Error");
                }
            }
            
            else if(strcmp(tmp[0],"*IDN?") == 0){
                
                Serial.println(IDN);
            }
            
            else if(strcmp(tmp[0],"reset") == 0){
                
                delay(1);
                
                resetFunc();
                
            }
            
            else{
                Serial.println("Fisrt word Error must be atten");
            }
            string_index=0;
            
            
            
#ifdef DEBUG
            //Serial.println("command: "+command);
#endif
            
            clear = Serial.read();
            
            command="";
            /*
            command="";
            command.toCharArray(carry,20);
            Address_int=atoi(carry);
            value_int=atoi(carry);
            */
            
        }
        
        
        else{
            
            //Serial.flush();
            
        }
    }
    
}

Try the examples in Serial Input Basics - the second example will probably be most suited to your requirement. It should empty the buffer fast enough. You may wish to increase the value in the constant numChars if you want to receive more than 32 chars

...R

            command.concat(inByte);

Each time that a character is concatenated to the String instance, the time it takes to do that increases. Stop using Strings!