Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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
Alarus wants to merge 5 commits into arduino:master from Alarus:master
Closed

New Serial.Begin() #106

Alarus wants to merge 5 commits into arduino:master from Alarus:master

Conversation

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.
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
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.

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.

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?

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 notifications@github.com

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.

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?

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 notifications@github.com

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

tbowmo pushed a commit to tbowmo/Arduino that referenced this pull request Jul 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers
No reviews
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /