mirror of
				https://github.com/mik3y/usb-serial-for-android
				synced 2025-11-04 12:28:17 +00:00 
			
		
		
		
	Improved DTR and RTS support. DTR and RTS can now be queried after transmission. Added usage of existing methods and new constants.
This commit is contained in:
		
							parent
							
								
									92b16a8c24
								
							
						
					
					
						commit
						89ad5be9c3
					
				@ -78,6 +78,7 @@ public class Cp21xxSerialDriver implements UsbSerialDriver {
 | 
				
			|||||||
        private static final int SILABSER_SET_MHS_REQUEST_CODE = 0x07;
 | 
					        private static final int SILABSER_SET_MHS_REQUEST_CODE = 0x07;
 | 
				
			||||||
        private static final int SILABSER_SET_BAUDRATE = 0x1E;
 | 
					        private static final int SILABSER_SET_BAUDRATE = 0x1E;
 | 
				
			||||||
        private static final int SILABSER_FLUSH_REQUEST_CODE = 0x12;
 | 
					        private static final int SILABSER_FLUSH_REQUEST_CODE = 0x12;
 | 
				
			||||||
 | 
					        private static final int SILABSER_SET_DTR_RTS_REQUEST_CODE = 0x07;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
       private static final int FLUSH_READ_CODE = 0x0a;
 | 
					       private static final int FLUSH_READ_CODE = 0x0a;
 | 
				
			||||||
       private static final int FLUSH_WRITE_CODE = 0x05;
 | 
					       private static final int FLUSH_WRITE_CODE = 0x05;
 | 
				
			||||||
@ -103,6 +104,21 @@ public class Cp21xxSerialDriver implements UsbSerialDriver {
 | 
				
			|||||||
        private static final int CONTROL_WRITE_DTR = 0x0100;
 | 
					        private static final int CONTROL_WRITE_DTR = 0x0100;
 | 
				
			||||||
        private static final int CONTROL_WRITE_RTS = 0x0200;
 | 
					        private static final int CONTROL_WRITE_RTS = 0x0200;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /*
 | 
				
			||||||
 | 
					         * SILABSER_SET_DTR_RTS_REQUEST_CODE
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        private static final int DTR_ENABLE = 0x101;
 | 
				
			||||||
 | 
					        private static final int DTR_DISABLE = 0x100;
 | 
				
			||||||
 | 
					        private static final int RTS_ENABLE = 0x202;
 | 
				
			||||||
 | 
					        private static final int RTS_DISABLE = 0x200;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        private UsbEndpoint mReadEndpoint;
 | 
				
			||||||
 | 
					        private UsbEndpoint mWriteEndpoint;
 | 
				
			||||||
 | 
					        private UsbRequest mUsbRequest;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        private boolean dtr = false;
 | 
				
			||||||
 | 
					        private boolean rts = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // second port of Cp2105 has limited baudRate, dataBits, stopBits, parity
 | 
					        // second port of Cp2105 has limited baudRate, dataBits, stopBits, parity
 | 
				
			||||||
        // unsupported baudrate returns error at controlTransfer(), other parameters are silently ignored
 | 
					        // unsupported baudrate returns error at controlTransfer(), other parameters are silently ignored
 | 
				
			||||||
        private boolean mIsRestrictedPort;
 | 
					        private boolean mIsRestrictedPort;
 | 
				
			||||||
@ -276,19 +292,13 @@ public class Cp21xxSerialDriver implements UsbSerialDriver {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        @Override
 | 
					        @Override
 | 
				
			||||||
        public boolean getDTR() throws IOException {
 | 
					        public boolean getDTR() throws IOException {
 | 
				
			||||||
            return true;
 | 
					            return dtr;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        @Override
 | 
					        @Override
 | 
				
			||||||
        public void setDTR(boolean value) throws IOException {
 | 
					        public void setDTR(boolean value) throws IOException {
 | 
				
			||||||
            mConnection.controlTransfer(
 | 
					            dtr = value;
 | 
				
			||||||
                    UsbConstants.USB_DIR_OUT | UsbConstants.USB_TYPE_VENDOR | 0x01,
 | 
					            setConfigSingle(SILABSER_SET_DTR_RTS_REQUEST_CODE, dtr ? DTR_ENABLE : DTR_DISABLE);
 | 
				
			||||||
                    0x07,
 | 
					 | 
				
			||||||
                    value ? 0x101 : 0x100,
 | 
					 | 
				
			||||||
                    0,
 | 
					 | 
				
			||||||
                    null,
 | 
					 | 
				
			||||||
                    0,
 | 
					 | 
				
			||||||
                    2000);
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        @Override
 | 
					        @Override
 | 
				
			||||||
@ -298,19 +308,13 @@ public class Cp21xxSerialDriver implements UsbSerialDriver {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        @Override
 | 
					        @Override
 | 
				
			||||||
        public boolean getRTS() throws IOException {
 | 
					        public boolean getRTS() throws IOException {
 | 
				
			||||||
            return true;
 | 
					            return rts;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        @Override
 | 
					        @Override
 | 
				
			||||||
        public void setRTS(boolean value) throws IOException {
 | 
					        public void setRTS(boolean value) throws IOException {
 | 
				
			||||||
            mConnection.controlTransfer(
 | 
					            rts = value;
 | 
				
			||||||
                0x41,
 | 
					            setConfigSingle(SILABSER_SET_DTR_RTS_REQUEST_CODE, rts ? RTS_ENABLE : RTS_DISABLE);
 | 
				
			||||||
                0x07,
 | 
					 | 
				
			||||||
                value ? 0x202 : 0x200,
 | 
					 | 
				
			||||||
                0,
 | 
					 | 
				
			||||||
                null,
 | 
					 | 
				
			||||||
                0,
 | 
					 | 
				
			||||||
                2000);
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        @Override
 | 
					        @Override
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user