npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

capacitor-serial-plugin

v1.1.3

Published

This plugin can be used for reading data from other device over the usb channel

Readme

usb-serial-plugin

This plugin can be used for reading data from other device over the usb channel

This project is forked from capacitor-plugin-usb-serial

Install

npm install capacitor-serial-plugin
npx cap sync

Android

build.gradle

This plugin uses usb-serial-for-android library. You need to add the maven repository to your build.gradle file.

allprojects {
    repositories {
        google()
        mavenCentral()
        maven { url 'https://jitpack.io' }
    }
}

AndroidManifest.xml

This plugin requires the following feature:

<manifest ...>
    <uses-feature android:name="android.hardware.usb.host" />
    ...
</manifest>

See the Android Documentation for more information.

Configuration

| Prop | Type | Description | Default | Since | | -------------------- | ------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------- | ----- | | dataEncoding | 'utf8' | 'base64' | Encoding format for serial data. - 'utf8': Return data as UTF-8 decoded string (default) - 'base64': Return data as base64 encoded string | 'utf8' | 1.0.0 | | dataThrottleMs | number | Data throttle interval in milliseconds for aggregating received data. Multiple data packets received within this interval will be batched together. Helps improve performance when receiving high-frequency data. | 50 | 1.0.0 | | dataBufferSize | number | Maximum buffer size in bytes before flushing data. When the buffer reaches this size, data is sent immediately without waiting for throttle interval. | 4096 | 1.0.0 |

Examples

In capacitor.config.json:

{
  "plugins": {
    "UsbSerial": {
      "dataEncoding": "base64",
      "dataThrottleMs": 100,
      "dataBufferSize": 8192
    }
  }
}

In capacitor.config.ts:

/// <reference types="capacitor-serial-plugin" />

import { CapacitorConfig } from '@capacitor/cli';

const config: CapacitorConfig = {
  plugins: {
    UsbSerial: {
      dataEncoding: "base64",
      dataThrottleMs: 100,
      dataBufferSize: 8192,
    },
  },
};

export default config;

API

connectedDevices()

connectedDevices() => Promise<{ devices: UsbSerialDevice[]; }>

Get a list of currently connected USB serial devices.

Returns: Promise<{ devices: UsbSerialDevice[]; }>


openSerial(...)

openSerial(options: UsbSerialOptions) => Promise<void>

Open a serial connection to a USB device.

| Param | Type | Description | | ------------- | ------------------------------------------------------------- | --------------------------- | | options | UsbSerialOptions | - Serial connection options |


closeSerial()

closeSerial() => Promise<void>

Close the current serial connection.


readSerial()

readSerial() => Promise<{ data: string; }>

Reads data from the serial port.

Returns: Promise<{ data: string; }>


writeSerial(...)

writeSerial(options: { data: string; }) => Promise<void>

Writes data to the serial port.

| Param | Type | Description | | ------------- | ------------------------------ | ------------------- | | options | { data: string; } | - The write options |


addListener('log', ...)

addListener(eventName: 'log', listenerFunc: (data: { text: string; tag: string; }) => void) => Promise<PluginListenerHandle> & PluginListenerHandle

Listen for log messages from the plugin.

| Param | Type | Description | | ------------------ | -------------------------------------------------------------- | --------------------------------------------------------- | | eventName | 'log' | - Must be 'log' | | listenerFunc | (data: { text: string; tag: string; }) => void | - Callback function called when log messages are received |

Returns: Promise<PluginListenerHandle> & PluginListenerHandle


addListener('connected', ...)

addListener(eventName: 'connected', listenerFunc: (data: UsbSerialDevice) => void) => Promise<PluginListenerHandle> & PluginListenerHandle

Listen for device connection events.

| Param | Type | Description | | ------------------ | ------------------------------------------------------------------------------ | ------------------------------------------------- | | eventName | 'connected' | - Must be 'connected' | | listenerFunc | (data: UsbSerialDevice) => void | - Callback function called when a device connects |

Returns: Promise<PluginListenerHandle> & PluginListenerHandle


addListener('attached', ...)

addListener(eventName: 'attached', listenerFunc: (data: UsbSerialDevice) => void) => Promise<PluginListenerHandle> & PluginListenerHandle

Listen for device attachment events.

| Param | Type | Description | | ------------------ | ------------------------------------------------------------------------------ | ---------------------------------------------------- | | eventName | 'attached' | - Must be 'attached' | | listenerFunc | (data: UsbSerialDevice) => void | - Callback function called when a device is attached |

Returns: Promise<PluginListenerHandle> & PluginListenerHandle


addListener('detached', ...)

addListener(eventName: 'detached', listenerFunc: (data: UsbSerialDevice) => void) => Promise<PluginListenerHandle> & PluginListenerHandle

Listen for device detachment events.

| Param | Type | Description | | ------------------ | ------------------------------------------------------------------------------ | ---------------------------------------------------- | | eventName | 'detached' | - Must be 'detached' | | listenerFunc | (data: UsbSerialDevice) => void | - Callback function called when a device is detached |

Returns: Promise<PluginListenerHandle> & PluginListenerHandle


addListener('data', ...)

addListener(eventName: 'data', listenerFunc: (data: { data: string; }) => void) => Promise<PluginListenerHandle> & PluginListenerHandle

Listen for incoming serial data.

| Param | Type | Description | | ------------------ | ------------------------------------------------- | ------------------------------------------------ | | eventName | 'data' | - Must be 'data' | | listenerFunc | (data: { data: string; }) => void | - Callback function called when data is received |

Returns: Promise<PluginListenerHandle> & PluginListenerHandle


addListener('error', ...)

addListener(eventName: 'error', listenerFunc: (data: { error: string; }) => void) => Promise<PluginListenerHandle> & PluginListenerHandle

Listen for error events from the serial communication.

| Param | Type | Description | | ------------------ | -------------------------------------------------- | -------------------------------------------- | | eventName | 'error' | - Must be 'error' | | listenerFunc | (data: { error: string; }) => void | - Callback function called when errors occur |

Returns: Promise<PluginListenerHandle> & PluginListenerHandle


getDataEncoding()

getDataEncoding() => Promise<{ encoding: 'utf8' | 'base64'; }>

Get the current data encoding configuration.

Returns: Promise<{ encoding: 'utf8' | 'base64'; }>


removeAllListeners()

removeAllListeners() => Promise<void>

Remove all listeners for all events.


Interfaces

UsbSerialDevice

| Prop | Type | | ---------------------- | ------------------- | | deviceId | number | | vendorId | number | | productId | number | | deviceName | string | | manufacturerName | string | | serialNumber | string |

UsbSerialOptions

| Prop | Type | | -------------- | ----------------------------------------------------------- | | deviceId | number | | portNum | number | | baudRate | number | | dataBits | number | | stopBits | number | | parity | 'none' | 'odd' | 'even' | 'mark' | 'space' | | dtr | boolean | | rts | boolean |

PluginListenerHandle

| Prop | Type | | ------------ | ----------------------------------------- | | remove | () => Promise<void> |