Skip to content

ENH: Cleaner Serial I/O code #14

Description

@BobGlicksman

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/

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions