セクションの複数ページをまとめています。 印刷またはPDF形式で保存...

もとのページに戻る

2025-02-14 現在

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

TWELITE のファームウェア書き込みを行うPythonモジュール(ベータ版)
tweliter モジュールは、TWELITE のファームウェアを書き込むためのPythonモジュールです。PyPIからインストールでき、コマンドラインツールとして使用できるほか、Pythonスクリプトから制御することもできます。

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

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

概要

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

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

インストール方法

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


pip install tweliter

Poetryなら


poetry add tweliter

使用例

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

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


tweliter dir/SomeApp_BLUE.bin

スクリプトから

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

from pathlib import Path
from tweliter import Tweliter

file = Path('dir/SomeApp_BLUE.bin')

try:
    with Tweliter(url="ftdi://:ft-x:/1") as liter:
        # Get serial interface for communication
        ser = liter.get_serial_instance()

        # Reset and enter program mode
        liter.enter_program_mode()

        # Write firmware
        liter.write_firmware(ser, file)

        # Reset device to check startup message
        liter.reset_device()

        # Show startup message
        ser.read_until(b"!INF MONO WIRELESS") # wait for prefix
        line = ser.readline()
        print(line.decode("utf-8").strip())
except IOError as e:
    print(e)