Section
Getting Started
API
Features
Guides
Reference
AI Access
Async
AsyncDevice on any executorAsyncDevice is Device with its queries as futures, behind the off-by-default async flag.
cargo add medius --features asyncReply waits use flume, so futures run under any executor, no tokio.
cargo add futuresResult is the fallible return type (see Errors).
See also: call kinds & timeouts, concurrency, testing.
Constructing an AsyncDevice
open, find, into_async, into_innerfn 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
| Constructor | Description |
|---|---|
open | Takes a serial-port path, opens it, and runs the handshake. It blocks like Device::open, then hands back an AsyncDevice. |
find | Discovers the first medius box by USB id, opens it, and runs the handshake. Blocks like Device::find, then hands back an AsyncDevice. |
into_async | Reinterprets an already-open Device as an AsyncDevice. It's zero-cost over the same Link core, no new connection. |
into_inner | Hands 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();Awaiting a query
every query method is a futureasync 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
| Method | Resolves to | Description |
|---|---|---|
query_version().await | Version | Firmware identity. |
query_health().await | Health | Whether 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(())
}