# 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 API](http://developer.android.com/guide/topics/connectivity/usb/host.html)
available on Android 3.1+.
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 basic
functions for use with your own protocols.
* **Homepage**: https://github.com/mik3y/usb-serial-for-android
* **Google group**: http://groups.google.com/group/usb-serial-for-android
* **Latest release**: [v0.1.0](https://github.com/mik3y/usb-serial-for-android/releases)
## Quick Start
**1.** [Link your project](https://github.com/mik3y/usb-serial-for-android/wiki/Building-From-Source) to the library.
**2.** Copy [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.
**3.** Configure your `AndroidManifest.xml` to notify your app when a device is attached (see [Android USB Host documentation](http://developer.android.com/guide/topics/connectivity/usb/host.html#discovering-d) for help).
```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>
```
**4.** Use it! Example code snippet:
```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) {
// You probably need to call UsbManager.requestPermission(driver.getDevice(), ..)
return;
}
// Read some data! Most have just one port (port 0).
UsbSerialPort port = driver.getPorts().get(0);
try {
port.open(connection);
port.setParameters(115200, 8, UsbSerialPort.STOPBITS_1, UsbSerialPort.PARITY_NONE);
byte buffer[] = new byte[16];
int numBytesRead = port.read(buffer, 1000);
Log.d(TAG, "Read " + numBytesRead + " bytes.");
} catch (IOException e) {
// Deal with error.
} finally {
port.close();
}
```
For a more complete example, see the
[UsbSerialExamples project](https://github.com/mik3y/usb-serial-for-android/blob/master/usbSerialExamples)
in git, which is a simple application for reading and showing serial data.
A [simple Arduino application](https://github.com/mik3y/usb-serial-for-android/blob/master/arduino)
is also available which can be used for testing.
## 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 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 CDC devices, which use VID 0x1234
// and PIDS 0x0001 and 0x0002.
ProbeTable customTable = new ProbeTable();
customTable.addProduct(0x1234, 0x0001, CdcAcmSerialDriver.class);
customTable.addProduct(0x1234, 0x0002, CdcAcmSerialDriver.class);
UsbSerialProber prober = new UsbSerialProber(customTable);
List<UsbSerialDriver> drivers = prober.findAllDrivers(usbManager);
// ...
```
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
* *Serial chips:* FT232R, CDC/ACM (eg Arduino Uno) and possibly others.
See [CompatibleSerialDevices](https://github.com/mik3y/usb-serial-for-android/wiki/Compatible-Serial-Devices).
* *Android phones and tablets:* Nexus 7, Motorola Xoom, and many others.
See [CompatibleAndroidDevices](https://github.com/mik3y/usb-serial-for-android/wiki/Compatible-Android-Devices).
## Author, License, and Copyright
usb-serial-for-android is written and maintained by *mike wakerly*.
This library is licensed under *LGPL Version 2.1*. Please see LICENSE.txt for the
complete license.
Copyright 2011-2012, Google Inc. All Rights Reserved.
Portions of this library are based on libftdi
(http://www.intra2net.com/en/developer/libftdi). Please see
FtdiSerialDriver.java for more information.
## Help & Discussion
For common problems, see the
[Troubleshooting](https://github.com/mik3y/usb-serial-for-android/wiki/Troubleshooting)
wiki page.
For other help and discussion, please join our Google Group,
[usb-serial-for-android](https://groups.google.com/forum/?fromgroups#!forum/usb-serial-for-android).
Are you using the library? Let us know on the group and we'll add your project to
[ProjectsUsingUsbSerialForAndroid](https://github.com/mik3y/usb-serial-for-android/wiki/Projects-Using-usb-serial-for-android).
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Android 通过USB与PLC设备通信(USB转串口) (119个子文件)
usbSerialExamples-debug.apk 41KB
gradlew.bat 2KB
fileSnapshots.bin 925KB
taskHistory.bin 569KB
taskArtifacts.bin 306KB
localClassSetAnalysis.bin 111KB
fileHashes.bin 68KB
taskHistory.bin 54KB
classAnalysis.bin 46KB
localClassSetAnalysis.bin 36KB
localClassSetAnalysis.bin 32KB
fileHashes.bin 32KB
jarAnalysis.bin 23KB
outputFiles.bin 21KB
taskJars.bin 18KB
localJarClasspathSnapshot.bin 18KB
resourceHashesCache.bin 18KB
localJarClasspathSnapshot.bin 18KB
localJarClasspathSnapshot.bin 18KB
annotation-processors.bin 18KB
last-build.bin 1B
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.gitignore 506B
build.gradle 5KB
build.gradle 394B
build.gradle 262B
settings.gradle 51B
gradlew 5KB
usbSerialExamples.iml 8KB
usbSerialForAndroid.iml 7KB
usb-serial-for-android-master.iml 962B
serial_test.ino 1KB
usb_serialport_20180318b02.jar 64KB
proguard-usb_serialport_20180318b0.jar 50KB
proguard-usb_serialport_20180318b02.jar 50KB
gradle-wrapper.jar 49KB
DateUtils.java 37KB
DataUtils.java 25KB
FtdiSerialDriver.java 20KB
ProlificSerialDriver.java 20KB
FileUtils.java 19KB
ModbusTransferImpl.java 16KB
CdcAcmSerialDriver.java 16KB
SerialConsoleActivityI.java 12KB
Cp21xxSerialDriver.java 12KB
SerialConsoleActivity.java 12KB
USBManagerImpl.java 10KB
StringUtil.java 10KB
Ch34xSerialDriver.java 10KB
USBManager.java 9KB
SerialConsoleActivity.java 8KB
UsbSerialPort.java 7KB
DeviceListActivityI.java 7KB
DeviceListActivity.java 7KB
DeviceListActivity.java 7KB
DeviceListActivity.java 7KB
USBDevice.java 7KB
SerialConsoleActivity.java 6KB
AppException.java 6KB
SerialInputOutputManager.java 5KB
CommonUsbSerialPort.java 5KB
HexDump.java 5KB
UsbSerialProber.java 4KB
ProbeTable.java 4KB
LogUtils.java 3KB
AppConfig.java 3KB
UsbId.java 3KB
USBManager.java 3KB
ModbusTransfer.java 2KB
LogInfoManager.java 2KB
UsbSerialDriver.java 1KB
UsbSerialRuntimeException.java 1KB
USBParams.java 695B
MainApplication.java 606B
BuildInfo.java 490B
localJarClasspathSnapshot.lock 17B
fileContent.lock 17B
fileHashes.lock 17B
localClassSetAnalysis.lock 17B
localJarClasspathSnapshot.lock 17B
buildOutputCleanup.lock 17B
taskArtifacts.lock 17B
localJarClasspathSnapshot.lock 17B
taskHistory.lock 17B
javaCompile.lock 17B
localClassSetAnalysis.lock 17B
localClassSetAnalysis.lock 17B
proguard.map 29KB
README.md 5KB
ic_launcher.png 4KB
ic_launcher.png 3KB
ic_launcher.png 2KB
proguard-rules.pro 19KB
local.properties 420B
gradle-wrapper.properties 230B
cache.properties 49B
共 119 条
- 1
- 2
资源评论
- zhenaigbb2020-07-10还可以。。
- charle_chen2019-09-26已下载,可用 不错的
- senheyuan2019-08-30先下载学习下
- 蓝火明之柱2019-05-31为什么用了手机串口调试示例软件点击了“发送读指令",结果是指令发送失败!,但是电脑端的串口助手也接收到了指令。
- namehehe2019-03-30我手机不是很好用呢NullPointer2019-04-02有什么问题呢,搜索列表弹不出来么?
NullPointer
- 粉丝: 7
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于paddle搭建神经网络实现水果识别分类python源码+数据集(高分项目).zip
- 三菱plc编程口通信学习笔记.doc
- 与HIS接口解决方案...doc
- 专利技术交底书-案例模板-软件类-样板示例.doc
- C# 超简单的人脸识别库 .zip
- 实现人脸识别资源代码.zip
- 东北大学-微机原理实验报告及答案-8255并行接口.doc
- 实现人脸检测,人脸识别,人脸标记68个坐标点 人脸对齐 人脸特征测试等 同时可以自行训练人脸识别库.zip
- 基于中科视拓 seetaface6基础源码和JNI源码编译而来的项目.zip
- Python基于opencv人脸识别的考勤系统源码+代码说明(毕业设计).zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功