flusbserial 0.2.0
flusbserial: ^0.2.0 copied to clipboard
A cross-platform USB serial plugin for Flutter desktop apps (Windows, Linux, macOS).
flusbserial #
A cross-platform USB Serial plugin for Flutter desktop apps (Windows, Linux, macOS).
This plugin provides direct access to USB serial devices using libusb, without relying on traditional COM ports.
It is inspired and based on code from UsbSerial and quick_usb.
Supported / Planned Devices #
Device Family | CP210x | CDC ACM | CH34X | FTDI | PL2303 | BLED112 |
---|---|---|---|---|---|---|
Status | ✅ | ✅ | ✅ | ⏳ | ⏳ | ⏳ |
Note: This library is in development. File any potential issues you see.
Getting Started #
1. Install libusb driver #
This plugin requires an appropriate WinUSB (libusb) driver to access your device.
-
Windows:
You can use Zadig to replace the default driver with WinUSB for your device.
(Plug in your USB device → open Zadig → select your device from the list → choose WinUSB → click Install Driver). -
Linux / macOS:
Usually libusb is available by default.
If not, install it with your package manager:# Ubuntu/Debian sudo apt-get install libusb-1.0-0-dev # macOS (Homebrew) brew install libusb
Installing #
-
Add dependency to
pubspec.yaml
Get the latest version from the 'Installing' tab on pub.dev
dependencies:
flusbserial: <latest_version>
Note: Based upon the other dependencies included in your project, you may have to add a dependency override for the
ffi
package.
- 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 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);
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.