bytes_to_write

Function bytes_to_write 

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

Gets the number of bytes available to write to the serial port

Returns the number of bytes that can be written to the output buffer without blocking.

§Arguments

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

§Returns

The number of bytes available to write, or an Error if it failed.

§Example

use tauri_plugin_serialplugin::commands::bytes_to_write;
use tauri::{AppHandle, State};
 
#[tauri::command]
async fn check_write_buffer(
    app: AppHandle<tauri::Wry>,
    serial: State<'_, tauri_plugin_serialplugin::desktop_api::SerialPort<tauri::Wry>>
) -> Result<(), String> {
    let available = bytes_to_write(app, serial, "COM1".to_string())
        .map_err(|e| e.to_string())?;
    println!("{} bytes available to write", available);
    Ok(())
}

§JavaScript Equivalent

import { SerialPort } from "tauri-plugin-serialplugin-api";;
 
const port = new SerialPort({ path: "COM1" });
await port.open();
const available = await port.bytesToWrite();
console.log(`${available} bytes available to write`);