usb_serial 패키지는 FTDI, CDC 및 기타 프로토콜을 사용하여 안드로이드에서 Flutter 애플리케이션과 USB UART 장치 간의 통신을 가능하게 합니다. USB 시리얼 포트에서 읽기 및 쓰기 작업을 위한 직관적인 인터페이스를 제공하여 센서, 마이크로컨트롤러 및 산업용 장비와 같은 하드웨어 주변기기를 연결하는 데 이상적입니다. 이 플러그인은 네이티브 안드로이드 USB API를 활용하며, USB를 통해 직접 하드웨어와 상호작용해야 하는 앱 개발자를 위해 설계되었습니다.
사용 사례
USB-시리얼 어댑터에 연결
마이크로컨트롤러에서 데이터 읽기
산업용 하드웨어 제어
사물인터넷 장치와의 통합
사용자 정의 하드웨어 인터페이스 개발
주요 기능
FTDI 및 CDC 프로토콜을 지원합니다
간단한 읽기/쓰기 API
Android 전용 플랫폼 지원
네이티브 USB 통신
오픈소스 구현
적합한 대상
IoT 애플리케이션 개발자
하드웨어 통합업체
임베디드 시스템 엔지니어
USB를 사용하는 Android 앱 개발자
USB 연결 장치를 사용한 프로토타이핑
고려 사항
Android 플랫폼에 한정
USB OTG 지원이 필요합니다
적절한 장치 권한이 필요합니다
추가 하드웨어 드라이버가 필요할 수 있습니다
iOS와 호환되지 않습니다
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
Looking for maintainer
I'm looking for a new maintainer for this project, please indicate your interest here: https://github.com/altera2015/usbserial/issues/121
usb_serial
An Android USB Serial Flutter Plugin
This plugin allows Flutter code to interact with USB serial devices connected to your Android device. For example an FTDI or CDC based USB device.
Getting Started
Add a dependency to your pubspec.yaml
dependencies:
usb_serial: ^0.5.0
include the usbserial package at the top of your dart file.
in the res/xml directory. This will notify your app when one of the specified devices
is plugged in.
Usage of Asynchronous API
...
onPressed: () async {
List<UsbDevice> devices = awaitUsbSerial.listDevices();
print(devices);
UsbPort port;
if (devices.length == 0) {
return;
}
port = await devices[0].create();
bool openResult = await port.open();
if ( !openResult ) {
print("Failed to open");
return;
}
await port.setDTR(true);
await port.setRTS(true);
port.setPortParameters(115200, UsbPort.DATABITS_8,
UsbPort.STOPBITS_1, UsbPort.PARITY_NONE);
// print first result and close port.
port.inputStream.listen((Uint8List event) {
print(event);
port.close();
});
await port.write(Uint8List.fromList([0x10, 0x00]));
}
...
Usage of transaction API
This API is a layer on top of the asynchronous part of the library. It provides two
Stream Transformers and a Transaction helper based on the StreamQueue class.
Terminated Transformer, this splits incoming data based on a configurable end of message bytes "terminator".
Magic Header + Length byte, this splits incoming data based on a configurable header ( with wildcards! ) and a length byte directly following the header.
In case neither is a fit, you can use one of those Transformers to create you own that is specific
to the binary format you are dealing with.
...
Transaction<String> transaction = Transaction.stringTerminated(port.inputStream, Uint8List.fromList([13,10]));
...
// While using transactions you can still listen to all// incoming messages!
transaction.stream.listen( (String data) {
print(data);
});
// you can write asynchronous messages as before!
p.write(Uint8List.fromList([65,66,13,10]));
// BUT you can also write 'transactions'. This is a combination of a flush, write and wait for response// with a timeout. If no response is received within the timeout a null value is returned.// this sends "AB\r\n"var response = await transaction.transaction(p, Uint8List.fromList([65,66,13,10]), Duration(seconds: 1) );
print("The response was $response");
Upgrading from pre-0.3.0
In version 0.3.0 a resource bug was fixed (issue #35) which required signature
changes.
Transformer Class changes
The Transformer classes previously inherited directly from StreamTransformer, this class
however has no dispose method. So a new abstract class was added to include dispose and
called by Transaction.dispose().
If you are using the static factory methods you should not have to make any changes to your
code. Only if you created your own Transformer/Transactions.