This repository has been archived on 2026-08-31. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
donglora/examples/all_commands.py
T
swaits 1fbbf110bc feat: GetMac command + MacAddress response
New protocol command (tag 8): GetMac returns the board's 6-byte hardware
address. Useful when multiple dongles are connected to one host.

Response (tag 6): MacAddress containing 6 raw bytes.

Updated: PROTOCOL.md, CHANGELOG, donglora.py decoder, all_commands.py.
2026-03-30 09:08:59 -06:00

55 lines
1.3 KiB
Python
Executable File

#!/usr/bin/env python3
"""Exercise every DongLoRa command to verify the API works.
Usage:
uv run examples/all_commands.py [PORT]
"""
# /// script
# requires-python = ">=3.10"
# dependencies = ["cobs", "pyserial"]
# ///
import serial
import sys
sys.path.insert(0, __import__("pathlib").Path(__file__).parent.as_posix())
import donglora as dl # noqa: E402
try:
ser = dl.connect(sys.argv[1] if len(sys.argv) > 1 else None)
print("── Ping ──")
print(dl.send(ser, "Ping"))
print("\n── SetConfig ──")
print(dl.send(ser, "SetConfig", config=dl.DEFAULT_CONFIG))
print("\n── GetConfig ──")
print(dl.send(ser, "GetConfig"))
print("\n── StartRx ──")
print(dl.send(ser, "StartRx"))
print("\n── StopRx ──")
print(dl.send(ser, "StopRx"))
print("\n── Transmit ──")
print(dl.send(ser, "Transmit", payload=b"Hello from all_commands.py!"))
print("\n── DisplayOff ──")
print(dl.send(ser, "DisplayOff"))
print("\n── DisplayOn ──")
print(dl.send(ser, "DisplayOn"))
print("\n── GetMac ──")
print(dl.send(ser, "GetMac"))
print("\nAll 9 commands exercised successfully.")
except KeyboardInterrupt:
print("\nInterrupted.")
except serial.SerialException as e:
print(f"\nSerial error: {e}", file=sys.stderr)
sys.exit(1)