[![Actions Status](https://github.com/mik3y/usb-serial-for-android/workflows/build/badge.svg)](https://github.com/mik3y/usb-serial-for-android/actions)
[![Jitpack](https://jitpack.io/v/mik3y/usb-serial-for-android.svg)](https://jitpack.io/#mik3y/usb-serial-for-android)
[![Codacy](https://app.codacy.com/project/badge/Grade/ef799bba8a7343818af0a90eba3ecb46)](https://app.codacy.com/gh/kai-morich/usb-serial-for-android-mik3y/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
[![codecov](https://codecov.io/gh/mik3y/usb-serial-for-android/branch/master/graph/badge.svg)](https://codecov.io/gh/mik3y/usb-serial-for-android)
# usb-serial-for-android
This is a driver library for communication with Arduinos and other USB serial hardware on
Android, using the
[Android USB Host Mode (OTG)](http://developer.android.com/guide/topics/connectivity/usb/host.html)
available since Android 3.1 and working reliably since Android 4.2.
No root access, ADK, or special kernel drivers are required; all drivers are implemented in
Java. You get a raw serial port with `read()`, `write()`, and [other functions](https://github.com/mik3y/usb-serial-for-android/wiki/FAQ#Feature_Matrix) for use with your own protocols.
## Quick Start
**1.** Add library to your project:
Add jitpack.io repository to your root build.gradle:
```gradle
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
```
Starting with gradle 6.8 you can alternatively add jitpack.io repository to your settings.gradle:
```gradle
dependencyResolutionManagement {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
```
If using gradle kotlin use line
```gradle.kts
maven(url = "https://jitpack.io")
```
Add library to dependencies
```gradle
dependencies {
implementation 'com.github.mik3y:usb-serial-for-android:3.8.0'
}
```
**2.** If the app should be notified when a device is attached, add
[device_filter.xml](https://github.com/mik3y/usb-serial-for-android/blob/master/usbSerialExamples/src/main/res/xml/device_filter.xml)
to your project's `res/xml/` directory and configure in your `AndroidManifest.xml`.
```xml
<activity
android:name="..."
...>
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
</intent-filter>
<meta-data
android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
android:resource="@xml/device_filter" />
</activity>
```
**3.** Use it! Example code snippet:
open device:
```java
// Find all available drivers from attached devices.
UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
List<UsbSerialDriver> availableDrivers = UsbSerialProber.getDefaultProber().findAllDrivers(manager);
if (availableDrivers.isEmpty()) {
return;
}
// Open a connection to the first available driver.
UsbSerialDriver driver = availableDrivers.get(0);
UsbDeviceConnection connection = manager.openDevice(driver.getDevice());
if (connection == null) {
// add UsbManager.requestPermission(driver.getDevice(), ..) handling here
return;
}
UsbSerialPort port = driver.getPorts().get(0); // Most devices have just one port (port 0)
port.open(connection);
port.setParameters(115200, 8, UsbSerialPort.STOPBITS_1, UsbSerialPort.PARITY_NONE);
```
then use direct read/write
```java
port.write(request, WRITE_WAIT_MILLIS);
len = port.read(response, READ_WAIT_MILLIS);
```
or direct write + event driven read:
```java
usbIoManager = new SerialInputOutputManager(usbSerialPort, this);
usbIoManager.start();
...
port.write("hello".getBytes(), WRITE_WAIT_MILLIS);
@Override
public void onNewData(byte[] data) {
runOnUiThread(() -> { textView.append(new String(data)); });
}
```
and finally:
```java
port.close();
```
For a simple example, see
[UsbSerialExamples](https://github.com/mik3y/usb-serial-for-android/blob/master/usbSerialExamples)
folder in this project.
See separate github project [SimpleUsbTerminal](https://github.com/kai-morich/SimpleUsbTerminal)
for a more complete example with:
* Background service to stay connected while the app is not visible or rotating
* Flow control
## Probing for Unrecognized Devices
Sometimes you may need to do a little extra work to support devices which
usb-serial-for-android doesn't (yet) know about -- but which you know to be
compatible with one of the built-in drivers. This may be the case for a brand
new device or for one using a custom VID/PID pair.
UsbSerialProber is a class to help you find and instantiate compatible
UsbSerialDrivers from the tree of connected UsbDevices. Normally, you will use
the default prober returned by ``UsbSerialProber.getDefaultProber()``, which
uses USB interface types and the built-in list of well-known VIDs and PIDs that
are supported by our drivers.
To use your own set of rules, create and use a custom prober:
```java
// Probe for our custom FTDI device, which use VID 0x1234 and PID 0x0001 and 0x0002.
ProbeTable customTable = new ProbeTable();
customTable.addProduct(0x1234, 0x0001, FtdiSerialDriver.class);
customTable.addProduct(0x1234, 0x0002, FtdiSerialDriver.class);
UsbSerialProber prober = new UsbSerialProber(customTable);
List<UsbSerialDriver> drivers = prober.findAllDrivers(usbManager);
// ...
```
*Note*: as of v3.5.0 this library detects CDC devices by USB interface types instead of fixed VID+PID,
so custom probers are typically not required any more for CDC devices.
Of course, nothing requires you to use UsbSerialProber at all: you can
instantiate driver classes directly if you know what you're doing; just supply
a compatible UsbDevice.
## Compatible Devices
This library supports USB to serial converter chips:
* FTDI FT232R, FT232H, FT2232H, FT4232H, FT230X, FT231X, FT234XD
* Prolific PL2303
* Silabs CP2102, CP210*
* Qinheng CH340, CH341A, CH9102
devices implementing the CDC/ACM protocol like
* Arduino using ATmega32U4
* Digispark using V-USB software USB
* BBC micro:bit using ARM mbed DAPLink firmware
* ...
and some device specific drivers:
* GsmModem devices, e.g. for Unisoc based Fibocom GSM modems
* Chrome OS CCD (Closed Case Debugging)
## Help & Discussion
For common problems, see the [FAQ](https://github.com/mik3y/usb-serial-for-android/wiki/FAQ) wiki page.
Are you using the library? Add your project to
[ProjectsUsingUsbSerialForAndroid](https://github.com/mik3y/usb-serial-for-android/wiki/Projects-Using-usb-serial-for-android).
没有合适的资源?快使用搜索试试~ 我知道了~
qt桌面端和qtC++Android串口源码
共301个文件
java:57个
sample:26个
xml:23个
需积分: 5 0 下载量 118 浏览量
2024-08-23
11:19:23
上传
评论
收藏 1.56MB ZIP 举报
温馨提示
qt桌面端和qtC++Android串口源码
资源推荐
资源详情
资源评论
收起资源包目录
qt桌面端和qtC++Android串口源码 (301个子文件)
00916aa402a207ae72df893a4e5e408ba5d082 350B
01d7b6d640a873f9162a6379e2fce285a2c3b5 427B
0b530afd203e6d9c63c09990ba5b24c00ee638 408B
12b8f4e0533ef01985303e36e14da4a0e4cd90 49B
13279e50338014d7b8356e412d30c3e3802757 49B
15e9b156242bba7a7bb3f97891dad9fbb798c9 2KB
1682fcb31e12c02442a36f2c18bc8335fe53a6 515B
17af33916742bf4a1d665c8fb62174c4af62da 49B
199467cfcc8ba1768bb110b376b827337999c2 46B
19aca895e94d94b90d4dbf6be4cdf1b3fd2ff7 1KB
1a4a2a02e55741aace3928b71c5219f14cbc2e 304B
1b28a220fe8a35f5cb8e52281f8349d7b111ed 2KB
1da36a9a150e2a883ac654042f2b998e42dbc1 568B
1efbd88021b8935d66b2240bf22f11455055a2 196B
268bbe25fe695f3de2a29f0b83bc75c24867f8 3KB
28f28f8e4755a78a5bf0fef4644577b199c8c4 139B
2b95d329d95f5a31b9cfed3551403a87f1766c 45B
2bd6c1d5afacc50969d6c5d26ea12ab5e7dcee 4KB
2db836ec0d1b34836cc8ac286bab88b7a9a1dd 350B
2ee0a31ee554d7e37c8b81b6eeddf7decda3a8 215B
304bcbb6bf837750b2cef4c76f1af3cc2338a1 271B
3212d9b9567ec86e9704922a13bb35232edbf9 1KB
3a800244e877010d1b5ceca7cf0c0479d5cbd0 791B
3c2f258bb2f04c43a80494aa0e3e94b347e663 810B
3d30e72d5bbb5868c62b40eed25727eb107f5f 63B
440203e4ac47540f30c3976d9b57f19dbd1ade 351B
47c1c5896b6bca3688fb0e6f3cb9b712dbcdee 143B
48ddcd6d07b0c593923f074c7082858eb74fc3 189B
4aab86324e44d4ad06da1c753bbd654fa2520d 481B
4e7ab77df33f92b9efc2269866f215b404b5e3 410B
512abb7b993c19578aaa798ad8863caa9188ee 608B
520826732df88fc9810985d385ae3b4d56bfb7 351B
553162f122c71b34635112e717c3e733b5b212 942B
567980d03703d2f474a5c5f0bbeea1899fa766 402B
5700754b70c8c607adecc158cefb726d49d6e2 608B
5fd386968357d7cc2ea9e0c85c973da5348857 350B
6153384cd07a57c58f52f6660d7fecd791d4d4 787B
62d97ae3854ac97d181d177aaf71d2d5d0fede 660B
63aef76743b7f2bca807f7b4f2588f911cc92c 77B
64cb84ad4e7c191990a7331f20482c5391255f 876B
65628573bcf3a6bdb8998c46aece11a53b553c 748B
683432542d500fbcb539136669783b3ab6f7e0 49B
699a7d240279eef71a63356e4da4424bf945db 301B
71d4d31d81ca6e52352ced0c2c8b70ee2553d3 301B
7334ca4c4b543f1e45f7918930462ba3ee7eed 180B
73a849a4fed066a836208b78a3535425178ae3 274B
767b721e3a9f7ac13f45c922dc4e8827708c13 138B
76dc410b38b188742dae8675abf9f0deeb9b16 2KB
7d71eac4458bdeb272057e4a34dbb21838ab64 351B
7f8779d701712f33e16db88ecbbf11436a6f67 82B
81b8fd2e8d3050d3655355676b309d6e01633d 192B
825dc642cb6eb9a060e54bf8d69288fbee4904 15B
8498886e67240f050afef1e242aad6adb376f9 648B
8971450009d571d9cfeb83c267da0863602dc4 76B
89b6167e7eb2f4dea33632860f516ded55baf7 6KB
8ad9bd09af1ed6d97d1c488c6c4971930bb72e 301B
8eaab6bf200acfb267df272562f7bfb4dd5510 4KB
918d0e982a9de9359328a2437e16538e3b8e65 195B
9403cd10bb724a17da377eaa4df728a8fe561b 4KB
9bcdf6f6c0fb876fa30aa3d31ac2114336b66d 288B
9de29bb2d1d6434b8b29ae775ad8c2e48c5391 15B
9fa40c7ced5f6bc108e01e51e9a80d92a68ab8 52B
a19f096b035fa1c60e1e4f4a1f4c9c72448010 301B
a2bdc7a39b223bc424ee838ad168a8a797fbff 1KB
a59ac64876240ae48d950f2f91cd5486ba1337 62B
a63e7607daeb0fb14afdbba1836b5ed5df7984 50B
a7de019c06bacf0c02797ba3e69bc5ebb7bcbc 2KB
aaddda02852a9b92b86ac5e1050fcf64335123 618B
ad6ef405aa6cc232a074165627c12b795a502b 161B
aebf0f0fd2f1a7bae1abdfd3be1aa5b1cb42af 51B
af6aabf130fa848a569f6ecd04c8d54499426e 377B
android 1KB
android 284B
android 41B
android 41B
b0a4efaa557e3e5fc2eb9918b7ea8b2d43e20e 2KB
b4cdf9a9a455c05937ba5f120c9fe16b5f710c 96B
b961fd5a86aa5fbfe90f707c3138408be7c718 48KB
b9d5d9ebb80cf09c2298c7a1feb83f451938de 609B
gradlew.bat 3KB
gradlew.bat 2KB
gradlew.bat 0B
bcebbeabf07f6470c20263353b0664dfc4922f 274B
be50486598d449dd67e03bddeaa8858aa1f72d 631B
c166555d29b2878f0fabbc9e738b9679bc5c91 495B
c219f052a812b19e60471a0d7de3a3dd0625e8 63B
c99e4801dc1bfd704c52feb4e3473f78c8eccc 177B
c9ac8098da20351d072dffe395f22b9909b2bf 53B
cab6da17bcd2dfe032baff34b1a3d3a3e108c2 5KB
cc48b11ce691b16e74eccce917bdba90316b50 214B
cdd3d517fc5249beaefa600691cf150f2fa3e6 2KB
COMMIT_EDITMSG 13B
config 369B
config 310B
USBCore.cpp 21KB
CDC.cpp 10KB
CDC.cpp 9KB
PortWidgets.cpp 6KB
SerialPort.cpp 2KB
main.cpp 183B
共 301 条
- 1
- 2
- 3
- 4
资源评论
TravisBytes
- 粉丝: 1117
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 学习记录111111111111111111111111
- JavaScript函数
- java-leetcode题解之Range Sum Query 2D - Mutable.java
- java-leetcode题解之Random Pick Index.java
- java-leetcode题解之Race Car.java
- java-leetcode题解之Profitable Schemes.java
- java-leetcode题解之Product of Array Exclude Itself.java
- java-leetcode题解之Prime Arrangements.java
- MCU51-51单片机
- java-leetcode题解之Power of Two.java
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功