Expand description
Commands module providing Tauri commands for serial port operations
This module contains all the Tauri commands that can be invoked from the frontend
to interact with serial ports. Each command is designed to be used with the
tauri::invoke
function or through the plugin’s JavaScript API.
§Examples
use tauri_plugin_serialplugin::commands;
use tauri::{AppHandle, State};
#[tauri::command]
async fn open_serial_port(
app: AppHandle<tauri::Wry>,
serial: State<'_, tauri_plugin_serialplugin::desktop_api::SerialPort<tauri::Wry>>
) -> Result<(), String> {
commands::open(app, serial, "COM1".to_string(), 9600, None, None, None, None, None)
.map_err(|e| e.to_string())
}
Command functions for serial port operations
This module contains all the Tauri command functions that can be used to interact with serial ports. These functions can be imported and used directly in your Rust code.
§Example
use tauri_plugin_serialplugin::commands::{available_ports, open, write, read, close};
use tauri_plugin_serialplugin::state::{DataBits, FlowControl, Parity, StopBits};
use tauri::{AppHandle, State};
#[tauri::command]
async fn my_serial_function(
app: AppHandle<tauri::Wry>,
serial: State<'_, tauri_plugin_serialplugin::desktop_api::SerialPort<tauri::Wry>>
) -> Result<(), String> {
// Get available ports
let ports = available_ports(app.clone(), serial.clone())
.map_err(|e| e.to_string())?;
// Open a port
open(app.clone(), serial.clone(), "COM1".to_string(), 9600, None, None, None, None, None)
.map_err(|e| e.to_string())?;
// Write data
write(app.clone(), serial.clone(), "COM1".to_string(), "Hello".to_string())
.map_err(|e| e.to_string())?;
// Read data
let data = read(app.clone(), serial.clone(), "COM1".to_string(), Some(1000), Some(1024))
.map_err(|e| e.to_string())?;
// Close port
close(app, serial, "COM1".to_string())
.map_err(|e| e.to_string())?;
Ok(())
}
Functions§
- available_
ports - Lists all available serial ports on the system
- available_
ports_ direct - Lists all available serial ports using platform-specific commands
- bytes_
to_ read - Gets the number of bytes available to read from the serial port
- bytes_
to_ write - Gets the number of bytes available to write to the serial port
- cancel_
read - Cancels ongoing read operations on a serial port
- clear_
break - Clears the break condition on the serial port
- clear_
buffer - Clears the specified buffer of the serial port
- close
- Closes a serial port
- close_
all - Closes all open serial ports
- force_
close - Forcefully closes a serial port
- managed_
ports - Lists all currently managed serial ports
- open
- Opens a serial port with the specified configuration
- read
- Reads string data from a serial port
- read_
binary - Reads binary data from a serial port
- read_
carrier_ detect - Reads the CD (Carrier Detect) control signal state
- read_
clear_ to_ send - Reads the CTS (Clear To Send) control signal state
- read_
data_ set_ ready - Reads the DSR (Data Set Ready) control signal state
- read_
ring_ indicator - Reads the RI (Ring Indicator) control signal state
- set_
baud_ rate - Sets the baud rate for a serial port
- set_
break - Sets the break condition on the serial port
- set_
data_ bits - Sets the number of data bits for a serial port
- set_
flow_ control - Sets the flow control mode for a serial port
- set_
parity - Sets the parity checking mode for a serial port
- set_
stop_ bits - Sets the number of stop bits for a serial port
- set_
timeout - Sets the read timeout for a serial port
- start_
listening - Starts listening for data on a serial port
- stop_
listening - Stops listening for data on a serial port
- write
- Writes string data to a serial port
- write_
binary - Writes binary data to a serial port
- write_
data_ terminal_ ready - Sets the DTR (Data Terminal Ready) control signal
- write_
request_ to_ send - Sets the RTS (Request To Send) control signal