cancel_read

Function cancel_read 

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

Cancels ongoing read operations on a serial port

Stops any active read operations on the specified port. This is useful for interrupting long-running read operations or cleaning up resources.

§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 read operation was cancelled successfully, or an Error if it failed.

§Example

use tauri_plugin_serialplugin::commands::cancel_read;
use tauri::{AppHandle, State};
 
#[tauri::command]
async fn stop_reading(
    app: AppHandle<tauri::Wry>,
    serial: State<'_, tauri_plugin_serialplugin::desktop_api::SerialPort<tauri::Wry>>
) -> Result<(), String> {
    cancel_read(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.cancelListen();