Code Monkey home page Code Monkey logo

tauri-plugin-serialport's Introduction

Tauri Plugin serialport

This plugin is based on the plugin developped by lzhida. https://github.com/lzhida/tauri-plugin-serialport.

A lot of the API is similar, but it differs on few aspects:

  • It should be used with tauri v2 and is incompatible withe tauri v1
  • It uses the structures from serialport-rs and does not implement custom structures
  • Chinese comment or messages have been translated or removed.
  • It includes additional features:
    • Possibility to set DTR (for some CDC devices such as Raspberry pico)
    • list_available_ports returns a rich structure including vid, pid, serial number
    • The reading section has been reworked so that it can read long messages before sending them to the frontend resulting overall on faster read time

Why another tauri serial plugin ?

There are two other repo for a tauri serial plugin on github:

The first one is the one I forked initially, it was not compatible with tauri v2 and it was missing some features I needed (serial port details when listing them and support for DTR). The second one is very similar to the one lzhida developped but with updated dependencies and translated messages.

I reworked the source code to simplify the plugin, make it compatible with tauri v2 and added a few features.

Installation

There are three general methods of installation that we can recommend.

  1. Pull sources directly from Github using git tags / revision hashes (most secure, good for developement, shown below)
  2. Git submodule install this repo in your tauri project and then use file protocol to ingest the source
  3. Use crates.io and npm (easiest, and requires you to trust that our publishing pipeline worked)

For more details and usage see the example app. Please note, below in the dependencies you can also lock to a revision/tag in both the Cargo.toml and package.json

Rust

src-tauri/Cargo.toml

[dependencies.tauri-plugin-serialport]
git = "https://github.com/eleroy/tauri-plugin-serialport"
version = "v0.1.0"

Use in src-tauri/src/main.rs:

use tauri_plugin_serialport;

fn main() {
    tauri::Builder::default()
        .plugin(tauri_plugin_serialport::init())
        .build()
        .run();
}

JS

npm install https://github.com/eleroy/tauri-plugin-serialport
# or
yarn add https://github.com/eleroy/tauri-plugin-serialport

USAGE

Use within your JS/TS:

import { SerialPort } from 'tauri-plugin-serialport-api';
const availablePorts = await SerialPort.available_ports()
console.log(availablePorts)
const serialPort = new SerialPort(
  {
    path: availablePorts[0].port_name, 
    baudRate:115200, 
    dtr:true
  })
await serialPort.open()
await serialPort.read({timeout:10})
serialPort.listen((data) => console.log(data), decode=true)
await serialPort.write("Hello world")

tauri-plugin-serialport's People

Contributors

eleroy avatar lzhida avatar dependabot[bot] avatar

Stargazers

剧终 avatar

Watchers

Lucian avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.