-
-
Notifications
You must be signed in to change notification settings - Fork 7k
New Serial.Begin() #106
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
New Serial.Begin() #106
Conversation
Adding advanced begin (); with the ability to specify the length of bits, parity, stop bits.
Adding advanced begin (); with the ability to specify the length of bits, parity, stop bits.
Adding advanced begin (); with the ability to specify the length of bits, parity, stop bits.
Adding advanced begin (); with the ability to specify the length of bits, parity, stop bits.
Adding advanced begin (); with the ability to specify the length of bits, parity, stop bits.
I believe we should save the possibility for extra parameters to Serial.begin() for hardware flow control. More advanced chips, like the one that will be on Arduino Due, have hardware flow control features like RTS/CTS and automatic RS485 transmit enable. Those really want to be specified in begin(). How about making changes to the communication format as a separate function? |
I used the reset function begin (). You can use: Serial.begin (baudrate); or Serial.begin (baudrate, databits, parity, stopbits);. |
Paul, I'm not sure I quite understand your comment. If we want to add support for specifying flow control in begin(), can't we do that with additional parameters or an alternative overload of the function? If you want to specify an alternative number of data or stop bits, or a different parity, it seems weird to have to do that in a different function. Serial.begin(9600, 8, 'N', 1) feels natural to me. |
If we go with Serial.begin(baud, bits, parity, stop), that's 4 integer parameters. In theory, 2 and 3 parameters are still options for future features. But usually redefining what the Nth parameter's meaning, based only on how many other parameters are present, is confusing. Especially for a system that's meant to be easy to use, we're looking at adding a 5th, 6th and maybe 7th parameter later for Due's hardware flow control capabilities. Maybe you're fine with the prospect of 6 parameters? That seems pretty excessive to me. Also, only the first 3 might be passed efficiently in registers by the compiler on AVR and/or ARM, so there is a code size cost to a long parameter list. These proposed parameters are all integers, or types that automatically promote to integer. Maybe not a big deal, but a long list or same-type parameters is often considered not great API design. This decision will forever become part of Arduino's API, or at least any change will mean painful incompatibility, so I think at least some forward-looking though is worthwhile. Perhaps Serial.begin(baud, format) might make more sense, with some nicely named "format" constants or static objects defined? |
i like the idea of "Serial.begin(baud, format)" where format is a struct 2012/8/13 PaulStoffregen [email protected]
|
"Format" string to set "8N1" or "7E1", etc.? Structure does not take up more space in memory? Function begin() is executed at the beginning of whether to use a structure? |
your string use 3 byte, we can use a struct that use 1 byte and some hidden 2012/8/14 Alarus [email protected]
|
fix check for NULL buffer in getString()
Adding advanced begin (); with the ability to specify the length of bits, parity, stop bits.