Medius - Rust LibraryConnection

Connecting

Open, find, and hand the box back

A Medius box bridges a mouse and a PC over USB-serial. The medius crate is the Rust client and Device is the handle; opening one finds the box, runs the handshake, and starts the background threads in one call.

See also: choosing a port, threading, keepalive & teardown, and the box handshake.

Open a device

Auto-detect, or a path you already have
fn Device::open(path: impl AsRef<Path>) -> Result<Device>

Blocks

fn Device::find() -> Result<Device>

Blocks

fn Device::find_medius() -> Vec<PortInfo>

No round-trip

open and find block on the handshake. Auto-detect matches on USB identity (vid 0x1A86, pid 0x55D3), the WCH CH343 bridge in every box.

FUNCTIONS
FunctionDescription
openOpens a serial path you already have (Linux /dev/ttyACM0, Windows COM3).
findOpens the first matching port, or returns Error::NotFound.
find_mediusLists every match as a PortInfo without opening one.
EXAMPLE
use medius::Device;

// auto-detect the box:
let dev = Device::find()?;

// or, open a path you already know:
let dev = Device::open("/dev/ttyACM0")?;

Zero config

No settings struct, just two defaults

Nothing to configure; two read-only defaults bound the QUERY wait and keepalive timer.

ConstantValue
DEFAULT_QUERY_TIMEOUT1 s
DEFAULT_KEEPALIVE_CADENCE500 ms
EXAMPLE
use medius::{DEFAULT_QUERY_TIMEOUT, DEFAULT_KEEPALIVE_CADENCE};

println!("query timeout:     {:?}", DEFAULT_QUERY_TIMEOUT);   // 1s
println!("keepalive cadence: {:?}", DEFAULT_KEEPALIVE_CADENCE); // 500ms

Async device

The same link, with awaitable queries
fn AsyncDevice::open(path: impl AsRef<Path>) -> Result<AsyncDevice>

Blocks

fn AsyncDevice::find() -> Result<AsyncDevice>

Blocks

fn into_async(self) -> AsyncDevice

No round-trip

fn into_inner(self) -> Device

No round-trip

Behind the async feature, AsyncDevice turns the reply-reading queries into futures; the fire-and-forget calls stay synchronous. Construct one with AsyncDevice::find, open by path, or into_async; full surface on the async feature page.

cargo add medius --features async
EXAMPLE
use futures::executor::block_on;
use medius::AsyncDevice;

// discover and open directly as async:
let dev = AsyncDevice::find()?;
let version = block_on(dev.query_version())?; // awaits the reply
dev.move_rel(10, 0)?;                          // fire-and-forget, stays sync

// or open a path you already have:
let dev = AsyncDevice::open("/dev/ttyACM0")?;