pub fn read_data_set_ready<R: Runtime>(
_app: AppHandle<R>,
serial: State<'_, SerialPort<R>>,
path: String,
) -> Result<bool, Error>
Expand description
Reads the DSR (Data Set Ready) control signal state
Reads the current state of the DSR signal line. This signal indicates whether the remote device (modem) is ready for communication.
§Arguments
_app
- The Tauri app handleserial
- The serial port statepath
- The path to the serial port (e.g., “COM1”, “/dev/ttyUSB0”)
§Returns
The DSR signal state (true for high, false for low), or an Error
if it failed.
§Example
use tauri_plugin_serialplugin::commands::read_data_set_ready;
use tauri::{AppHandle, State};
#[tauri::command]
async fn check_dsr(
app: AppHandle<tauri::Wry>,
serial: State<'_, tauri_plugin_serialplugin::desktop_api::SerialPort<tauri::Wry>>
) -> Result<(), String> {
let dsr_state = read_data_set_ready(app, serial, "COM1".to_string())
.map_err(|e| e.to_string())?;
println!("DSR signal is: {}", if dsr_state { "high" } else { "low" });
Ok(())
}
§JavaScript Equivalent
import { SerialPort } from "tauri-plugin-serialplugin-api";;
const port = new SerialPort({ path: "COM1" });
await port.open();
const dsrState = await port.readDataSetReady();
console.log("DSR signal is:", dsrState ? "high" : "low");