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

GitHub 代码仓bjssoftsolutions/serial_communication

串行通信

Flutter Android 串行通信插件

串行通信 项目封面
星标
17
复刻
13
最近推送(UTC)
2024年1月19日
项目状态
未归档

原始 README

以下为英文项目原文快照,最新内容请访问 GitHub。

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

BJS Soft Solution Pvt Ltd GitHub avatar
GitHub 作者

BJS Soft Solution Pvt Ltd ↗

BJS Soft Solution Pvt LtdLahore, Pakistan官方网站 ↗
语言JavaDart

此仓库发布的插件

使用的依赖

依赖清单 3 项

  • flutter{"sdk":"flutter"}
  • plugin_platform_interface^2.0.2
  • flutter_test开发依赖{"sdk":"flutter"}

如何选择适合项目的代码仓?

先按使用场景筛选,再比较项目活跃情况,最后到原始仓库核对使用要求。

  1. 通过仓库名、作者或描述搜索,再按技术分类缩小范围。
  2. 结合星标、复刻与最近推送比较项目;星标反映社区关注,不代表质量保证。
  3. 使用前在 GitHub 核对 README、许可证与 Issues。

来源与维护

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗