Medius - Rust LibraryAsync

Async

AsyncDevice on any executor

AsyncDevice is Device with its queries as futures, behind the off-by-default async flag.

cargo add medius --features async

Reply waits use flume, so futures run under any executor, no tokio.

cargo add futures

Result is the fallible return type (see Errors).

See also: call kinds & timeouts, concurrency, testing.

Constructing an AsyncDevice

open, find, into_async, into_inner
fn open(path: impl AsRef<Path>) -> Result<AsyncDevice>

Blocks

fn find() -> Result<AsyncDevice>

Blocks

fn into_async(self) -> AsyncDevice

No round-trip

fn into_inner(self) -> Device

No round-trip

CONSTRUCTORS
ConstructorDescription
openTakes a serial-port path, opens it, and runs the handshake. It blocks like Device::open, then hands back an AsyncDevice.
findDiscovers the first medius box by USB id, opens it, and runs the handshake. Blocks like Device::find, then hands back an AsyncDevice.
into_asyncReinterprets an already-open Device as an AsyncDevice. It's zero-cost over the same Link core, no new connection.
into_innerHands the sync Device back.
EXAMPLE
// discover and open in one call (runs the handshake, blocks)
let device = AsyncDevice::find()?;

// or by path:
let device = AsyncDevice::open("/dev/ttyACM0")?;

// or reinterpret an already-open Device:
let device = Device::find()?.into_async();

Everything else on Device is mirrored on AsyncDevice and stays synchronous, including counters, logs, reapply, and reconnect. Only the queries are futures.

Awaiting a query

every query method is a future
async fn query_version(&self) -> Result<Version>

Blocks

async fn query_health(&self) -> Result<Health>

Blocks

Each future awaits the correlated RESP with the default timeout, then resolves to its struct.

RETURNS
MethodResolves toDescription
query_version().awaitVersionFirmware identity.
query_health().awaitHealthWhether the box is wired and ready.

Two shown; the rest (device_info, caps, query_rate, query_stats, query_locks, query_catch) resolve the same way. The full list is on Requests.

.await is only legal inside an async function or block.

EXAMPLE
async fn run(device: &AsyncDevice) -> medius::Result<()> {
    let v = device.query_version().await?;
    let h = device.query_health().await?;
    println!("{v}, link_up={}", h.link_up);
    Ok(())
}