Skip to content
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

ENH: Cleaner Serial I/O code #14

Open
BobGlicksman opened this issue Aug 10, 2024 · 0 comments
Open

ENH: Cleaner Serial I/O code #14

BobGlicksman opened this issue Aug 10, 2024 · 0 comments

Comments

@BobGlicksman
Copy link
Owner

Utility code in tpp_LoRa.cpp utilizes the available() method and self-implemented timers to timeout serial I/O communications. There is nothing wrong with this approach. However, the Serial I/O library has these features built-in and the code could be cleaned up accordingly. Specifically, Serial.readString() reads in a string from the serial I/O port. The readString() method has an automatic timeout on it and will return whatever is in the serial buffer (including nothing) when it times out. The default timeout is 1 second (1000 ms). However, this can be changed by using the setTimeout() method. The argument to setTimeout() is a number of milliseconds for the timeout, i.e. Serial.setTimeout(10) sets a 10 ms timeout for the readString() method on the Serial port.

In addition to readString, the library has another method called readStringUntil(). The argument is a char -- the character that will terminate the read and return the string when it is detected. If the termination character is not received within the timeout period, the string will be returned upon timeout.

Reference: https://www.arduino.cc/reference/en/language/functions/communication/serial/

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

No branches or pull requests

1 participant