serialplugin_core/lib.rs
1//! Serial port core of `tauri-plugin-serialplugin`, usable from plain Rust (no Tauri).
2//!
3//! [`SerialManager`] owns every open port: one RX hub thread per port, watch streams
4//! with native framing ([`events::WatchOptions::parser`]), request/response
5//! [`exchange`](SerialManager::exchange), queued AT commands, GSM 07.10 CMUX virtual
6//! channels, `tcp://host:port` bridges and (feature `ble`) Bluetooth LE serial.
7//! Events are delivered to an [`EventSink`] closure you pass to
8//! [`SerialManager::watch`].
9//!
10//! ```no_run
11//! use serialplugin_core::{events::{SerialEvent, WatchOptions}, EventSink, SerialManager};
12//! use std::sync::Arc;
13//!
14//! let serial = SerialManager::new();
15//! let path = serial.open("/dev/ttyUSB0".into(), 115_200, None, None, None, None, None)?;
16//! let sink: EventSink = Arc::new(|event| {
17//! if let SerialEvent::Data { data, .. } = event {
18//! println!("{}", String::from_utf8_lossy(&data));
19//! }
20//! true // keep the subscription
21//! });
22//! let watch_id = serial.watch(path.clone(), WatchOptions::default(), sink)?;
23//! let reply = serial.at(path.clone(), "AT+CSQ".into(), None)?;
24//! println!("{:?}", reply.status);
25//! serial.unwatch(watch_id)?;
26//! serial.close(path)?;
27//! # Ok::<(), serialplugin_core::error::Error>(())
28//! ```
29
30/// Logging macros that respect the global log level ([`state::set_log_level`]).
31pub mod logger;
32
33#[cfg(any(test, target_os = "android"))]
34mod jni_ready;
35
36#[cfg(target_os = "android")]
37pub mod android;
38pub mod api;
39pub mod at;
40pub mod cmux;
41pub mod error;
42pub mod events;
43pub mod exchange;
44pub mod hub;
45pub mod port;
46pub mod state;
47pub mod sync_util;
48
49#[cfg(target_os = "ios")]
50#[path = "serialport_ios.rs"]
51pub mod serialport;
52
53#[cfg(any(not(target_os = "android"), debug_assertions))]
54pub mod mock_serial;
55
56pub use api::SerialManager;
57pub use error::Error;
58pub use events::{EventSink, PortListSink};