mirror of
				https://github.com/mik3y/usb-serial-for-android
				synced 2025-10-31 02:17:23 +00:00 
			
		
		
		
	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.)
This commit is contained in:
		
							parent
							
								
									fe2eb8278b
								
							
						
					
					
						commit
						f73b485418
					
				| @ -3,6 +3,9 @@ Current Version (in development) | |||||||
|     setRTS. |     setRTS. | ||||||
|   * Library version is available in `com.hoho.android.usbserial.BuildInfo`. |   * Library version is available in `com.hoho.android.usbserial.BuildInfo`. | ||||||
|   * Adds probe support for LUFA CDC device. |   * 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) | v0.1.0 (2012-10-12) | ||||||
|   * New driver: CdcAcmSerialDriver. |   * New driver: CdcAcmSerialDriver. | ||||||
|  | |||||||
| @ -30,11 +30,6 @@ public class CdcAcmSerialDriver extends CommonUsbSerialDriver { | |||||||
|     private UsbEndpoint mReadEndpoint; |     private UsbEndpoint mReadEndpoint; | ||||||
|     private UsbEndpoint mWriteEndpoint; |     private UsbEndpoint mWriteEndpoint; | ||||||
| 
 | 
 | ||||||
|     private int mBaudRate; |  | ||||||
|     private int mDataBits; |  | ||||||
|     private int mStopBits; |  | ||||||
|     private int mParity; |  | ||||||
| 
 |  | ||||||
|     private boolean mRts = false; |     private boolean mRts = false; | ||||||
|     private boolean mDtr = false; |     private boolean mDtr = false; | ||||||
| 
 | 
 | ||||||
| @ -77,13 +72,6 @@ public class CdcAcmSerialDriver extends CommonUsbSerialDriver { | |||||||
|         Log.d(TAG, "Read endpoint direction: " + mReadEndpoint.getDirection()); |         Log.d(TAG, "Read endpoint direction: " + mReadEndpoint.getDirection()); | ||||||
|         mWriteEndpoint = mDataInterface.getEndpoint(0); |         mWriteEndpoint = mDataInterface.getEndpoint(0); | ||||||
|         Log.d(TAG, "Write endpoint direction: " + mWriteEndpoint.getDirection()); |         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) { |     private int sendAcmControlMessage(int request, int value, byte[] buf) { | ||||||
| @ -150,14 +138,6 @@ public class CdcAcmSerialDriver extends CommonUsbSerialDriver { | |||||||
|         return offset; |         return offset; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Deprecated |  | ||||||
|     @Override |  | ||||||
|     public int setBaudRate(int baudRate) throws IOException { |  | ||||||
|         mBaudRate = baudRate; |  | ||||||
|         setParameters(mBaudRate, mDataBits, mStopBits, mParity); |  | ||||||
|         return mBaudRate; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     @Override |     @Override | ||||||
|     public void setParameters(int baudRate, int dataBits, int stopBits, int parity) { |     public void setParameters(int baudRate, int dataBits, int stopBits, int parity) { | ||||||
|         byte stopBitsByte; |         byte stopBitsByte; | ||||||
|  | |||||||
| @ -106,10 +106,6 @@ abstract class CommonUsbSerialDriver implements UsbSerialDriver { | |||||||
|     @Override |     @Override | ||||||
|     public abstract int write(final byte[] src, final int timeoutMillis) throws IOException; |     public abstract int write(final byte[] src, final int timeoutMillis) throws IOException; | ||||||
| 
 | 
 | ||||||
|     @Override |  | ||||||
|     @Deprecated |  | ||||||
|     public abstract int setBaudRate(final int baudRate) throws IOException; |  | ||||||
| 
 |  | ||||||
|     @Override |     @Override | ||||||
|     public abstract void setParameters( |     public abstract void setParameters( | ||||||
|             int baudRate, int dataBits, int stopBits, int parity) throws IOException; |             int baudRate, int dataBits, int stopBits, int parity) throws IOException; | ||||||
|  | |||||||
| @ -162,18 +162,18 @@ public class Cp2102SerialDriver extends CommonUsbSerialDriver { | |||||||
|         return offset; |         return offset; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Override |     private void setBaudRate(int baudRate) throws IOException {    | ||||||
|     @Deprecated |  | ||||||
|     public int setBaudRate(int baudRate) throws IOException {    |  | ||||||
|         byte[] data = new byte[] { |         byte[] data = new byte[] { | ||||||
|                 (byte) ( baudRate & 0xff), |                 (byte) ( baudRate & 0xff), | ||||||
|                 (byte) ((baudRate >> 8 ) & 0xff), |                 (byte) ((baudRate >> 8 ) & 0xff), | ||||||
|                 (byte) ((baudRate >> 16) & 0xff), |                 (byte) ((baudRate >> 16) & 0xff), | ||||||
|                 (byte) ((baudRate >> 24) & 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); |                 0, 0, data, 4, USB_WRITE_TIMEOUT_MILLIS); | ||||||
|         return baudRate; |         if (ret < 0) { | ||||||
|  |             throw new IOException("Error setting baud rate."); | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|  | |||||||
| @ -89,11 +89,6 @@ import java.util.Map; | |||||||
|  */ |  */ | ||||||
| public class FtdiSerialDriver extends CommonUsbSerialDriver { | 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_STANDARD = 0x00 << 5; | ||||||
|     public static final int USB_TYPE_CLASS = 0x00 << 5; |     public static final int USB_TYPE_CLASS = 0x00 << 5; | ||||||
|     public static final int USB_TYPE_VENDOR = 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 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 |      * 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 |      * 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)) { |                 if (mConnection.claimInterface(mDevice.getInterface(i), true)) { | ||||||
|                     Log.d(TAG, "claimInterface " + i + " SUCCESS"); |                     Log.d(TAG, "claimInterface " + i + " SUCCESS"); | ||||||
|                 } else { |                 } else { | ||||||
|                     Log.d(TAG, "claimInterface " + i + " FAIL"); |                     throw new IOException("Error claiming interface " + i); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|             reset(); |             reset(); | ||||||
|             setParameters(DEFAULT_BAUD_RATE, DEFAULT_DATA_BITS, DEFAULT_STOP_BITS, DEFAULT_PARITY); |  | ||||||
|             opened = true; |             opened = true; | ||||||
|         } finally { |         } finally { | ||||||
|             if (!opened) { |             if (!opened) { | ||||||
| @ -314,9 +303,7 @@ public class FtdiSerialDriver extends CommonUsbSerialDriver { | |||||||
|         return offset; |         return offset; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Override |     private int setBaudRate(int baudRate) throws IOException { | ||||||
|     @Deprecated |  | ||||||
|     public int setBaudRate(int baudRate) throws IOException { |  | ||||||
|         long[] vals = convertBaudrate(baudRate); |         long[] vals = convertBaudrate(baudRate); | ||||||
|         long actualBaudrate = vals[0]; |         long actualBaudrate = vals[0]; | ||||||
|         long index = vals[1]; |         long index = vals[1]; | ||||||
| @ -333,7 +320,7 @@ public class FtdiSerialDriver extends CommonUsbSerialDriver { | |||||||
|     @Override |     @Override | ||||||
|     public void setParameters(int baudRate, int dataBits, int stopBits, int parity) |     public void setParameters(int baudRate, int dataBits, int stopBits, int parity) | ||||||
|             throws IOException { |             throws IOException { | ||||||
|         mBaudRate = setBaudRate(baudRate); |         setBaudRate(baudRate); | ||||||
| 
 | 
 | ||||||
|         int config = dataBits; |         int config = dataBits; | ||||||
| 
 | 
 | ||||||
| @ -377,10 +364,6 @@ public class FtdiSerialDriver extends CommonUsbSerialDriver { | |||||||
|         if (result != 0) { |         if (result != 0) { | ||||||
|             throw new IOException("Setting parameters failed: result=" + result); |             throw new IOException("Setting parameters failed: result=" + result); | ||||||
|         } |         } | ||||||
| 
 |  | ||||||
|         mParity = parity; |  | ||||||
|         mStopBits = stopBits; |  | ||||||
|         mDataBits = dataBits; |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private long[] convertBaudrate(int baudrate) { |     private long[] convertBaudrate(int baudrate) { | ||||||
|  | |||||||
| @ -115,17 +115,6 @@ public interface UsbSerialDriver { | |||||||
|      */ |      */ | ||||||
|     public int write(final byte[] src, final int timeoutMillis) throws IOException; |     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. |      * Sets various serial port parameters. | ||||||
|      * |      * | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user