Plot Something - ME 405 Term Project
|
This class implements a task which reads user input one character at a time and puts characters together into lines of text. More...
Public Member Functions | |
def | __init__ (self, stream serial_device, echo=True) |
Create a non-blocking input object. More... | |
def | any (self) |
Check whether there are any lines of input and return the oldest if so. More... | |
def | get (self) |
Get one line of characters which have been received through the serial device. More... | |
def | check (self) |
This method is run within a task function to watch for characters coming through a serial port. More... | |
This class implements a task which reads user input one character at a time and puts characters together into lines of text.
The result is code that can be used similarly to the Python input()
function but doesn't block other tasks while waiting for the lazy bum user to type something. Lines of text which have been received are put into a list; the lines can then be read from the list as they become available.
The class in this module is designed to be run within a task which is run by the scheduler in cotask.py
. See the example file basic_tasks.py
and the test code at the bottom of this file for examples of such tasks.
When running this code with Thonny, one often sees warnings such as WARNING:root:Unexpected echo
, indicating that the text which Thonny saw from the microcontroller in response to user input isn't what Thonny expected to see. These warnings may be ignored.
def nb_input.NB_Input.__init__ | ( | self, | |
stream | serial_device, | ||
echo = True |
|||
) |
Create a non-blocking input object.
There should be at most one of these for each serial port.
serial_device | The UART or similar serial port through which characters will be received |
echo | If true, characters will be printed back as they're typed |
def nb_input.NB_Input.any | ( | self | ) |
Check whether there are any lines of input and return the oldest if so.
True
if there are any lines of user input available def nb_input.NB_Input.check | ( | self | ) |
This method is run within a task function to watch for characters coming through a serial port.
As characters are received, it assembles them into a line and makes a reference to the line available when the user has pressed Enter.
None
if no line has been received since the last line was returned def nb_input.NB_Input.get | ( | self | ) |
Get one line of characters which have been received through the serial device.
This method pops a line of text from the queue, so each line of text can only be gotten once.
None
if no lines are available