pub fn set_data_bits<R: Runtime>(
_app: AppHandle<R>,
serial: State<'_, SerialPort<R>>,
path: String,
data_bits: DataBits,
) -> Result<(), Error>
Expand description
Sets the number of data bits for a serial port
Changes the number of data bits per character. Most modern applications use 8 data bits, but some legacy systems may use 7 bits.
§Arguments
_app
- The Tauri app handleserial
- The serial port statepath
- The path to the serial port (e.g., “COM1”, “/dev/ttyUSB0”)data_bits
- The number of data bits (Five, Six, Seven, or Eight)
§Returns
Ok(())
if the data bits were set successfully, or an Error
if it failed.
§Example
use tauri_plugin_serialplugin::commands::set_data_bits;
use tauri_plugin_serialplugin::state::DataBits;
use tauri::{AppHandle, State};
#[tauri::command]
async fn configure_data_bits(
app: AppHandle<tauri::Wry>,
serial: State<'_, tauri_plugin_serialplugin::desktop_api::SerialPort<tauri::Wry>>
) -> Result<(), String> {
set_data_bits(app, serial, "COM1".to_string(), DataBits::Eight)
.map_err(|e| e.to_string())
}
§JavaScript Equivalent
import { SerialPort, DataBits } from "tauri-plugin-serialplugin-api";;
const port = new SerialPort({ path: "COM1" });
await port.open();
await port.setDataBits(DataBits.Eight);