Add new interface method: getDevice().

pull/36/head
mike wakerly 2012-06-26 23:13:21 -07:00
rodzic 7a690f3ad2
commit f801b31997
4 zmienionych plików z 26 dodań i 10 usunięć

Wyświetl plik

@ -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>

Wyświetl plik

@ -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;
}
}

Wyświetl plik

@ -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();
}

Wyświetl plik

@ -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 {