kopia lustrzana https://github.com/mik3y/usb-serial-for-android
Add new interface method: getDevice().
rodzic
7a690f3ad2
commit
f801b31997
|
@ -3,5 +3,6 @@
|
|||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="gen"/>
|
||||
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
|
||||
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
|
||||
<classpathentry kind="output" path="bin/classes"/>
|
||||
</classpath>
|
||||
|
|
|
@ -20,15 +20,15 @@
|
|||
|
||||
package com.hoho.android.usbserial.driver;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import android.hardware.usb.UsbConstants;
|
||||
import android.hardware.usb.UsbDevice;
|
||||
import android.hardware.usb.UsbDeviceConnection;
|
||||
import android.hardware.usb.UsbEndpoint;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* A {@link UsbSerialDriver} implementation for a variety of FTDI devices
|
||||
* <p>
|
||||
|
@ -239,7 +239,7 @@ public class FtdiSerialDriver implements UsbSerialDriver {
|
|||
|
||||
@Override
|
||||
public int write(byte[] src, int timeoutMillis) throws IOException {
|
||||
final UsbEndpoint endpoint = mDevice.getInterface(0).getEndpoint(0);
|
||||
final UsbEndpoint endpoint = mDevice.getInterface(0).getEndpoint(1);
|
||||
int offset = 0;
|
||||
|
||||
while (offset < src.length) {
|
||||
|
@ -258,8 +258,9 @@ public class FtdiSerialDriver implements UsbSerialDriver {
|
|||
timeoutMillis);
|
||||
if (amt <= 0) {
|
||||
throw new IOException("Error writing " + writeLength
|
||||
+ " bytes at offset " + offset);
|
||||
+ " bytes at offset " + offset + " length=" + src.length);
|
||||
}
|
||||
Log.d(TAG, "Wrote amt=" + amt + " attempted=" + writeBuffer.length);
|
||||
offset += amt;
|
||||
}
|
||||
return offset;
|
||||
|
@ -373,4 +374,9 @@ public class FtdiSerialDriver implements UsbSerialDriver {
|
|||
return usbDevice.getVendorId() == 0x0403 && usbDevice.getProductId() == 0x6001;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UsbDevice getDevice() {
|
||||
return mDevice;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,6 +22,8 @@ package com.hoho.android.usbserial.driver;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import android.hardware.usb.UsbDevice;
|
||||
|
||||
/**
|
||||
* Driver interface for a supported USB serial device.
|
||||
*
|
||||
|
@ -32,7 +34,7 @@ public interface UsbSerialDriver {
|
|||
/**
|
||||
* Opens and initializes the device as a USB serial device. Upon success,
|
||||
* caller must ensure that {@link #close()} is eventually called.
|
||||
*
|
||||
*
|
||||
* @throws IOException on error opening or initializing the device.
|
||||
*/
|
||||
public void open() throws IOException;
|
||||
|
@ -73,4 +75,11 @@ public interface UsbSerialDriver {
|
|||
*/
|
||||
public int setBaudRate(final int baudRate) throws IOException;
|
||||
|
||||
/**
|
||||
* Returns the currently-bound USB device.
|
||||
*
|
||||
* @return the device
|
||||
*/
|
||||
public UsbDevice getDevice();
|
||||
|
||||
}
|
||||
|
|
|
@ -20,19 +20,19 @@
|
|||
|
||||
package com.hoho.android.usbserial.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import android.hardware.usb.UsbRequest;
|
||||
import android.util.Log;
|
||||
|
||||
import com.hoho.android.usbserial.driver.UsbSerialDriver;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/**
|
||||
* Utility class which services a {@link UsbSerialDriver} in its {@link #run()}
|
||||
* method.
|
||||
*
|
||||
* @author opensource@hoho.com (mike wakerly)
|
||||
* @author mike wakerly (opensource@hoho.com)
|
||||
*/
|
||||
public class SerialInputOutputManager implements Runnable {
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue