Async
AsyncDevice is Device with its queries as futures, behind the off-by-default async feature.
cargo add medius --features asyncReply waits use flume, so futures run under any executor, without tokio.
cargo add futuresResult is the fallible return type.
See also: call kinds & timeouts, concurrency, testing.
Constructionopen, 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
| Name | Description |
|---|---|
open | Opens a serial-port path and runs the handshake, blocking like Device::open. |
find | Opens the first Medius box by USB id and runs the handshake, blocking like Device::find. |
into_async | Reinterprets an open Device at zero cost, over the same Link core. No new connection. |
into_inner | Returns the sync Device. |
EXAMPLE
// find, open and handshake (blocks)
let device = AsyncDevice::find()?;
// or by path:
let device = AsyncDevice::open("/dev/ttyACM0")?;
// or reinterpret an open Device:
let device = Device::find()?.into_async();QueriesEvery 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
| Method | Resolves to | Description |
|---|---|---|
query_version().await | Version | Firmware identity. |
query_health().await | Health | Whether the box is wired and ready. |
Every other query resolves the same way. The full list is on Requests.
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(())
}