How to make these variables accessible?

Hi all,

I'm just playing around the s/w serial library and I want to be able to read the values of these variables from my .ino file.

static char _receive_buffer[_SS_MAX_RX_BUFF];
static volatile uint8_t _receive_buffer_tail;
static volatile uint8_t _receive_buffer_head;

In the softwareserial.h, the above variables are declared under private so I just moved them to public as shown below. But during compile, when I reach the line trying to print the contents of _receive_buffer, I get the error: error: '_receive_buffer' was not declared in this scope

/******************************************************************************
* Definitions
******************************************************************************/

//#define _SS_MAX_RX_BUFF 64 // RX buffer size
#define _SS_MAX_RX_BUFF 256 // RX buffer size
#ifndef GCC_VERSION
#define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
#endif

class SoftwareSerial : public Stream
{
private:
  // per object data
  uint8_t _receivePin;
  uint8_t _receiveBitMask;
  volatile uint8_t *_receivePortRegister;
  uint8_t _transmitBitMask;
  volatile uint8_t *_transmitPortRegister;

  uint16_t _rx_delay_centering;
  uint16_t _rx_delay_intrabit;
  uint16_t _rx_delay_stopbit;
  uint16_t _tx_delay;

  uint16_t _buffer_overflow:1;
  uint16_t _inverse_logic:1;

  // static data
  //static char _receive_buffer[_SS_MAX_RX_BUFF]; 
  //static volatile uint8_t _receive_buffer_tail;
  //static volatile uint8_t _receive_buffer_head;
  static SoftwareSerial *active_object;

  // private methods
  void recv();
  uint8_t rx_pin_read();
  void tx_pin_write(uint8_t pin_state);
  void setTX(uint8_t transmitPin);
  void setRX(uint8_t receivePin);

  // private static method for timing
  static inline void tunedDelay(uint16_t delay);

public:

  static char _receive_buffer[_SS_MAX_RX_BUFF]; 
  static volatile uint8_t _receive_buffer_tail;
  static volatile uint8_t _receive_buffer_head;
  // public methods
  SoftwareSerial(uint8_t receivePin, uint8_t transmitPin, bool inverse_logic = false);
  ~SoftwareSerial();
  void begin(long speed);
  bool listen();
  void end();
  bool isListening() { return this == active_object; }
  bool overflow() { bool ret = _buffer_overflow; _buffer_overflow = false; return ret; }
  int peek();

  virtual size_t write(uint8_t byte);
  virtual int read();
  virtual int available();
  virtual void flush();
  
  using Print::write;

  // public only for easy access by interrupt handlers
  static inline void handle_interrupt();
};

// Arduino 0012 workaround
#undef int
#undef char
#undef long
#undef byte
#undef float
#undef abs
#undef round

#endif

Thanks in advance!
Alyas

You didn't show the code you are using to try to access those variables. You need to access them like this:

SoftwareSerial::_receive_buffer

instead of just:

_receive_buffer

and similarly for the others.

Thanks so much! Oh so such simple. I really should start learning this c++ stuff

so I just moved them to public as shown below

:astonished:

What are you trying to do ?

tuxduino:

so I just moved them to public as shown below

:astonished:

What are you trying to do ?

I don't need the circular buffer so I just need to read the contents of the whole buffer. Once read, I just flush the contents so new data can be written to the buffer.

I hope you plan to remove the code that manages the circular buffer too. You're asking for trouble if you try to step on the library's toes.

Besides, what does it mean "I don't need the circular buffer" ?

My strong suggestion is just leave the library code alone. It's there for a purpose. If you think you know better than whoever wrote the library, just don't use it and write you own code.
OTOH, if you need to manage serial received data there are plenty of examples around, and many helpful people around here. Just show what you have and ask for hints.

The path you're on isn't taking you anywhere IMHO.

The path you're on isn't taking you anywhere IMHO.

I disagree. I think it's taking OP down a rabbit hole. Not necessarily a desired place to go. :slight_smile:

:stuck_out_tongue:

alyas:
I don't need the circular buffer so I just need to read the contents of the whole buffer. Once read, I just flush the contents so new data can be written to the buffer.

Why?

You know, I hope, that this buffer is written to by an interrupt, so you are asking for trouble to modify it unrestrained.