pub fn close<R: Runtime>(
_app: AppHandle<R>,
serial: State<'_, SerialPort<R>>,
path: String,
) -> Result<(), Error>
Expand description
Closes a serial port
Closes the specified serial port and releases all associated resources. The port must be open before it can be closed.
§Arguments
_app
- The Tauri app handleserial
- The serial port statepath
- The path to the serial port (e.g., “COM1”, “/dev/ttyUSB0”)
§Returns
Ok(())
if the port was closed successfully, or an Error
if it failed.
§Example
use tauri_plugin_serialplugin::commands::close;
use tauri::{AppHandle, State};
#[tauri::command]
async fn close_serial_port(
app: AppHandle<tauri::Wry>,
serial: State<'_, tauri_plugin_serialplugin::desktop_api::SerialPort<tauri::Wry>>
) -> Result<(), String> {
close(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.close();