-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Add room() function to Serial Class to see free TXbuffer space (HWS & SWS) #1408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
int room() |
There allready exists the following function in hardwareSerial. Think it is int HardwareSerial::available(void) On Sat, Sep 21, 2013 at 3:11 AM, pwbecker [email protected] wrote:
|
Sorry, your proposal is on the transmittting site. Posted too quick. :) Have you checked - https://code.google.com/p/arduino/issues/list - if a On Sat, Sep 21, 2013 at 3:13 PM, Rob Tillaart [email protected]:
|
Just a quick mention, on the Arduino Developers Mailing List, this feature was discussed. Cristian decided this function would be named writeBufferFree(), if it's ever implemented in Arduino. Here's the mail list conversation, for reference. https://groups.google.com/a/arduino.cc/forum/#!msg/developers/ls3hkviFYM4/XWT2LbfzNcgJ |
Seen (parts of) the discussion, think it is convergating in the right direction. |
In my view this should be handled up in the stream class just like available() rather than down in HardwareSerial. |
Better have it in |
Print currently doesn't inherit from Stream so I don't see the issue of backward compatibility for Print if the function was added to Stream. The potential issue is for all of those that inherit from Stream, but if there was a default function in Stream, then even those would be able to still link. |
Funny |
@bperrybap, but I'm proposing to put the function in @jantje, the downside of returning -1 (as opposed to 1 or a large positive value) to signal "not implemented" is that callers are forced to check the return value - there is no automatic, graceful fallback. In the regard, using an unsigned return value and then returning -1 (== MAX_INT as unsigned) might be better as it allows automatic fallback at least in some cases, as well as not requiring a signed return value (which doesn't make any sense for available buffer space). As for the naming of the functions - I think we discussed that on the mailing list and a decision was made, so I'm not going into that. I agree that we should put this method in |
Jan, could you elaborate on "I do think having the method in stream is vital (at least it is for me) and only hardware Serial is really bad (and no solution to me) because replacing the serial to a software serial is going to break the code"? Sometimes explaining just one important real application can be much more persuasive that simply claiming you need a feature. When you say "is going to break the code", if you explain what code this is, how it will break, and why that's important, the use of a specific case can really add weight to your argument. Just to be clear, I'm not trying to argue either for or against this idea. I'm only trying to help you make a stronger case for it. So I guess in an indirect way, that means I'm for it? I agree with Matthijs about the name. Cristian already said he made a final decision. Only Cristian can change the decision on the name. |
TheoryThe whole point of having a base class is to make abstraction from the implementation. By putting the solution in hardware serial we make a mistake agains basic oo principles. Here are the consequences I think of. My caseIn my case I need it for the leonardo (that is also yun and esplora and probably your teens as well) they do not have a hardware serial.
Board compatibility: "is going to break the code"So when my code working on the UNO is ported to the leonardo it will not compile as Serial_ does not contain the new method (whatever its name) The BridgeClass; a Arduino example why it is needed.Look at the bridge (which is written with the leonardo in mind) Flexibility: "is going to break the code"But it goes further than that. Suppose I have my code working on a UNO and then I need to move it to alt software serial because I need to free up Serial for something else. |
This is of course fixed by implementing a method with the same name in CDCSerial (the class the Leonardo uses for the virtual serial port). Same goes for SoftwareSerial and others. That's just a small remark on that particular argument - I totally agree with your point. Especially the example of the BridgeClass is important - we want to support calling the |
Technically I see very little difference between returning -1 or MAX_INT as default value. From a "architectural point of view" I think -1 is the way to go. PS I tried to use MAX_INT but it seems to be unknown in the arduino development environment. |
about print or stream |
Thinking about Stream versus print again. |
That's exactly what I meant. |
On 07/08/2014 06:59 AM, Matthijs Kooijman wrote:
Was that the second sentences was simply explaining the proposal for re-consideration We will need to get clarification from Jan to be sure what was meant. My view is that this should not be added to Print I believe that Stream should be the i/o class and an output formatting class If I'm doing i/o but not doing any formatted data output, why should I have to include In terms of going down the path of adding any new virtual functions to Print, |
Seems my last comment is not fully understood. I think technically the new function is -again from a technical/coding point of view- best placed in print. Class wise it is defend-able that you derive a 2-directional class from a 1 directional class. ( I would not do so but that is what Arduino did.) However due to the naming (print and stream) and due to the OO rules (print should not know about stream) you get a big naming issue. Available (not specifying by name what is available in a 2 buffered class) is a really nice example of how quickly it all becomes confusing. Rereading the above I'm not sure it is making thing clearer. So I'll try to answer the questions: However ....... ......this will open a whole discussion on The whole discussion will make that the solution will never be implemented. So therefore my vote goes for adding the new method to the Serial class. in stream.h add following methods:
In any class you want the available send buffer size do like in hardware serial:
in hardwareSerial.cpp add
Note as I only added stuff this is 100% downwards compatible. |
I don't really think
AFAIU, Otherwise I mostly agree with what jantje is saying. Two caveats:
|
This code predates Christian his decision. I'm to old/experienced to fight for a name. Name them like Christian wants it.
Very good points. |
I just did the mod in Arduino IDE 1.5.7. Works great. |
There have been so many mods discussed, which one did you do? |
mine :-) because I did that one in 1.5.5 as well. |
Fixed with #2193 |
Sometimes one wants to know the amount of free places in the transmit buffer
The function to check this is straightforward.
this makes it possible to check and fill up the ring buffer to the max (esp when using low baud rates) without overflow.
The name room() is not as ambiguous as space which already has a meaning in serial communication. Available() is already used for receive.
The text was updated successfully, but these errors were encountered: