serial_communication
Um plugin Android para comunicação serial que permite ler e escrever dados através das portas disponíveis
Plugin de comunicação serial Android do Flutter
{"sdk":"flutter"}^2.0.2{"sdk":"flutter"}Texto original em inglês. Visite o GitHub para a versão atual.
Pub
An Android Plugin for Serial Communication which allow you to read and write the data through the available ports The supported features are:
This PlugIn enables the communication with the USB RS232 RS485 UART
Supported platforms:
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:
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';
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.
The example directory has a sample application that demonstrates the features of this plugin.
Initialisation
The first step is to call the startSerial() method and subscribe the
StreamSubscription
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)
Log Channel: In the log channel you wll get the repsone when you open any port ,close any port , transmit data (TX).
Read Channel: In the Read channel you wll get the Recived data (RX)
The getAvailablePorts() method will return you all the
available ports on a device
serialList = await serialCommunication.getAvailablePorts();
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)
closePort method will close the port if you have opened any port
serialCommunication.closePort();
sendCommand method will send your message Its has 1 required parameter {String message}
serialCommunication.sendCommand(message: "message");
clearLog method will clear the Log channel clearRead method will clear the Read channel
serialCommunication.clearLog();
serialCommunication.clearRead();
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
Any help from the open-source community is always welcome and needed:
Found an issue?
Wish a feature?
Are you using and liking the project?
Are you a developer?
Have you already helped in any way?