mirror of
https://github.com/mik3y/usb-serial-for-android
synced 2025-07-23 09:55:40 +00:00
fix example code in README
This commit is contained in:
parent
3479892809
commit
1ef426920f
@ -34,7 +34,7 @@ functions for use with your own protocols.
|
|||||||
</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.");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user