Improved DTR and RTS support. DTR and RTS can now be queried after transmission. Added usage of existing methods and new constants.

pull/240/head
Tim Vahlbrock 2019-11-14 14:44:39 +01:00
rodzic 92b16a8c24
commit 89ad5be9c3
1 zmienionych plików z 22 dodań i 18 usunięć

Wyświetl plik

@ -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_BAUDRATE = 0x1E;
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_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_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
// unsupported baudrate returns error at controlTransfer(), other parameters are silently ignored
private boolean mIsRestrictedPort;
@ -276,19 +292,13 @@ public class Cp21xxSerialDriver implements UsbSerialDriver {
@Override
public boolean getDTR() throws IOException {
return true;
return dtr;
}
@Override
public void setDTR(boolean value) throws IOException {
mConnection.controlTransfer(
UsbConstants.USB_DIR_OUT | UsbConstants.USB_TYPE_VENDOR | 0x01,
0x07,
value ? 0x101 : 0x100,
0,
null,
0,
2000);
dtr = value;
setConfigSingle(SILABSER_SET_DTR_RTS_REQUEST_CODE, dtr ? DTR_ENABLE : DTR_DISABLE);
}
@Override
@ -298,19 +308,13 @@ public class Cp21xxSerialDriver implements UsbSerialDriver {
@Override
public boolean getRTS() throws IOException {
return true;
return rts;
}
@Override
public void setRTS(boolean value) throws IOException {
mConnection.controlTransfer(
0x41,
0x07,
value ? 0x202 : 0x200,
0,
null,
0,
2000);
rts = value;
setConfigSingle(SILABSER_SET_DTR_RTS_REQUEST_CODE, rts ? RTS_ENABLE : RTS_DISABLE);
}
@Override