pub fn bytes_to_read<R: Runtime>(
_app: AppHandle<R>,
serial: State<'_, SerialPort<R>>,
path: String,
) -> Result<u32, Error>
Expand description
Gets the number of bytes available to read from the serial port
Returns the number of bytes that are currently available in the input buffer and ready to be read.
§Arguments
_app
- The Tauri app handleserial
- The serial port statepath
- The path to the serial port (e.g., “COM1”, “/dev/ttyUSB0”)
§Returns
The number of bytes available to read, or an Error
if it failed.
§Example
use tauri_plugin_serialplugin::commands::bytes_to_read;
use tauri::{AppHandle, State};
#[tauri::command]
async fn check_available_data(
app: AppHandle<tauri::Wry>,
serial: State<'_, tauri_plugin_serialplugin::desktop_api::SerialPort<tauri::Wry>>
) -> Result<(), String> {
let available = bytes_to_read(app, serial, "COM1".to_string())
.map_err(|e| e.to_string())?;
println!("{} bytes available to read", available);
Ok(())
}
§JavaScript Equivalent
import { SerialPort } from "tauri-plugin-serialplugin-api";;
const port = new SerialPort({ path: "COM1" });
await port.open();
const available = await port.bytesToRead();
console.log(`${available} bytes available to read`);