serialplugin-core
The serial port core of tauri-plugin-serialplugin,
with no Tauri dependency. Use it from a plain Rust / tokio app (gateways, daemons,
CLIs) that talks to many ports at once; the Tauri plugin is a thin layer over it.
- One
SerialManagerowns every open port: local serial (serialport),tcp://host:portbridges,ble://…(featureble: desktop, iOS and Android) and, on Android, USB adapters through the plugin's JNI bridge. - One RX hub thread per port:
watchstreams, pollread, request/responseexchangeand queuedat/at_phases/send_sms_pdunever steal each other's bytes. URCs can be split out of the stream (WatchOptions::route_urc). - Native framing on watch (
SerialManager::watch_framed, theserial-codecparsers: readline, delimiter, SLIP, …): each frame is oneSerialEvent::Data. - GSM 07.10 CMUX:
enable_mux,open_mux_channelgive virtual ports (<path>#dlci=N) that take the same calls as physical ones.
Example
use ;
use SerialManager;
use Arc;
let serial = new;
let path = serial.open?;
// Called on the port's RX thread (the last remainder on unwatch / close may come on
// the caller's thread), never under a manager lock: keep it short (forward into a channel).
let sink: EventSink = new;
let parser = from_str.unwrap;
let watch_id = serial.watch_framed?;
let csq = serial.at?;
println!;
serial.unwatch?;
serial.close?;
# Ok::
cargo run -p serialplugin-core --example headless -- /dev/ttyUSB0 115200 prints every
line a port sends.
Methods block (open, read with a timeout, at): in async code call them through
tokio::task::spawn_blocking. SerialManager is cheap to clone; clones share the
ports. Port-list changes: watch_ports(options, sink) with a PortListSink.
License
Apache-2.0 OR MIT.