1
0
mirror of https://github.com/mik3y/usb-serial-for-android synced 2025-06-07 16:06:10 +00:00

Merge pull request #137 from shanet/readme_fixes

Readme fixes
This commit is contained in:
mike w 2016-09-11 16:30:05 -04:00 committed by GitHub
commit 6d8c40a71c

View File

@ -17,9 +17,9 @@ functions for use with your own protocols.
**1.** [Link your project](https://github.com/mik3y/usb-serial-for-android/wiki/Building-From-Source) to the library. **1.** [Link your project](https://github.com/mik3y/usb-serial-for-android/wiki/Building-From-Source) to the library.
**2.** Copy [device_filter.xml](http://usb-serial-for-android.googlecode.com/git/UsbSerialExamples/res/xml/device_filter.xml) to your project's `res/xml/` directory. **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). **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 ```xml
<activity <activity
@ -29,12 +29,12 @@ functions for use with your own protocols.
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" /> <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
</intent-filter> </intent-filter>
<meta-data <meta-data
android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
android:resource="@xml/device_filter" /> android:resource="@xml/device_filter" />
</activity> </activity>
``` ```
**5.** Use it! Example code snippet: **4.** Use it! Example code snippet:
```java ```java
// Find all available drivers from attached devices. // Find all available drivers from attached devices.
@ -53,10 +53,11 @@ if (connection == null) {
} }
// Read some data! Most have just one port (port 0). // Read some data! Most have just one port (port 0).
UsbSerialPort port = driver.getPort(0); UsbSerialPort port = driver.getPorts().get(0);
port.open(connection);
try { try {
port.setBaudRate(115200); port.open(connection);
port.setParameters(115200, 8, UsbSerialPort.STOPBITS_1, UsbSerialPort.PARITY_NONE);
byte buffer[] = new byte[16]; byte buffer[] = new byte[16];
int numBytesRead = port.read(buffer, 1000); int numBytesRead = port.read(buffer, 1000);
Log.d(TAG, "Read " + numBytesRead + " bytes."); Log.d(TAG, "Read " + numBytesRead + " bytes.");