HardwareSerial.h edit is not working

Hello everybody,

I'm trying to build an acoustic levitator using an Arduino MEGA. For this I'm using intructions I found on the internet. The guy who wrote the code said:

/*Please do not forget to In the public interface of Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino\HardwareSerial.h
add the following inline functions
inline bool _dataAvailable() {return _rx_buffer_head != _rx_buffer_tail; }
inline byte _peekData() { return _rx_buffer[_rx_buffer_tail]; }
inline void _discardByte() { _rx_buffer_tail = (rx_buffer_index_t)(_rx_buffer_tail + 1) % SERIAL_RX_BUFFER_SIZE; }
*/

I did exactly what he said but the code won't compile with the Arduino. I get messages like

DriverMEGA:121: error: 'class HardwareSerial' has no member named '_dataAvailable'

Same with the other two functions. It seems that the program is not reading the functions I added to the HardwareSerial.h file.

Did I edit the file right? Why is is not working? Other users seem to not have any problems with the same code.

Thank you.

Did I edit the file right?

My crystal ball says no. Since you didn't post the modified file properly (I do NOT look at pictures of text), I can only assume that my crystal ball knows what it is talking about.

You provided no proof that you modified the correct file, either.

There is NO reason to add those methods to the HardwareSerial class. It already has an available() method that returns the number of bytes available to read. That value could be treated as a boolean (although I think it is far better to explicitly acknowledge that you are interested in the value being greater than 0). The class already has a peek() method that does exactly what that function is supposed to do.

And, it is trivial to throw away unread data, without adding a new method to the class.

The problem is probably that the file you're editing is not the file being used by the Arduino IDE. You may have multiple copies of this file on your computer and you need to be sure to get the right one.

The easiest way to find it is:

  • File > Examples > SPI > BarometricPressureSensor
  • Sketch > Show Sketch Folder
  • Move up folder levels until you reach the one that contains boards.txt
  • cores/arduino/HardwareSerial.h relative to this folder is the one you should edit.

pert:
The problem is probably that the file you're editing is not the file being used by the Arduino IDE. You may have multiple copies of this file on your computer and you need to be sure to get the right one.

The easiest way to find it is:

  • File > Examples > SPI > BarometricPressureSensor
  • Sketch > Show Sketch Folder
  • Move up folder levels until you reach the one that contains boards.txt
  • cores/arduino/HardwareSerial.h relative to this folder is the one you should edit.

Thank you so much!! It worked!