2016-07-14 01:24:56 +02:00
|
|
|
# Serial Read Line
|
|
|
|
|
|
|
|
Read a line of text from the serial port.
|
|
|
|
|
|
|
|
```sig
|
|
|
|
serial.readLine();
|
|
|
|
```
|
|
|
|
|
2019-12-02 05:58:26 +01:00
|
|
|
### ~hint
|
2016-07-14 01:24:56 +02:00
|
|
|
|
2020-09-08 11:04:25 +02:00
|
|
|
This function expects the line it reads to be terminated with the `\n`
|
2016-07-14 01:24:56 +02:00
|
|
|
character. If your terminal software does not terminate lines with
|
2020-09-08 11:04:25 +02:00
|
|
|
`\n`, this function will probably never return a value.
|
|
|
|
|
|
|
|
|
|
|
|
You can override the ``serial.NEW_LINE_DELIMITER`` field to change the newline delimiter.
|
2016-07-14 01:24:56 +02:00
|
|
|
|
2019-12-02 05:58:26 +01:00
|
|
|
### ~
|
2016-07-14 01:24:56 +02:00
|
|
|
|
2019-12-02 05:58:26 +01:00
|
|
|
## Returns
|
2016-07-14 01:24:56 +02:00
|
|
|
|
2019-12-02 05:58:26 +01:00
|
|
|
* a [string](/types/string) containing input from the serial port, such as a response typed by a user
|
2016-07-14 01:24:56 +02:00
|
|
|
|
2019-12-02 05:58:26 +01:00
|
|
|
## Example
|
2016-07-14 01:24:56 +02:00
|
|
|
|
|
|
|
The following example requests the user's name, then repeats it to greet the user.
|
|
|
|
|
|
|
|
```blocks
|
|
|
|
basic.forever(() => {
|
|
|
|
serial.writeLine("What is your name?");
|
|
|
|
let answer = serial.readLine();
|
|
|
|
serial.writeString("Hello,");
|
|
|
|
serial.writeLine(answer);
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2019-12-02 05:58:26 +01:00
|
|
|
## See also
|
2016-07-14 01:24:56 +02:00
|
|
|
|
|
|
|
[serial](/device/serial),
|
|
|
|
[serial write line](/reference/serial/write-line),
|
|
|
|
[serial write value](/reference/serial/write-value)
|