Skip to content

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

Closed
wants to merge 5 commits into from
Closed

New Serial.Begin() #106

wants to merge 5 commits into from

Conversation

Alarus
Copy link
Contributor

@Alarus Alarus commented Aug 12, 2012

Adding advanced begin (); with the ability to specify the length of bits, parity, stop bits.

Alarus added 5 commits August 12, 2012 20:18
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.
@PaulStoffregen
Copy link
Contributor

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?

@ghost ghost assigned damellis Aug 12, 2012
@Alarus
Copy link
Contributor Author

Alarus commented Aug 12, 2012

I used the reset function begin (). You can use: Serial.begin (baudrate); or Serial.begin (baudrate, databits, parity, stopbits);.
You can write additional features flow control, but it will be built on top of the current function.
The new function begin () checks the parity.

@damellis
Copy link
Contributor

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.

@PaulStoffregen
Copy link
Contributor

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?

@lestofante
Copy link

i like the idea of "Serial.begin(baud, format)" where format is a struct
that contains the value for flow control.
i don't like the idea of separated method because what can't change in
runtime should be possible to be setted during begin()

2012/8/13 PaulStoffregen [email protected]

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?


Reply to this email directly or view it on GitHubhttps://github.com//pull/106#issuecomment-7709103.

@Alarus
Copy link
Contributor Author

Alarus commented Aug 14, 2012

"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?

@lestofante
Copy link

your string use 3 byte, we can use a struct that use 1 byte and some hidden
math. With one byte you have 255 combinations, but valid format are less;
example code (in java):
https://github.com/lestofante/jSpace2d/blob/master/src/base/game/network/packets/utils/ClientState.java

2012/8/14 Alarus [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?


Reply to this email directly or view it on GitHubhttps://github.com//pull/106#issuecomment-7719682.

@Alarus Alarus closed this Aug 14, 2012
tbowmo pushed a commit to tbowmo/Arduino that referenced this pull request Jul 14, 2016
fix check for NULL buffer in getString()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants