'winrt IBuffer in Python
I am using winrt in python to read sensor data over Bluetooth. This returns a _winrt_Windows_Storage_Streams.IBuffer object. Does anyone know how to turn this into a nice python object?
Solution 1:[1]
Bleak is a cross-platform Bluetooth Low Energy client Python library that may be a better solution than using the Windows runtime APIs directly. It has a simplified API and already handles the conversion of IBuffer to bytearray.
Under the hood, Bleak uses bleak-winrt to provide Python bindings to the Windows SDK. These bindings are automatically generated using PyWinRT. These projects are based on the same code but have many improvements over the seemingly unmaintained winrt package from the xlang project.
The bleak-winrt bindings implement the Python buffer protocol for the IBuffer interface. So you can pass the IBuffer object directly to any Python API that uses the Python buffer protocol. For example, if the data is structured (as opposed to a stream), then struct.unpack() is probably quite useful in this case.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | David Lechner |
