set_break

Function set_break 

Source
pub fn set_break<R: Runtime>(
    _app: AppHandle<R>,
    serial: State<'_, SerialPort<R>>,
    path: String,
) -> Result<(), Error>
Expand description

Sets the break condition on the serial port

Activates the break condition, which holds the transmit line low for a period longer than a character time. This is often used to signal special conditions or reset devices.

§Arguments

  • _app - The Tauri app handle
  • serial - The serial port state
  • path - The path to the serial port (e.g., “COM1”, “/dev/ttyUSB0”)

§Returns

Ok(()) if the break condition was set successfully, or an Error if it failed.

§Example

use tauri_plugin_serialplugin::commands::set_break;
use tauri::{AppHandle, State};
 
#[tauri::command]
async fn activate_break(
    app: AppHandle<tauri::Wry>,
    serial: State<'_, tauri_plugin_serialplugin::desktop_api::SerialPort<tauri::Wry>>
) -> Result<(), String> {
    set_break(app, serial, "COM1".to_string())
        .map_err(|e| e.to_string())
}

§JavaScript Equivalent

import { SerialPort } from "tauri-plugin-serialplugin-api";;
 
const port = new SerialPort({ path: "COM1" });
await port.open();
await port.setBreak();