सार्वजनिक जानकारी से बना चयन मार्गदर्शन। केवल संदर्भ हेतु।
usb_serial पैकेज एंड्रॉइड पर FTDI, CDC और अन्य प्रोटोकॉल का उपयोग करके फ्लटर एप्लिकेशन को USB UART डिवाइस के साथ संचार करने में सक्षम बनाता है। यह USB सीरियल पोर्ट्स से पढ़ने और लिखने के लिए एक सीधा इंटरफेस प्रदान करता है, जिससे सेंसर, माइक्रोकंट्रोलर और औद्योगिक उपकरण जैसे हार्डवेयर पेरिफेरल्स से जुड़ना आसान हो जाता है। यह प्लगइन मूल एंड्रॉइड USB API का उपयोग करता है और USB के माध्यम से सीधे हार्डवेयर इंटरैक्शन की आवश्यकता वाले एप्लिकेशन बनाने वाले डेवलपर्स के लिए डिज़ाइन किया गया है।
उपयोग
यूएसबी-टू-सीरियल एडाप्टर से कनेक्ट करना
माइक्रोकंट्रोलर से डेटा पढ़ना
औद्योगिक हार्डवेयर को नियंत्रित करना
आईओटी उपकरणों के साथ एकीकरण
कस्टम हार्डवेयर इंटरफ़ेस विकसित करना
मुख्य विशेषताएँ
FTDI और CDC प्रोटोकॉल का समर्थन करता है
सरल पढ़ने/लिखने एपीआई
Android-केवल प्लेटफॉर्म समर्थन
मूल यूएसबी संचार
ओपन-सोर्स अमलीकरण
इनके लिए उपयुक्त
आईओटी एप्लिकेशन डेवलपर्स
हार्डवेयर इंटीग्रेटर्स
एम्बेडेड सिस्टम इंजीनियर
USB के साथ काम कर रहे Android ऐप विकासकर्ता
यूएसबी-कनेक्टेड डिवाइस के साथ प्रोटोटाइपिंग
विचार योग्य बातें
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.