Giter VIP home page Giter VIP logo

node-serialport-bindings-webserial's Introduction

SUMMARY

NPM Version

WebSerial bindings for serialport module.

INSTALL

  1. Install module:
    npm i serialport-bindings-webserial
  2. Import a module into your code:
    import { SerialPortStream } from '@serialport/stream';
    import { WebSerialBinding } from 'serialport-bindings-webserial';

EXAMPLES

  1. List available and paired ports:

    let ports = await WebSerialBinding.list();
    console.log(ports);
  2. Open any port:

    The browser will show pop-up with all available ports.

    let port = await new SerialPortStream({
        binding: WebSerialBinding,
        path: 'webserial://any',
        baudRate: 115200
    });
  3. Open any port with custom options for SerialPort.open:

    The browser will show pop-up with all available ports.

    let webSerialOpenOptions = {
        bufferSize: 4 * 1024 // https://developer.mozilla.org/en-US/docs/Web/API/SerialPort/open#buffersize
    };
    
    let port = await new SerialPortStream({
        binding: WebSerialBinding,
        path: 'webserial://any',
        baudRate: 115200,
        webSerialOpenOptions
    });
  4. Open any port with filters:

    The browser will show pop-up with all available ports which fit the requested filter.

    let webSerialRequestOptions = {
        filters: [{ usbVendorId: 0x067B, usbProductId: 0x2303 }]
    };
    
    let port = await new SerialPortStream({
        binding: WebSerialBinding,
        path: 'webserial://any',
        baudRate: 115200,
        webSerialRequestOptions
    });
  5. Open with native SerialPort:

    You can open a port using reference to the native SerialPort object.

    let webSerialPort = await navigator.requestPort({});
    
    let port = new SerialPortStream({
        binding: WebSerialBinding,
        path: 'webserial://any',
        baudRate: 115200,
        webSerialPort
    });
  6. Open port by virtual path:

    let ports = await WebSerialBinding.list();
    
    let port = new SerialPortStream({
        binding: WebSerialBinding,
        path: ports[0].path, // for example: webserial://usb0
        baudRate: 115200,
    });

NOTES

You need something like vite-plugin-node-polyfills or node-stdlib-browser for using the serialport module in the browser.

node-serialport-bindings-webserial's People

Contributors

azq2 avatar

Stargazers

Jonathan Beri avatar

Watchers

 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.