What is the system name for the Serial RX buffer? For example:
char myChar = _rx_buffer_[6];
Serial.println(myChar);
What is the system name for the Serial RX buffer? For example:
char myChar = _rx_buffer_[6];
Serial.println(myChar);
In Arduino Platform, the vocabulary to bring out a data byte from the UART FIFO is: Serial.read(). What is this variable/data item : rx_buffer[6]?
In general, the rx_buffer is a protected variable somewhereinside the HardwareSerial Class (sometimes further inside of a RingBuffer structure...)
(that means that normal sketch code can't access it directly, BTW.)
SgtS47:
What is the system name for the Serial RX buffer? For example:char myChar = _rx_buffer_[6];
Serial.println(myChar);
You can't do what you want but the real question is probably why you want to do it in the first place as there may be other ways of achieving whatever it is that you are doing
@OP
char myChar = rx_buffer[6];
In HardwareSerial.h file (referred by Post#2), I see the following declaration:
unsigned char _rx_buffer[SERIAL_RX_BUFFER_SIZE];
==> unsigned char _rx_buffer[64];
This is a declaration of a 64-byte wide array of type 'unsigned char', which is a ring type buffer to accommodate the bytes (ASCII code or binary code) arriving via UART/Serial Port.
In your declaration, why is it like this: rx_buffer? I am talking about the extra underscore (_) attached with the word buffer. From where have you got it?
I assume that the correct form of your code should be like this:
char myChar = _rx_buffer[6];
, and with the help of this code you have wished to read 'data item number-6' from a 'protected buffer'. The code is not compiled in the Arduino IDE.
May someone be kind to explain a little bit why a user has not been allowed to access the said protected buffer directly; but, he can access it indirectly using Serial.read() method.
GolamMostafa:
May someone be kind to explain a little bit why a user has not been allowed to access the said protected buffer directly; but, he can access it indirectly using Serial.read() method.
To prevent users from doing stupid things. Encapsulation and Abstraction are two of the Pillars of Object Oriented Programming.
gfvalvo:
To prevent users from doing stupid things. Encapsulation and Abstraction are two of the Pillars of Object Oriented Programming.
Is a user so stupid that he is going to edit the HardwareSerial.h file and spread pollution all over the place of UART programming? Is HardwareSerial.h a protected file in the PC?
I suppose you'll have to take your complaint back to the founders of OOP.
Is a user so stupid that he is going to edit the HardwareSerial.h file and spread pollution all over the place of UART programming?
I guess if you know what you are doing you can and will read the serial port directly, if for some reason that improves your program. If you don't know what you are doing....
gfvalvo:
I suppose you'll have to take your complaint back to the founders of OOP.
It is not that! We have to know why has it been so essential to add 'Encapsulation and Abstraction' on normal procedural programming.
It is very very unlikely that the user is going to pollute his code knowingly; but, he could do the same by mistake. Also, his co-worker in a multi-user system could willingly/mistakenly pollute the codes. We need a protection mechanism! C++ offers such protection to user codes through the introduction of class concept.
GolamMostafa:
It is not that! We have to know why has it been so essential to add 'Encapsulation and Abstraction' on normal procedural programming.
I guess part of the answer is that it is not "normal procedural programming". The Serial library is written using OOP principles.
I like the idea of encapsulation. If you look at the "OOP" features in Python you will see that they chose not to implement encapsulation and to my mind that is a real PITA because you think you have defined a class with its constituent variables and methods and then I accidentally create a line of code that writes to a non-existent member of the class and Python is perfectly happy with that - it just creates a new member. But what I want it to do is say "STUPID BERK, xxx IS NOT A MEMBER OF THAT CLASS".
...R
You can "peek" the first char in the buffer, thought maybe there was a way to peek the xth. Oh well, thanks anyway, guess I need to find a different MCU or programming platform.
SgtS47:
You can "peek" the first char in the buffer, thought maybe there was a way to peek the xth. Oh well, thanks anyway, guess I need to find a different MCU or programming platform.
You have still not told us why you want to do this.
Why do you need to peek the xth?
I think the problem isn't in the platform and certainly not in the MCU (it has nothing to do with the hardware ;)) but in your thinking
And yeah, UKHeliBob is right, it's turning into an XYproblem.
gfvalvo:
To prevent users from doing stupid things. Encapsulation and Abstraction are two of the Pillars of Object Oriented Programming.
Guess I should have heeded the warnings about this forum. Never mind.
It's not a warning about this forum, it's a sign of good programming
SgtS47:
Guess I should have heeded the warnings about this forum. Never mind.
Why have you not told us WHY you want to peek the Xth character.
I can't imagine any advantage in being able to do so.
...R