Remove setBaudRate(); do not touch line config in open().

Callers should call setParameters() after open() (and now have the option of
skipping this step where feasible.)
pull/36/head
mike wakerly 2013-04-07 22:40:55 -07:00
rodzic fe2eb8278b
commit f73b485418
6 zmienionych plików z 11 dodań i 60 usunięć

Wyświetl plik

@ -3,6 +3,9 @@ Current Version (in development)
setRTS.
* Library version is available in `com.hoho.android.usbserial.BuildInfo`.
* Adds probe support for LUFA CDC device.
* setBaudrate() has been removed; use setParameters().
* open() no longer implicitly sets the baud rate. Clients should call
setParameters() immediately after open(), when necessary.
v0.1.0 (2012-10-12)
* New driver: CdcAcmSerialDriver.

Wyświetl plik

@ -30,11 +30,6 @@ public class CdcAcmSerialDriver extends CommonUsbSerialDriver {
private UsbEndpoint mReadEndpoint;
private UsbEndpoint mWriteEndpoint;
private int mBaudRate;
private int mDataBits;
private int mStopBits;
private int mParity;
private boolean mRts = false;
private boolean mDtr = false;
@ -77,13 +72,6 @@ public class CdcAcmSerialDriver extends CommonUsbSerialDriver {
Log.d(TAG, "Read endpoint direction: " + mReadEndpoint.getDirection());
mWriteEndpoint = mDataInterface.getEndpoint(0);
Log.d(TAG, "Write endpoint direction: " + mWriteEndpoint.getDirection());
Log.d(TAG, "Setting line coding to 115200/8N1");
mBaudRate = 115200;
mDataBits = DATABITS_8;
mParity = PARITY_NONE;
mStopBits = STOPBITS_1;
setParameters(mBaudRate, mDataBits, mStopBits, mParity);
}
private int sendAcmControlMessage(int request, int value, byte[] buf) {
@ -150,14 +138,6 @@ public class CdcAcmSerialDriver extends CommonUsbSerialDriver {
return offset;
}
@Deprecated
@Override
public int setBaudRate(int baudRate) throws IOException {
mBaudRate = baudRate;
setParameters(mBaudRate, mDataBits, mStopBits, mParity);
return mBaudRate;
}
@Override
public void setParameters(int baudRate, int dataBits, int stopBits, int parity) {
byte stopBitsByte;

Wyświetl plik

@ -106,10 +106,6 @@ abstract class CommonUsbSerialDriver implements UsbSerialDriver {
@Override
public abstract int write(final byte[] src, final int timeoutMillis) throws IOException;
@Override
@Deprecated
public abstract int setBaudRate(final int baudRate) throws IOException;
@Override
public abstract void setParameters(
int baudRate, int dataBits, int stopBits, int parity) throws IOException;

Wyświetl plik

@ -162,18 +162,18 @@ public class Cp2102SerialDriver extends CommonUsbSerialDriver {
return offset;
}
@Override
@Deprecated
public int setBaudRate(int baudRate) throws IOException {
private void setBaudRate(int baudRate) throws IOException {
byte[] data = new byte[] {
(byte) ( baudRate & 0xff),
(byte) ((baudRate >> 8 ) & 0xff),
(byte) ((baudRate >> 16) & 0xff),
(byte) ((baudRate >> 24) & 0xff)
};
mConnection.controlTransfer(REQTYPE_HOST_TO_DEVICE, SILABSER_SET_BAUDRATE,
int ret = mConnection.controlTransfer(REQTYPE_HOST_TO_DEVICE, SILABSER_SET_BAUDRATE,
0, 0, data, 4, USB_WRITE_TIMEOUT_MILLIS);
return baudRate;
if (ret < 0) {
throw new IOException("Error setting baud rate.");
}
}
@Override

Wyświetl plik

@ -89,11 +89,6 @@ import java.util.Map;
*/
public class FtdiSerialDriver extends CommonUsbSerialDriver {
private static final int DEFAULT_BAUD_RATE = 115200;
private static final int DEFAULT_DATA_BITS = DATABITS_8;
private static final int DEFAULT_PARITY = PARITY_NONE;
private static final int DEFAULT_STOP_BITS = STOPBITS_1;
public static final int USB_TYPE_STANDARD = 0x00 << 5;
public static final int USB_TYPE_CLASS = 0x00 << 5;
public static final int USB_TYPE_VENDOR = 0x00 << 5;
@ -164,11 +159,6 @@ public class FtdiSerialDriver extends CommonUsbSerialDriver {
private int mMaxPacketSize = 64; // TODO(mikey): detect
private int mBaudRate;
private int mDataBits;
private int mParity;
private int mStopBits;
/**
* Due to http://b.android.com/28023 , we cannot use UsbRequest async reads
* since it gives no indication of number of bytes read. Set this to
@ -208,11 +198,10 @@ public class FtdiSerialDriver extends CommonUsbSerialDriver {
if (mConnection.claimInterface(mDevice.getInterface(i), true)) {
Log.d(TAG, "claimInterface " + i + " SUCCESS");
} else {
Log.d(TAG, "claimInterface " + i + " FAIL");
throw new IOException("Error claiming interface " + i);
}
}
reset();
setParameters(DEFAULT_BAUD_RATE, DEFAULT_DATA_BITS, DEFAULT_STOP_BITS, DEFAULT_PARITY);
opened = true;
} finally {
if (!opened) {
@ -314,9 +303,7 @@ public class FtdiSerialDriver extends CommonUsbSerialDriver {
return offset;
}
@Override
@Deprecated
public int setBaudRate(int baudRate) throws IOException {
private int setBaudRate(int baudRate) throws IOException {
long[] vals = convertBaudrate(baudRate);
long actualBaudrate = vals[0];
long index = vals[1];
@ -333,7 +320,7 @@ public class FtdiSerialDriver extends CommonUsbSerialDriver {
@Override
public void setParameters(int baudRate, int dataBits, int stopBits, int parity)
throws IOException {
mBaudRate = setBaudRate(baudRate);
setBaudRate(baudRate);
int config = dataBits;
@ -377,10 +364,6 @@ public class FtdiSerialDriver extends CommonUsbSerialDriver {
if (result != 0) {
throw new IOException("Setting parameters failed: result=" + result);
}
mParity = parity;
mStopBits = stopBits;
mDataBits = dataBits;
}
private long[] convertBaudrate(int baudrate) {

Wyświetl plik

@ -115,17 +115,6 @@ public interface UsbSerialDriver {
*/
public int write(final byte[] src, final int timeoutMillis) throws IOException;
/**
* Sets the baud rate of the serial device.
*
* @param baudRate the desired baud rate, in bits per second
* @return the actual rate set
* @throws IOException on error setting the baud rate
* @deprecated Use {@link #setParameters(int, int, int, int)} instead of this method.
*/
@Deprecated
public int setBaudRate(final int baudRate) throws IOException;
/**
* Sets various serial port parameters.
*