flutter_serial_communication 0.0.1 copy "flutter_serial_communication: ^0.0.1" to clipboard
flutter_serial_communication: ^0.0.1 copied to clipboard

outdated

Flutter plugin for handling serial communication

About Flutter Serial Communication #

This library aims to ease Flutter Developers to do serial communcation with their peripherals without too much hassle.

Notes: Doesn't require root access on Android

WARNING!!! THIS IS AN EARLY ACCESS LIBRARY. SOME BUGS MIGHT BE PRESENT THAT WILL BE A HINDRANCE TO YOUR PROJECT.

Installing #

Android #

1. Add jitpack.io repository to your build.gradle (root)

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

2. Add library to Android dependencies (root build gradle / app build gradle)

dependencies {
    ...
    implementation 'com.github.mik3y:usb-serial-for-android:3.5.1'
}

3. Install it to your flutter project

flutter pub add shelf_static

or by adding dependencies to your package's pubspec.yaml then run dart pub get

dependencies:
  flutter_serial_communication: 0.0.1

4. Import it in your .dart file

import 'package:flutter_serial_communication/flutter_serial_communication.dart';

Features #

  • Doesn't require root in Android
  • Easy to use
  • Using listener for reading message & device connection status

Functions #

  • Get All Available Devices:
    • Requires: none
    • Returns: Future<List<String>>
final _flutterSerialCommunicationPlugin = FlutterSerialCommunication();

List<String> newConnectedDevices = await _flutterSerialCommunicationPlugin.getAvailableDevices() ?? [];
  • Connect:
    • Requires: index(int), baudRate(int)
    • Returns: Future<bool>
final _flutterSerialCommunicationPlugin = FlutterSerialCommunication();

int index = 0; // Index of List<String> from getAvailableDevices()
int baudRate = 0; // Your device's baud rate
bool isConnectionSuccess = await _flutterSerialCommunicationPlugin.connect(index, baudRate);
  • Disconnect:
    • Requires: none
    • Returns: Future<void>
final _flutterSerialCommunicationPlugin = FlutterSerialCommunication();

await _flutterSerialCommunicationPlugin.disconnect();
  • Write:
    • Requires: data(Uint8List)
    • Returns: Future<bool>
final _flutterSerialCommunicationPlugin = FlutterSerialCommunication();

bool isMessageSent = await _flutterSerialCommunicationPlugin.write(Uint8List.fromList([0xBB, 0x00, 0x22, 0x00, 0x00, 0x22, 0x7E]));
debugPrint("Is Message Sent:  $isMessageSent");
  • Read (Listener):
    • Requires: none
    • Returns: EventChannel
final _flutterSerialCommunicationPlugin = FlutterSerialCommunication();

EventChannel eventChannel = _flutterSerialCommunicationPlugin.getSerialMessageListener();
eventChannel.receiveBroadcastStream().listen((event) {
  debugPrint("Received From Native:  $event");
});
  • Device Connection Status (Listener):
    • Requires: none
    • Returns: EventChannel
final _flutterSerialCommunicationPlugin = FlutterSerialCommunication();

EventChannel eventChannel = _flutterSerialCommunicationPlugin.getDeviceConnectionListener();
eventChannel.receiveBroadcastStream().listen((event) {
  debugPrint("Received From Native:  $event");
});

Implementation #

25
likes
0
points
262
downloads

Publisher

verified publisherfarells.id

Weekly Downloads

Flutter plugin for handling serial communication

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on flutter_serial_communication