kopia lustrzana https://github.com/mik3y/usb-serial-for-android
UsbSerialPort: Add port number to interface.
rodzic
8a152071b4
commit
e4b3ed610c
|
@ -51,7 +51,7 @@ public class CdcAcmSerialDriver implements UsbSerialDriver {
|
|||
|
||||
public CdcAcmSerialDriver(UsbDevice device) {
|
||||
mDevice = device;
|
||||
mPort = new CdcAdcmSerialPort(device);
|
||||
mPort = new CdcAcmSerialPort(device, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -64,7 +64,7 @@ public class CdcAcmSerialDriver implements UsbSerialDriver {
|
|||
return Collections.singletonList(mPort);
|
||||
}
|
||||
|
||||
class CdcAdcmSerialPort extends CommonUsbSerialPort {
|
||||
class CdcAcmSerialPort extends CommonUsbSerialPort {
|
||||
|
||||
private UsbInterface mControlInterface;
|
||||
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 SEND_BREAK = 0x23;
|
||||
|
||||
public CdcAdcmSerialPort(UsbDevice device) {
|
||||
super(device);
|
||||
public CdcAcmSerialPort(UsbDevice device, int portNumber) {
|
||||
super(device, portNumber);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -37,6 +37,7 @@ abstract class CommonUsbSerialPort implements UsbSerialPort {
|
|||
public static final int DEFAULT_WRITE_BUFFER_SIZE = 16 * 1024;
|
||||
|
||||
protected final UsbDevice mDevice;
|
||||
protected final int mPortNumber;
|
||||
|
||||
// non-null when open()
|
||||
protected UsbDeviceConnection mConnection = null;
|
||||
|
@ -50,12 +51,20 @@ abstract class CommonUsbSerialPort implements UsbSerialPort {
|
|||
/** Internal write buffer. Guarded by {@link #mWriteBufferLock}. */
|
||||
protected byte[] mWriteBuffer;
|
||||
|
||||
public CommonUsbSerialPort(UsbDevice device) {
|
||||
public CommonUsbSerialPort(UsbDevice device, int portNumber) {
|
||||
mDevice = device;
|
||||
mPortNumber = portNumber;
|
||||
|
||||
mReadBuffer = new byte[DEFAULT_READ_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.
|
||||
|
@ -66,6 +75,11 @@ abstract class CommonUsbSerialPort implements UsbSerialPort {
|
|||
return mDevice;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPortNumber() {
|
||||
return mPortNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
|
|
|
@ -43,7 +43,7 @@ public class Cp21xxSerialDriver implements UsbSerialDriver {
|
|||
|
||||
public Cp21xxSerialDriver(UsbDevice device) {
|
||||
mDevice = device;
|
||||
mPort = new Cp21xxSerialPort(mDevice);
|
||||
mPort = new Cp21xxSerialPort(mDevice, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -104,8 +104,8 @@ public class Cp21xxSerialDriver implements UsbSerialDriver {
|
|||
private UsbEndpoint mReadEndpoint;
|
||||
private UsbEndpoint mWriteEndpoint;
|
||||
|
||||
public Cp21xxSerialPort(UsbDevice device) {
|
||||
super(device);
|
||||
public Cp21xxSerialPort(UsbDevice device, int portNumber) {
|
||||
super(device, portNumber);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -106,7 +106,7 @@ public class FtdiSerialDriver implements UsbSerialDriver {
|
|||
|
||||
public FtdiSerialDriver(UsbDevice device) {
|
||||
mDevice = device;
|
||||
mPort = new FtdiSerialPort(mDevice);
|
||||
mPort = new FtdiSerialPort(mDevice, 0);
|
||||
}
|
||||
@Override
|
||||
public UsbDevice getDevice() {
|
||||
|
@ -192,8 +192,8 @@ public class FtdiSerialDriver implements UsbSerialDriver {
|
|||
*/
|
||||
private static final boolean ENABLE_ASYNC_READS = false;
|
||||
|
||||
public FtdiSerialPort(UsbDevice device) {
|
||||
super(device);
|
||||
public FtdiSerialPort(UsbDevice device, int portNumber) {
|
||||
super(device, portNumber);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -50,7 +50,7 @@ public class ProlificSerialDriver implements UsbSerialDriver {
|
|||
|
||||
public ProlificSerialDriver(UsbDevice device) {
|
||||
mDevice = device;
|
||||
mPort = new ProlificSerialPort(mDevice);
|
||||
mPort = new ProlificSerialPort(mDevice, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -124,8 +124,8 @@ public class ProlificSerialDriver implements UsbSerialDriver {
|
|||
private IOException mReadStatusException = null;
|
||||
|
||||
|
||||
public ProlificSerialPort(UsbDevice device) {
|
||||
super(device);
|
||||
public ProlificSerialPort(UsbDevice device, int portNumber) {
|
||||
super(device, portNumber);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -85,6 +85,11 @@ public interface UsbSerialPort {
|
|||
public static final int STOPBITS_2 = 2;
|
||||
|
||||
public UsbSerialDriver getDriver();
|
||||
|
||||
/**
|
||||
* Port number within driver.
|
||||
*/
|
||||
public int getPortNumber();
|
||||
|
||||
/**
|
||||
* Opens and initializes the port. Upon success, caller must ensure that
|
||||
|
|
Ładowanie…
Reference in New Issue