Skip to content

Latest commit

 

History

History
26 lines (18 loc) · 806 Bytes

GenericHub.md

File metadata and controls

26 lines (18 loc) · 806 Bytes

Generic Powered Up Hub

Connecting to Hub via Bluetooth

Accessing Peripherals

Sending and Receiving Low-Level Messages

Hub.send(msg) add_message_handler

Use Disconnect in finally

It is recommended to make sure disconnect() method is called on connection object after you have finished your program. This ensures Bluetooth subsystem is cleared and avoids problems for subsequent re-connects of MoveHub. The best way to do that in Python is to use try ... finally clause:

from pylgbst import get_connection_auto
from pylgbst.hub import Hub

conn = get_connection_auto()  # ! don't put this into `try` block
try:
    hub = Hub(conn)
finally:
    conn.disconnect()

Additionally, hub has Hub.disconnect() and Hub.switch_off() methods to call corresponding commands.