搜索插件、代码仓与 APP 分类

插件详情v0.0.2

serial_communication

一个用于串行通信的 Android 插件,可让您通过可用端口读取和写入数据

Android
近 30 天下载
61
喜欢数
14
Pub 分数
160

安装插件

flutter pub add serial_communication

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

serial_communication 包是一个 Android 插件,可让 Flutter 应用通过可用的串行端口与外部硬件设备进行串行通信。它支持从这些端口读取和写入数据,从而实现与通过 UART/USB 转串行接口连接的传感器、微控制器或其他外设的直接交互。该包专为 Android 设计,为开发者提供了一个简单的 API,用于在其应用中集成基于硬件的功能。该包支持实时数据交换,非常适合物联网应用、工业自动化和嵌入式系统控制。

适合场景

  • 连接到Arduino设备
  • 实时读取传感器数据
  • 控制工业设备
  • 与USB转串口适配器集成
  • 构建物联网监控系统

主要特点

  • 仅支持 Android
  • 启用串行端口的读写操作
  • 硬件集成的简单API
  • 实时数据传输
  • 与 UART 和 USB 转串行设备兼容

适合对象

  • 物联网应用开发者
  • 硬件接口项目
  • 基于 Android 的工业应用
  • 嵌入式系统集成商
  • 使用微控制器进行原型设计

使用建议

  • 仅限 Android 平台
  • 需要硬件兼容性
  • 无 iOS 支持
  • 需要正确的权限和设备配置
  • 某些设备可能需要额外的原生设置

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Pub

Serial communication!

An Android Plugin for Serial Communication which allow you to read and write the data through the available ports The supported features are:

  • Listing the available serial ports on the device, including USB to serial adapters
  • Configuring serial ports (baud rate, stop bits, permission, ...)
  • Providing standard InputStream and OutputStream

Description

This PlugIn enables the communication with the USB RS232 RS485 UART

Supported platforms:

  • Android

Video tutorial

In order to completely understand you can view our sample video in which we are using an android Lcm module. Click the image below to watch the video:

IMAGE ALT TEXT

Getting Started

Add a dependency to your pubspec.yaml

dependencies:
	serial_communication: 0.0.2

include the usbserial package at the top of your dart file.

import  'package:serial_communication/serial_communication.dart';

❓ Usage

If you encounter any issues please refer to the API docs and the sample code in the example directory before opening a request on Github.

Example app

The example directory has a sample application that demonstrates the features of this plugin.


🔧 Android Setup

Initialisation
The first step is to call the startSerial() method and subscribe the StreamSubscription

Start Serial

startSerial method will open the transaction stream

SerialCommunication serialCommunication = SerialCommunication();

  @override
  void initState() {
    super.initState();
   serialCommunication.startSerial().listen(_updateConnectionStatus);
    getSerialList();
  }
  
 void  _updateConnectionStatus(SerialResponse? result) async {
logData = result!.logChannel ?? "";
receivedData = result.readChannel ?? "";
});
}

By calling the startSerial() it will provide you with the SerialResponse in the form of stream data

SerialResponse In Serial Response you will get the following type
1) Log Channel (type:String)
2) Read Channel (type:String)

  1. Log Channel: In the log channel you wll get the repsone when you open any port ,close any port , transmit data (TX).

  2. Read Channel: In the Read channel you wll get the Recived data (RX)

Available Ports

The getAvailablePorts() method will return you all the
available ports on a device

serialList = await  serialCommunication.getAvailablePorts();

Open

openPort method will open the serial communication Its has 3 required parameter { DataFormat dataFormat, String serialPort, int baudRate }

serialCommunication.openPort(
dataFormat: DataFormat.ASCII,
serialPort: serialList.first,
baudRate: serialCommunication.baudRateList.first)

Close

closePort method will close the port if you have opened any port

serialCommunication.closePort();

Send Command

sendCommand method will send your message Its has 1 required parameter {String message}

serialCommunication.sendCommand(message: "message");

Clear

clearLog method will clear the Log channel clearRead method will clear the Read channel

serialCommunication.clearLog();
serialCommunication.clearRead();

Destroy

destroy method will eliminate the resources

@override
void  dispose() {
serialCommunication.destroy();
super.dispose();
}

  • Baud Rate To get the Standard baud rates list call the SerialCommunication().baudRateList it will return the integer list of standard baud rate

  • Data Format The Data format is used to convert the data type To pass the data format in the open() method parameter For ascii format call the DataFormat.ASCII

    For hex_String format call the DataFormat.HEX_STRING

Contribution

Any help from the open-source community is always welcome and needed:

  • Found an issue?

    • Please fill a bug report with details.
  • Wish a feature?

    • Open a feature request with use cases.
  • Are you using and liking the project?

    • Promote the project: create an article, do a post or make a donation.
  • Are you a developer?

    • Fix a bug and send a pull request.
    • Implement a new feature.
    • Improve the Unit Tests.
  • Have you already helped in any way?

    • Many thanks from me, the contributors and everybody that uses this project!

    Maintainers

  • BJS MB Dev

  • Zain Ul Abideen

所属分类

依赖

依赖清单 1 项

  • plugin_platform_interface^2.0.2

源码仓库

使用此插件的项目

暂无相关数据。