API referenceVetraGlove ProPython

Reading data

Channels & subscriptions

Current version · 2.0.0

A read-only data channel returned by a device or Skeleton data accessor. Samples use the Sample wrapper.

ReadChannel[T].latest()

Reads the most recent piece of data without waiting.

Type

ReadChannel.latest() -> Sample[T] | None

Returns

Sample[T] | None. See Sample[T].

Details

  • Call conditions: The owning object is not closed.
  • Does not wait for new data; returns an empty value when no sample exists.

Each call reads the snapshot currently retained by the channel; it does not wait for the next frame. Use next() to wait once, or subscribe() to process data continuously.

Errors

  • Close errors.

Example

These snippets use an already selected device.

sample = device.pose().latest()
if sample is not None:
    print(sample.sequence, sample.value)

Complete example: subscription_config.py.

ReadChannel[T].subscribe()

Executes the callback each time new data is received.

Type

ReadChannel.subscribe(callback: Callable[[Sample[T]], object]) -> Subscription

Parameters

  • callback: Callable[[Sample[T]], object], required

Returns

Subscription.

Details

  • Call conditions: Recommended to register before start.

The callback receives a Sample[T]; sample.value holds the actual data. Keep callbacks short, and do not synchronously unsubscribe from inside that subscription’s callback.

Errors

  • Parameter or close errors.

Example

These snippets use an already selected device. Register the subscription before starting the device.

def on_pose(sample):
    print(sample.sequence, sample.value)

subscription = device.pose().subscribe(on_pose)

Complete example: subscription_config.py.

ReadChannel[T].next()

Asynchronously wait for the next sample.

Type

async ReadChannel.next() -> Sample[T]

Returns

Sample[T]. See Sample[T].

Details

  • Call conditions: While the owning object is running.
  • Asynchronously waits for one Sample[T] and can be cancelled. Use async for for continuous reading.

Errors

  • Cancellation, close or data stream errors.

Example

Start the owning device first, then call this async function from an asyncio application.

async def read_once(channel):
    sample = await channel.next()
    print(sample.sequence, sample.value)

Complete example: async_runtime.py.

ReadChannel[T].__aiter__()

Read new samples through asynchronous iteration.

Type

ReadChannel.__aiter__() -> AsyncIterator[Sample[T]]

Returns

AsyncIterator[Sample[T]]. See Sample[T].

Example

Start the owning device first, then call this async function from an asyncio application.

async def read_samples(channel):
    async for sample in channel:
        print(sample.sequence, sample.value)

Complete example: async_runtime.py.

ReadChannel[T].with_config()

Create a channel view with a subscription delivery policy.

Type

ReadChannel.with_config(config: SubscriptionConfig) -> ReadChannel[T]

Parameters

  • config: SubscriptionConfig, required

Returns

ReadChannel[T]. See ReadChannel[T].

Details

  • Call conditions: Before subscribe() or async iteration.
  • Returns a new read view sharing the same source; leaves the original channel, existing subscriptions, and computation rates unchanged.

The configuration affects only subsequent subscribe() calls and async iteration on that view. It leaves latest() and one-shot next() unchanged.

Errors

  • Parameter or close errors.

Example

These snippets use an already selected device. on_pose is an application-defined callback.

from qnbot_sdk import SubscriptionConfig

pose = device.pose().with_config(
    SubscriptionConfig.latest(max_rate_hz=30)
)
subscription = pose.subscribe(on_pose)

Complete example: subscription_config.py.