Python

このページは以前のファームウェアリリースについて説明しています。 このページを最新リリースで読む
このページは自動翻訳されたもので、まだレビューされていません。内容に相違がある場合は、英語の原文が優先されます。 英語の原文を読む

Pythonパッケージ blickfeld_qb2 は、ビルド済みのものが PyPIで入手できます。 ポイントクラウドをデータをコピーせずにNumPy配列として返すため、ライブストリーミングと処理にも十分な速度が得られます。

ライブラリをインストールする

pip install -U blickfeld_qb2
ライブラリをインポートする
import blickfeld_qb2

センサーに接続する

Channel は、センサーのホスト名またはIPアドレスへの暗号化されたgRPC接続を開きます。TokenFactory はアプリケーションキーでサインインします。

センサーへの暗号化および認証されたチャネル
import blickfeld_qb2

# Create token factory using an application key
token_factory = blickfeld_qb2.TokenFactory(
    application_key_secret="application-key-for-qb2-xxxxxxxxx"
)

# Open a secure & authenticated connection to the sensor
with blickfeld_qb2.Channel(
        fqdn_or_ip="qb2-xxxxxxxxx",
        token=token_factory
    ) as channel:
    # Call methods of services here
    # ..
    pass

まず アプリケーションキーを作成してください。 例の application-key-for-qb2-xxxxxxxxx をそのシークレットに、qb2-xxxxxxxxx をセンサーのホスト名またはIPアドレスに置き換えてください。

アプリケーションキーが無効な場合、チャネル上の最初のAPI呼び出しは gRPCステータスコード5、NOT_FOUNDで失敗します。

センサーの serial_number も渡すと、チャネルがその特定のセンサーに接続していることを確認できます。渡さない場合、チャネルはBlickfeldデバイスに接続していることのみを確認します。

リクエストを送信する

この例では、blickfeld_qb2.system.services の Firmware サービスの get_status() でファームウェアバージョンを読み取ります。

import blickfeld_qb2

# Create token factory using an application key
token_factory = blickfeld_qb2.TokenFactory(
    application_key_secret="application-key-for-qb2-xxxxxxxxx"
)

# Open a secure & authenticated connection to the sensor
with blickfeld_qb2.Channel(
        fqdn_or_ip="qb2-xxxxxxxxx",
        token=token_factory
    ) as channel:
    # Request the firmware status
    response = blickfeld_qb2.system.services.Firmware(channel).get_status()
    # Extract the firmware version
    firmware_version = response.status.installed_firmware_info
    # Print the firmware version
    print(firmware_version)

各レスポンスは、APIリファレンスで定義されているとおり、ネストされたオブジェクトを持つオブジェクトです。1つのチャネルで任意の数のリクエストを処理できます。出力(1行に1フィールド):

FirmwareInfo(
    label='HENNING v3.2.4',
    version=Version(major=3, minor=2, patch=4, revision='d1c2d249'),
    allowed_downgrade_version=Version(major=3, patch=11)
)

リリース済みファームウェアのバージョンには、is_release=Trueも表示されます。

リクエストを非同期で送信する

各メソッドの非同期版には、接頭辞 async_ が付いています。

import asyncio
import blickfeld_qb2

async def main():
    # Create token factory using an application key
    token_factory = blickfeld_qb2.TokenFactory(
        application_key_secret="application-key-for-qb2-xxxxxxxxx"
    )

    # Open a secure, authenticated & asynchronous connection to the sensor
    with blickfeld_qb2.Channel(
            fqdn_or_ip="qb2-xxxxxxxxx",
            token=token_factory
        ) as channel:
        # Request the firmware status asynchronously and await for the response
        response = await blickfeld_qb2.system.services.Firmware(channel).async_get_status()
        # Get the firmware version from the response
        firmware_version = response.status.installed_firmware_info
        # Print the firmware version
        print(firmware_version)

# run coroutine on the event loop
asyncio.run(main())

出力(1行に1フィールド):

FirmwareInfo(
    label='HENNING v3.2.4',
    version=Version(major=3, minor=2, patch=4, revision='d1c2d249'),
    allowed_downgrade_version=Version(major=3, patch=11)
)