Crates.io | tauri-plugin-serialport-v1 |
lib.rs | tauri-plugin-serialport-v1 |
version | 0.1.0 |
source | src |
created_at | 2024-04-18 07:14:35.923509 |
updated_at | 2024-04-18 07:14:35.923509 |
description | A tauri plugin developed based on Serialport. |
homepage | |
repository | |
max_upload_size | |
id | 1212208 |
size | 45,034 |
A tauri plugin developed based on Serialport.
src-tauri/Cargo.toml
tauri-plugin-serialport-v1 = "0.1.0"
Use in src-tauri/src/main.rs
:
use tauri_plugin_serialport_v1;
fn main() {
tauri::Builder::default()
.plugin(tauri_plugin_serialport_v1::init())
.build()
.run();
}
npm install @kuyoonjo/tauri-plugin-serialport-api@0.1.0
Use within your JS/TS:
import { Serialport } from 'tauri-plugin-serialport-api';
export interface SerialportInfo {
path: string;
info?: {
/** Vendor ID */
vid: number;
/** Product ID */
pid: number;
/** Serial number (arbitrary string) */
serialNumber?: string;
/** Manufacturer (arbitrary string) */
manufacturer?: string;
/** Product name (arbitrary string) */
product?: string;
};
}
export interface SerialportOptions {
path: string;
baudRate: number;
encoding?: string;
dataBits?: 5 | 6 | 7 | 8;
flowControl?: null | 'Software' | 'Hardware';
parity?: null | 'Odd' | 'Even';
stopBits?: 1 | 2;
timeout?: number;
size?: number;
[key: string]: any;
}
declare class Serialport {
isOpen: boolean;
encoding: string;
size: number;
constructor(options: SerialportOptions);
static available_ports(): Promise<SerialportInfo[]>;
static forceClose(path: string): Promise<void>;
static closeAll(): Promise<void>;
open(): Promise<void>;
close(): Promise<void>;
write(value: string): Promise<number>;
writeBinary(value: Uint8Array | number[]): Promise<number>;
read(options?: ReadOptions): Promise<void>;
cancelRead(): Promise<void>;
listen(fn: (data: string) => void, decodeAsString?: true): Promise<void>;
listen(fn: (data: number[]) => void, decodeAsString: false): Promise<void>;
cancelListen(): Promise<void>;
setBaudRate(value: number): Promise<void>;
setPath(value: string): Promise<void>;
change(options: {
path?: string;
baudRate?: number;
}): Promise<void>;
}