1
0
mirror of https://github.com/mik3y/usb-serial-for-android synced 2025-06-09 17:06:21 +00:00

UsbSerialPort: Add port number to interface.

This commit is contained in:
mike wakerly 2014-02-04 14:22:14 -08:00
parent 8a152071b4
commit e4b3ed610c
6 changed files with 33 additions and 14 deletions

View File

@ -51,7 +51,7 @@ public class CdcAcmSerialDriver implements UsbSerialDriver {
public CdcAcmSerialDriver(UsbDevice device) { public CdcAcmSerialDriver(UsbDevice device) {
mDevice = device; mDevice = device;
mPort = new CdcAdcmSerialPort(device); mPort = new CdcAcmSerialPort(device, 0);
} }
@Override @Override
@ -64,7 +64,7 @@ public class CdcAcmSerialDriver implements UsbSerialDriver {
return Collections.singletonList(mPort); return Collections.singletonList(mPort);
} }
class CdcAdcmSerialPort extends CommonUsbSerialPort { class CdcAcmSerialPort extends CommonUsbSerialPort {
private UsbInterface mControlInterface; private UsbInterface mControlInterface;
private UsbInterface mDataInterface; private UsbInterface mDataInterface;
@ -84,8 +84,8 @@ public class CdcAcmSerialDriver implements UsbSerialDriver {
private static final int SET_CONTROL_LINE_STATE = 0x22; private static final int SET_CONTROL_LINE_STATE = 0x22;
private static final int SEND_BREAK = 0x23; private static final int SEND_BREAK = 0x23;
public CdcAdcmSerialPort(UsbDevice device) { public CdcAcmSerialPort(UsbDevice device, int portNumber) {
super(device); super(device, portNumber);
} }
@Override @Override

View File

@ -37,6 +37,7 @@ abstract class CommonUsbSerialPort implements UsbSerialPort {
public static final int DEFAULT_WRITE_BUFFER_SIZE = 16 * 1024; public static final int DEFAULT_WRITE_BUFFER_SIZE = 16 * 1024;
protected final UsbDevice mDevice; protected final UsbDevice mDevice;
protected final int mPortNumber;
// non-null when open() // non-null when open()
protected UsbDeviceConnection mConnection = null; protected UsbDeviceConnection mConnection = null;
@ -50,12 +51,20 @@ abstract class CommonUsbSerialPort implements UsbSerialPort {
/** Internal write buffer. Guarded by {@link #mWriteBufferLock}. */ /** Internal write buffer. Guarded by {@link #mWriteBufferLock}. */
protected byte[] mWriteBuffer; protected byte[] mWriteBuffer;
public CommonUsbSerialPort(UsbDevice device) { public CommonUsbSerialPort(UsbDevice device, int portNumber) {
mDevice = device; mDevice = device;
mPortNumber = portNumber;
mReadBuffer = new byte[DEFAULT_READ_BUFFER_SIZE]; mReadBuffer = new byte[DEFAULT_READ_BUFFER_SIZE];
mWriteBuffer = new byte[DEFAULT_WRITE_BUFFER_SIZE]; mWriteBuffer = new byte[DEFAULT_WRITE_BUFFER_SIZE];
} }
@Override
public String toString() {
return String.format("<%s device_name=%s device_id=%s port_number=%s>",
getClass().getSimpleName(), mDevice.getDeviceName(),
mDevice.getDeviceId(), mPortNumber);
}
/** /**
* Returns the currently-bound USB device. * Returns the currently-bound USB device.
@ -66,6 +75,11 @@ abstract class CommonUsbSerialPort implements UsbSerialPort {
return mDevice; return mDevice;
} }
@Override
public int getPortNumber() {
return mPortNumber;
}
/** /**
* Sets the size of the internal buffer used to exchange data with the USB * Sets the size of the internal buffer used to exchange data with the USB
* stack for read operations. Most users should not need to change this. * stack for read operations. Most users should not need to change this.

View File

@ -43,7 +43,7 @@ public class Cp21xxSerialDriver implements UsbSerialDriver {
public Cp21xxSerialDriver(UsbDevice device) { public Cp21xxSerialDriver(UsbDevice device) {
mDevice = device; mDevice = device;
mPort = new Cp21xxSerialPort(mDevice); mPort = new Cp21xxSerialPort(mDevice, 0);
} }
@Override @Override
@ -104,8 +104,8 @@ public class Cp21xxSerialDriver implements UsbSerialDriver {
private UsbEndpoint mReadEndpoint; private UsbEndpoint mReadEndpoint;
private UsbEndpoint mWriteEndpoint; private UsbEndpoint mWriteEndpoint;
public Cp21xxSerialPort(UsbDevice device) { public Cp21xxSerialPort(UsbDevice device, int portNumber) {
super(device); super(device, portNumber);
} }
@Override @Override

View File

@ -106,7 +106,7 @@ public class FtdiSerialDriver implements UsbSerialDriver {
public FtdiSerialDriver(UsbDevice device) { public FtdiSerialDriver(UsbDevice device) {
mDevice = device; mDevice = device;
mPort = new FtdiSerialPort(mDevice); mPort = new FtdiSerialPort(mDevice, 0);
} }
@Override @Override
public UsbDevice getDevice() { public UsbDevice getDevice() {
@ -192,8 +192,8 @@ public class FtdiSerialDriver implements UsbSerialDriver {
*/ */
private static final boolean ENABLE_ASYNC_READS = false; private static final boolean ENABLE_ASYNC_READS = false;
public FtdiSerialPort(UsbDevice device) { public FtdiSerialPort(UsbDevice device, int portNumber) {
super(device); super(device, portNumber);
} }
@Override @Override

View File

@ -50,7 +50,7 @@ public class ProlificSerialDriver implements UsbSerialDriver {
public ProlificSerialDriver(UsbDevice device) { public ProlificSerialDriver(UsbDevice device) {
mDevice = device; mDevice = device;
mPort = new ProlificSerialPort(mDevice); mPort = new ProlificSerialPort(mDevice, 0);
} }
@Override @Override
@ -124,8 +124,8 @@ public class ProlificSerialDriver implements UsbSerialDriver {
private IOException mReadStatusException = null; private IOException mReadStatusException = null;
public ProlificSerialPort(UsbDevice device) { public ProlificSerialPort(UsbDevice device, int portNumber) {
super(device); super(device, portNumber);
} }
@Override @Override

View File

@ -85,6 +85,11 @@ public interface UsbSerialPort {
public static final int STOPBITS_2 = 2; public static final int STOPBITS_2 = 2;
public UsbSerialDriver getDriver(); public UsbSerialDriver getDriver();
/**
* Port number within driver.
*/
public int getPortNumber();
/** /**
* Opens and initializes the port. Upon success, caller must ensure that * Opens and initializes the port. Upon success, caller must ensure that