pub fn read_carrier_detect<R: Runtime>(
_app: AppHandle<R>,
serial: State<'_, SerialPort<R>>,
path: String,
) -> Result<bool, Error>
Expand description
Reads the CD (Carrier Detect) control signal state
Reads the current state of the CD signal line. This signal indicates whether a carrier signal is being received (commonly used with modems).
§Arguments
_app
- The Tauri app handleserial
- The serial port statepath
- The path to the serial port (e.g., “COM1”, “/dev/ttyUSB0”)
§Returns
The CD signal state (true for high, false for low), or an Error
if it failed.
§Example
use tauri_plugin_serialplugin::commands::read_carrier_detect;
use tauri::{AppHandle, State};
#[tauri::command]
async fn check_carrier(
app: AppHandle<tauri::Wry>,
serial: State<'_, tauri_plugin_serialplugin::desktop_api::SerialPort<tauri::Wry>>
) -> Result<(), String> {
let cd_state = read_carrier_detect(app, serial, "COM1".to_string())
.map_err(|e| e.to_string())?;
println!("Carrier detect is: {}", if cd_state { "active" } else { "inactive" });
Ok(())
}
§JavaScript Equivalent
import { SerialPort } from "tauri-plugin-serialplugin-api";;
const port = new SerialPort({ path: "COM1" });
await port.open();
const cdState = await port.readCarrierDetect();
console.log("Carrier detect is:", cdState ? "active" : "inactive");