Display for RX_BUFFER_SIZE in HardwareSerial.cpp

Hi Dude,

I want to display the value of RX_BUFFER_SIZE of HardwareSerial.cpp in my program like that

void setup() 
{
   
  Serial.begin(9600); // For debugging only

  Serial.print(F("\n\rRX_BUFFER_SIZE="));  //display value of RX_BUFFER_SIZE of  HardwareSerial.cpp
  Serial.println(RX_BUFFER_SIZE, DEC);
}
void loop() 
{
}

But I have an error when I put that line

error: 'RX_BUFFER_SIZE' was not declared in this scope

Arduino IDE is v1.0.4

Can anyone please point me how to solve that problem?

Thank in advance,
pak

Add #include <HardwareSerial.cpp> to the top of your sketch.

Tom, thank for quick reply, but it does not work, same error as well, here is my sketch

#include <HardwareSerial.cpp>
//#include <HardwareSerial.h>  //try but same error

void setup() 
{
   
  Serial.begin(9600); // For debugging only

  Serial.print(F("\n\rRX_BUFFER_SIZE="));  //display value of RX_BUFFER_SIZE of  HardwareSerial.cpp
  Serial.println(RX_BUFFER_SIZE, DEC);
}
void loop() 
{
}

Are you sure it's RX_BUFFER_SIZE? I thought (or at least in my version) it is: "SERIAL_BUFFER_SIZE"

#include <HardwareSerial.cpp>

void setup ()
  {
  Serial.begin (115200);
  Serial.println ();

  Serial.println (SERIAL_BUFFER_SIZE);
  }  // end of setup

void loop () { }

Although I'm a little surprised we didn't get a duplicate symbol on Serial.

It's not normally done to include a .cpp file inside another one, and that is the file with SERIAL_BUFFER_SIZE in it.

Oh, you're right, it's SERIAL_BUFFER_SIZE. I apologize for that, now compile with no error. The reason to check the buffer size is I'm using both UNO and mega2560 together and to ensure the correct buffer size with related MCU.

Thank again,
pak

You could have used the same calculation they do in HardwareSerial.cpp (based on the RAM size). It shouldn't be all that necessary to know the buffer size, and in any case both of those boards will be using 64 so I don't see what you have achieved here.