set_flow_control

Function set_flow_control 

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

Sets the flow control mode for a serial port

Changes the flow control method used by the serial port. Flow control prevents data loss by allowing the receiver to signal when it’s ready to receive more data.

§Arguments

  • _app - The Tauri app handle
  • serial - The serial port state
  • path - The path to the serial port (e.g., “COM1”, “/dev/ttyUSB0”)
  • flow_control - The flow control mode (None, Software, or Hardware)

§Returns

Ok(()) if the flow control was set successfully, or an Error if it failed.

§Example

use tauri_plugin_serialplugin::commands::set_flow_control;
use tauri_plugin_serialplugin::state::FlowControl;
use tauri::{AppHandle, State};
 
#[tauri::command]
async fn configure_flow_control(
    app: AppHandle<tauri::Wry>,
    serial: State<'_, tauri_plugin_serialplugin::desktop_api::SerialPort<tauri::Wry>>
) -> Result<(), String> {
    set_flow_control(app, serial, "COM1".to_string(), FlowControl::None)
        .map_err(|e| e.to_string())
}

§JavaScript Equivalent

import { SerialPort, FlowControl } from "tauri-plugin-serialplugin-api";;
 
const port = new SerialPort({ path: "COM1" });
await port.open();
await port.setFlowControl(FlowControl.None);