flusbserial 0.5.0 copy "flusbserial: ^0.5.0" to clipboard
flusbserial: ^0.5.0 copied to clipboard

A cross-platform USB serial plugin for Flutter desktop apps (Windows, Linux, macOS).

flusbserial #

flusbserial ascress.com

A cross-platform USB Serial plugin for Flutter desktop apps (Windows, Linux, macOS).

flusbserial provides direct access to USB serial devices via libusb, bypassing traditional COM ports.

It is inspired and based on code from UsbSerial and quick_usb.

This library is under active development. Please report any issues you encounter.

Supported Devices #

  • CP210x
  • CDC ACM
  • CH34x

Prerequisites #

This plugin requires libusb to access USB devices.

Windows #

By default, Windows does not allow direct USB access via libusb. You can use Zadig to replace your device's driver with WinUSB:

  1. Plug in your USB device.
  2. Open Zadig and select your device from the list.
  3. Choose WinUSB and click Install Driver.

Note: This will replace the existing driver for the selected device. Make sure you select the correct device from the list.

Linux #

libusb is usually available by default. If not:

# Ubuntu / Debian
sudo apt-get install libusb-1.0-0

# Fedora / RHEL
sudo dnf install libusb1

Apps built with this plugin require udev rules to access USB devices without root. You can create /etc/udev/rules.d/99-<your-app>.rules with your device's vendor and product IDs:

SUBSYSTEM=="usb|tty", ATTRS{idVendor}=="xxxx", ATTRS{idProduct}=="xxxx", MODE="666"

Then reload the rules:

sudo udevadm control --reload-rules && sudo udevadm trigger

macOS #

libusb is usually available by default. If not:

brew install libusb

Your app needs permission to access USB devices. Add the following key to both macos/Runner/DebugProfile.entitlements and macos/Runner/Release.entitlements:

<key>com.apple.security.device.usb</key>
<true/>

This plugin does not currently support Flutter's Swift Package Manager integration. If you have SPM enabled, you must disable it using one of the following methods:

Option A — Per project, add to your app's pubspec.yaml:

flutter:
  config:
    enable-swift-package-manager: false

Option B — Globally, run:

flutter config --no-enable-swift-package-manager

Installing #

  1. Add dependency to pubspec.yaml

    Get the latest version from the 'Installing' tab on pub.dev

dependencies:
    flusbserial: <latest_version>
  1. Import the package
import 'package:flusbserial/flusbserial.dart';

Usage #

Here are some examples to show the usage:

Initialize plugin #

UsbSerialDevice.init();

List available devices #

List<UsbDevice> devices = await UsbSerialDevice.listDevices();

Instantiate a new object of the UsbSerialDevice class #

UsbDevice? device;
...
// Auto-detect interface
UsbSerialDevice? mDevice = UsbSerialDevice.createDevice(device);

// Specific interface
UsbSerialDevice? mDevice = UsbSerialDevice.createDevice(device, interfaceId: 0);

// Specific driver (eg:- CDC ACM)
UsbSerialDevice? mDevice = UsbSerialDevice.createDevice(device, type: UsbSerialDevice.cdc);

Open a device and set it up #

await mDevice.open();
await mDevice.setBaudRate(1000000);
await mDevice.setDataBits(UsbSerialInterface.dataBits8);
await mDevice.setStopBits(UsbSerialInterface.stopBits1);
await mDevice.setParity(UsbSerialInterface.parityNone);

Set flow control if needed (only supported in CP210x & CH34x devices) #

await mDevice.setFlowControl(UsbSerialInterface.flowControlRtsCts);

Read / Write #

int bytesWritten = await mDevice.write(data, timeout);

Uint8List bytesRead = await mDevice.read(bytesToRead, timeout);

Change the state of DTR/RTS lines #

await mDevice.setDtr(true);
await mDevice.setDtr(false);
await mDevice.setRts(true);
await mDevice.setRts(false);

Set Auto Detach Kernel Driver (only for Linux) #

UsbSerialDevice.setAutoDetachKernelDriver(true);

Close the device #

await mDevice.close();

License #

MIT License

Copyright (c) 2025 Anashuman Singh

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
4
likes
160
points
1.47k
downloads

Documentation

API reference

Publisher

verified publisherascress.com

Weekly Downloads

A cross-platform USB serial plugin for Flutter desktop apps (Windows, Linux, macOS).

Repository (GitHub)
View/report issues

Topics

#usb #desktop #serialport

License

MIT (license)

Dependencies

dart_libusb, ffi, flutter, plugin_platform_interface

More

Packages that depend on flusbserial

Packages that implement flusbserial