Python
Das Python-Paket blickfeld_qb2 ist vorgefertigt auf PyPI verfügbar.
Es liefert Punktwolken als NumPy-Arrays, ohne die Daten zu kopieren, schnell genug, um sie live zu streamen und zu verarbeiten.
Mit dem Sensor verbinden
Der Channel öffnet eine verschlüsselte gRPC-Verbindung zum Hostnamen oder zur IP-Adresse des Sensors. Die TokenFactory meldet sich mit einem Anwendungsschlüssel an.
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
|
Erstellen Sie zuerst einen Anwendungsschlüssel.
Ersetzen Sie im Beispiel Ist der Anwendungsschlüssel ungültig, schlägt der erste API-Aufruf auf dem Kanal mit dem gRPC-Statuscode 5, |
Übergeben Sie zusätzlich die serial_number des Sensors, um zu prüfen, dass sich der Kanal genau mit diesem Sensor verbindet. Ohne sie prüft der Kanal nur, dass er sich mit einem Blickfeld-Gerät verbindet.
|
Anfrage senden
Dieses Beispiel liest die Firmware-Version mit get_status() des Dienstes Firmware in blickfeld_qb2.system.services.
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)
Jede Antwort ist ein Objekt mit verschachtelten Objekten, wie in der API-Referenz definiert. Ein Kanal bedient beliebig viele Anfragen. Ausgabe, ein Feld pro Zeile:
FirmwareInfo(
label='HENNING v3.2.4',
version=Version(major=3, minor=2, patch=4, revision='d1c2d249'),
allowed_downgrade_version=Version(major=3, patch=11)
)
Die Version einer freigegebenen Firmware zeigt zusätzlich is_release=True.
Anfragen asynchron senden
Die asynchrone Variante jeder Methode hat das Präfix 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())
Ausgabe, ein Feld pro Zeile:
FirmwareInfo(
label='HENNING v3.2.4',
version=Version(major=3, minor=2, patch=4, revision='d1c2d249'),
allowed_downgrade_version=Version(major=3, patch=11)
)