https://github.com/jakobkordez/libserialport_plus
Flutter libserialport FFI plugin
https://github.com/jakobkordez/libserialport_plus
android ffi flutter libserialport linux macos plugin serial serialport sigrok windows
Last synced: 5 months ago
JSON representation
Flutter libserialport FFI plugin
- Host: GitHub
- URL: https://github.com/jakobkordez/libserialport_plus
- Owner: jakobkordez
- License: gpl-3.0
- Created: 2025-04-26T10:20:34.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-10-15T09:13:11.000Z (9 months ago)
- Last Synced: 2025-10-23T05:15:55.192Z (9 months ago)
- Topics: android, ffi, flutter, libserialport, linux, macos, plugin, serial, serialport, sigrok, windows
- Language: Dart
- Homepage: https://pub.dev/packages/libserialport_plus
- Size: 327 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# libserialport_plus
A Flutter wrapper (FFI plugin) for the [libserialport](https://github.com/sigrok/libserialport) library.
This package provides a simple API for communicating over serial ports.
## Features
- Cross-platform support for Android, iOS, Linux, macOS and Windows.
- Reading and writing bytes to serial ports.
- Reading bytes from serial ports in a stream.
- Getting a list of available serial ports.
- Getting information about serial ports.
- Getting and setting serial port settings (baud rate, data bits, parity, stop bits, etc.).
## Usage
Add `libserialport_plus` as a dependency in your `pubspec.yaml` file.
```bash
flutter pub add libserialport_plus
```
Import the package in your Dart code:
```dart
import 'package:libserialport_plus/libserialport_plus.dart';
// Get a list of available serial ports
List ports = SerialPort.getAvailablePorts();
// Create a serial port instance (MUST BE DISPOSED AFTER USE)
SerialPort port = SerialPort("COM3");
// Get information about the serial port
SerialPortInfo info = port.getInfo();
// Open the serial port
port.open(SerialPortMode.readWrite);
// Check if the serial port is open
bool isOpen = port.isOpen();
// Read bytes from the serial port
Uint8List bytes = port.read(1024);
// Write some bytes to the serial port
port.write(bytes);
// Close the serial port
port.close();
// Dispose the serial port
port.dispose();
```
### Reader
```dart
// Create and open a serial port
SerialPort port = SerialPort("COM3");
port.open();
SerialPortReader reader = SerialPortReader(port);
reader.stream.listen((Uint8List bytes) {
// Do something with the bytes
});
// After you are done, close the reader
reader.close();
```
## macOS
If creating an app for macOS, serial permissions are required. Enable this by adding the following two lines to `DebugProfile.entitlements` and `Release.entitlements`:
```xml
com.apple.security.device.serial
```
## Development
To get started you need to initialize the `libserialport` submodule with:
```bash
git submodule update --init --recursive
```
The native build systems that are invoked by FFI (and method channel) plugins are:
- For Android: Gradle, which invokes the Android NDK for native builds.
- See the documentation in android/build.gradle.
- For iOS and MacOS: Xcode, via CocoaPods.
- See the documentation in ios/libserialport_plus.podspec.
- See the documentation in macos/libserialport_plus.podspec.
- For Linux and Windows: CMake.
- See the documentation in linux/CMakeLists.txt.
- See the documentation in windows/CMakeLists.txt.
## Binding to native code
To use the native code, bindings in Dart are needed.
To avoid writing these by hand, they are generated from the header file
(`src/libserialport/libserialport.h`) by `package:ffigen`.
Regenerate the bindings by running `dart run ffigen --config ffigen.yaml`.