/

Pythonによるファームウェアの書き込み

TWELITE のファームウェア書き込みを行うPythonモジュール(ベータ版)

概要

tweliter モジュールは、TWELITE のファームウェアを書き込むためのPythonモジュールです。

PyPIからインストールでき、コマンドラインツールとして使用できるほか、Pythonスクリプトから制御することもできます。

インストール方法

PyPIからインストールしてください。


pip install tweliter

Poetryなら


poetry add tweliter

Linux における追記事項

Windows における追記事項

使用例

コマンドラインツールとして

tweliter に続いて、バイナリファイル(.bin)を指定します。


tweliter dir/SomeApp_BLUE.bin

スクリプトから

Tweliteクラスのインスタンスを利用してください。

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}")