pub fn clear_buffer<R: Runtime>(
_app: AppHandle<R>,
serial: State<'_, SerialPort<R>>,
path: String,
buffer_type: ClearBuffer,
) -> Result<(), Error>
Expand description
Clears the specified buffer of the serial port
Clears either the input buffer, output buffer, or both buffers of the serial port. This is useful for removing stale data.
§Arguments
_app
- The Tauri app handleserial
- The serial port statepath
- The path to the serial port (e.g., “COM1”, “/dev/ttyUSB0”)buffer_type
- The type of buffer to clear (Input, Output, or Both)
§Returns
Ok(())
if the buffer was cleared successfully, or an Error
if it failed.
§Example
use tauri_plugin_serialplugin::commands::clear_buffer;
use tauri_plugin_serialplugin::state::ClearBuffer;
use tauri::{AppHandle, State};
#[tauri::command]
async fn clear_input_buffer(
app: AppHandle<tauri::Wry>,
serial: State<'_, tauri_plugin_serialplugin::desktop_api::SerialPort<tauri::Wry>>
) -> Result<(), String> {
clear_buffer(app, serial, "COM1".to_string(), ClearBuffer::Input)
.map_err(|e| e.to_string())
}
§JavaScript Equivalent
import { SerialPort, ClearBuffer } from "tauri-plugin-serialplugin-api";;
const port = new SerialPort({ path: "COM1" });
await port.open();
await port.clearBuffer(ClearBuffer.Input);