/      日本語

Flashing Firmware with Python

Latest Edition

Overview

The tweliter module is a Python module for flashing firmware to TWELITE devices.

It can be installed from PyPI, used as a command-line tool, or controlled from Python scripts.

Installation

Install it from PyPI:


pip install tweliter

With Poetry:


poetry add tweliter

Additional Notes for Linux

Additional Notes for Windows

Examples

As a Command-Line Tool

Specify a .bin binary file after tweliter.


tweliter dir/SomeApp_BLUE.bin

From a Script

Use an instance of the Tweliter class.

from pathlib import Path
from tweliter import Tweliter

file = Path("firmware/SomeApp_BLUE.bin")

try:
    with Tweliter(
        type_filter=Tweliter.Type.TWELITE_R2 | Tweliter.Type.TWELITE_R3
    ) as liter:
        # Get serial interface
        ser = liter.get_serial_instance()
        # Write firmware
        liter.write(ser, file, verify=True)
        # Show startup message
        print(liter.get_startup_message_after(ser, "!INF"))
except IOError as e:
    print(f"Couldn't connect {e}")
except RuntimeError as e:
    print(f"Failed to write {e}")