mirror of
https://github.com/mik3y/usb-serial-for-android
synced 2025-06-10 01:16:27 +00:00
Add new interface method: getDevice().
This commit is contained in:
parent
7a690f3ad2
commit
f801b31997
@ -3,5 +3,6 @@
|
|||||||
<classpathentry kind="src" path="src"/>
|
<classpathentry kind="src" path="src"/>
|
||||||
<classpathentry kind="src" path="gen"/>
|
<classpathentry kind="src" path="gen"/>
|
||||||
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
|
<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"/>
|
<classpathentry kind="output" path="bin/classes"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
@ -20,15 +20,15 @@
|
|||||||
|
|
||||||
package com.hoho.android.usbserial.driver;
|
package com.hoho.android.usbserial.driver;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
import android.hardware.usb.UsbConstants;
|
import android.hardware.usb.UsbConstants;
|
||||||
import android.hardware.usb.UsbDevice;
|
import android.hardware.usb.UsbDevice;
|
||||||
import android.hardware.usb.UsbDeviceConnection;
|
import android.hardware.usb.UsbDeviceConnection;
|
||||||
import android.hardware.usb.UsbEndpoint;
|
import android.hardware.usb.UsbEndpoint;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link UsbSerialDriver} implementation for a variety of FTDI devices
|
* A {@link UsbSerialDriver} implementation for a variety of FTDI devices
|
||||||
* <p>
|
* <p>
|
||||||
@ -239,7 +239,7 @@ public class FtdiSerialDriver implements UsbSerialDriver {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int write(byte[] src, int timeoutMillis) throws IOException {
|
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;
|
int offset = 0;
|
||||||
|
|
||||||
while (offset < src.length) {
|
while (offset < src.length) {
|
||||||
@ -258,8 +258,9 @@ public class FtdiSerialDriver implements UsbSerialDriver {
|
|||||||
timeoutMillis);
|
timeoutMillis);
|
||||||
if (amt <= 0) {
|
if (amt <= 0) {
|
||||||
throw new IOException("Error writing " + writeLength
|
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;
|
offset += amt;
|
||||||
}
|
}
|
||||||
return offset;
|
return offset;
|
||||||
@ -373,4 +374,9 @@ public class FtdiSerialDriver implements UsbSerialDriver {
|
|||||||
return usbDevice.getVendorId() == 0x0403 && usbDevice.getProductId() == 0x6001;
|
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 java.io.IOException;
|
||||||
|
|
||||||
|
import android.hardware.usb.UsbDevice;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Driver interface for a supported USB serial device.
|
* Driver interface for a supported USB serial device.
|
||||||
*
|
*
|
||||||
@ -73,4 +75,11 @@ public interface UsbSerialDriver {
|
|||||||
*/
|
*/
|
||||||
public int setBaudRate(final int baudRate) throws IOException;
|
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;
|
package com.hoho.android.usbserial.util;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
import android.hardware.usb.UsbRequest;
|
import android.hardware.usb.UsbRequest;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.hoho.android.usbserial.driver.UsbSerialDriver;
|
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()}
|
* Utility class which services a {@link UsbSerialDriver} in its {@link #run()}
|
||||||
* method.
|
* method.
|
||||||
*
|
*
|
||||||
* @author opensource@hoho.com (mike wakerly)
|
* @author mike wakerly (opensource@hoho.com)
|
||||||
*/
|
*/
|
||||||
public class SerialInputOutputManager implements Runnable {
|
public class SerialInputOutputManager implements Runnable {
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user