SerialManager()
Main class to establish and manage Serial connection with Bittle.
Attributes
port (str): Serial communication port.
baudrate (int): Baud rate.
timeout (int): Serial communication timeout in seconds.
parity (int): Serial communication parity, possible values: none, odd, even.
serial (serial.Serial): Serial communication instance.
Methods
initialize(): Sets serial communication parameters (port, baudrate, timeout and parity). If any of the parameters is updated after initialization, this method must be called to apply the changes.
discover_port(): Searches among avaliable communication ports the one associated to CH340 USB driver, which is used by Bittle. Returns True if found, False otherwise.
connect(): Starts serial communication, connects to Bittle and wait until full handshake is done (Bittle will send a response containing "Finished!" string at the end). Return True if connected successfully, False otherwise.
close_connection(): Closes serial communication.
send_msg(msg): Sends passed msg parameter (str) message to Bittle.
recv_msg(): Returns received message from Bittle (byte).
Example
The following example shows the complete process of searching, connecting and sending messages to Bittle through Serial connection.
Last updated