pub fn set_parity<R: Runtime>(
_app: AppHandle<R>,
serial: State<'_, SerialPort<R>>,
path: String,
parity: Parity,
) -> Result<(), Error>
Expand description
Sets the parity checking mode for a serial port
Changes the parity checking method used by the serial port. Parity is an error detection method that adds an extra bit to each character.
§Arguments
_app
- The Tauri app handleserial
- The serial port statepath
- The path to the serial port (e.g., “COM1”, “/dev/ttyUSB0”)parity
- The parity mode (None, Odd, or Even)
§Returns
Ok(())
if the parity was set successfully, or an Error
if it failed.
§Example
use tauri_plugin_serialplugin::commands::set_parity;
use tauri_plugin_serialplugin::state::Parity;
use tauri::{AppHandle, State};
#[tauri::command]
async fn configure_parity(
app: AppHandle<tauri::Wry>,
serial: State<'_, tauri_plugin_serialplugin::desktop_api::SerialPort<tauri::Wry>>
) -> Result<(), String> {
set_parity(app, serial, "COM1".to_string(), Parity::None)
.map_err(|e| e.to_string())
}
§JavaScript Equivalent
import { SerialPort, Parity } from "tauri-plugin-serialplugin-api";;
const port = new SerialPort({ path: "COM1" });
await port.open();
await port.setParity(Parity.None);