Skip to main content

Crate serialplugin_core

Crate serialplugin_core 

Source
Expand description

Serial port core of tauri-plugin-serialplugin, usable from plain Rust (no Tauri).

SerialManager owns every open port: one RX hub thread per port, watch streams with native framing ([events::WatchOptions::parser]), request/response exchange, queued AT commands, GSM 07.10 CMUX virtual channels, tcp://host:port bridges and (feature ble) Bluetooth LE serial. Events are delivered to an EventSink closure you pass to SerialManager::watch.

use serialplugin_core::{events::{SerialEvent, WatchOptions}, EventSink, SerialManager};
use std::sync::Arc;

let serial = SerialManager::new();
let path = serial.open("/dev/ttyUSB0".into(), 115_200, None, None, None, None, None)?;
let sink: EventSink = Arc::new(|event| {
    if let SerialEvent::Data { data, .. } = event {
        println!("{}", String::from_utf8_lossy(&data));
    }
    true // keep the subscription
});
let watch_id = serial.watch(path.clone(), WatchOptions::default(), sink)?;
let reply = serial.at(path.clone(), "AT+CSQ".into(), None)?;
println!("{:?}", reply.status);
serial.unwatch(watch_id)?;
serial.close(path)?;

Re-exports§

pub use api::SerialManager;
pub use error::Error;
pub use events::EventSink;
pub use events::PortListSink;

Modules§

api
SerialManager and the helpers it routes exchanges through.
at
AT command parsing, session config, and high-level command orchestration.
cmux
GSM 07.10 CMUX (virtual serial channels over one physical port).
error
events
Streaming event types, event sinks and watch / exchange options.
exchange
Low-level request/response exchange (physical port + CMUX), without Tauri.
hub
RX hub layer (shared state + poll loop on all platforms).
logger
Logging macros that respect the global log level (state::set_log_level). Centralized logging module for the serial plugin
mock_serial
Shared desktop serial port mock for unit tests (scripted RX, TX capture, error injection).
port
Port enumeration, monitoring, TX queue, and watch registry.
state
State types and enums for serial port configuration.
sync_util
Mutex helpers for background threads (recover from poison instead of panicking).

Macros§

log_debug
Logs a debug message if the current log level permits
log_error
Logs an error message if the current log level permits
log_info
Logs an info message if the current log level permits
log_warn
Logs a warning message if the current log level permits