1
0
mirror of https://github.com/mik3y/usb-serial-for-android.git synced 2026-08-15 18:33:02 +00:00

throw UnsupportedOperationException instead of returning false

This commit is contained in:
kai-morich
2020-07-31 21:02:59 +02:00
parent 954295456c
commit a664082f23
10 changed files with 109 additions and 93 deletions
@@ -239,21 +239,6 @@ public class CdcAcmSerialDriver implements UsbSerialDriver {
sendAcmControlMessage(SET_LINE_CODING, 0, msg);
}
@Override
public boolean getCD() throws IOException {
return false; // TODO
}
@Override
public boolean getCTS() throws IOException {
return false; // TODO
}
@Override
public boolean getDSR() throws IOException {
return false; // TODO
}
@Override
public boolean getDTR() throws IOException {
return mDtr;
@@ -265,11 +250,6 @@ public class CdcAcmSerialDriver implements UsbSerialDriver {
setDtrRts();
}
@Override
public boolean getRI() throws IOException {
return false; // TODO
}
@Override
public boolean getRTS() throws IOException {
return mRts;
@@ -212,28 +212,28 @@ public abstract class CommonUsbSerialPort implements UsbSerialPort {
public abstract void setParameters(int baudRate, int dataBits, int stopBits, int parity) throws IOException;
@Override
public abstract boolean getCD() throws IOException;
public boolean getCD() throws IOException { throw new UnsupportedOperationException(); }
@Override
public abstract boolean getCTS() throws IOException;
public boolean getCTS() throws IOException { throw new UnsupportedOperationException(); }
@Override
public abstract boolean getDSR() throws IOException;
public boolean getDSR() throws IOException { throw new UnsupportedOperationException(); }
@Override
public abstract boolean getDTR() throws IOException;
public boolean getDTR() throws IOException { throw new UnsupportedOperationException(); }
@Override
public abstract void setDTR(boolean value) throws IOException;
public void setDTR(boolean value) throws IOException { throw new UnsupportedOperationException(); }
@Override
public abstract boolean getRI() throws IOException;
public boolean getRI() throws IOException { throw new UnsupportedOperationException(); }
@Override
public abstract boolean getRTS() throws IOException;
public boolean getRTS() throws IOException { throw new UnsupportedOperationException(); }
@Override
public abstract void setRTS(boolean value) throws IOException;
public void setRTS(boolean value) throws IOException { throw new UnsupportedOperationException(); }
@Override
public abstract EnumSet<ControlLine> getControlLines() throws IOException;
@@ -242,8 +242,8 @@ public abstract class CommonUsbSerialPort implements UsbSerialPort {
public abstract EnumSet<ControlLine> getSupportedControlLines() throws IOException;
@Override
public boolean purgeHwBuffers(boolean purgeWriteBuffers, boolean purgeReadBuffers) throws IOException {
return false;
public void purgeHwBuffers(boolean purgeWriteBuffers, boolean purgeReadBuffers) throws IOException {
throw new UnsupportedOperationException();
}
}
@@ -305,15 +305,13 @@ public class Cp21xxSerialDriver implements UsbSerialDriver {
@Override
// note: only working on some devices, on other devices ignored w/o error
public boolean purgeHwBuffers(boolean purgeWriteBuffers, boolean purgeReadBuffers) throws IOException {
public void purgeHwBuffers(boolean purgeWriteBuffers, boolean purgeReadBuffers) throws IOException {
int value = (purgeReadBuffers ? FLUSH_READ_CODE : 0)
| (purgeWriteBuffers ? FLUSH_WRITE_CODE : 0);
if (value != 0) {
setConfigSingle(SILABSER_FLUSH_REQUEST_CODE, value);
}
return true;
}
}
@@ -337,7 +337,7 @@ public class FtdiSerialDriver implements UsbSerialDriver {
}
@Override
public boolean purgeHwBuffers(boolean purgeWriteBuffers, boolean purgeReadBuffers) throws IOException {
public void purgeHwBuffers(boolean purgeWriteBuffers, boolean purgeReadBuffers) throws IOException {
if (purgeWriteBuffers) {
int result = mConnection.controlTransfer(REQTYPE_HOST_TO_DEVICE, RESET_REQUEST,
RESET_PURGE_RX, mPortNumber+1, null, 0, USB_WRITE_TIMEOUT_MILLIS);
@@ -353,7 +353,6 @@ public class FtdiSerialDriver implements UsbSerialDriver {
throw new IOException("purge read buffer failed: result=" + result);
}
}
return true;
}
public void setLatencyTimer(int latencyTime) throws IOException {
@@ -464,7 +464,7 @@ public class ProlificSerialDriver implements UsbSerialDriver {
}
@Override
public boolean purgeHwBuffers(boolean purgeWriteBuffers, boolean purgeReadBuffers) throws IOException {
public void purgeHwBuffers(boolean purgeWriteBuffers, boolean purgeReadBuffers) throws IOException {
if (purgeWriteBuffers) {
vendorOut(FLUSH_RX_REQUEST, 0, null);
}
@@ -472,8 +472,6 @@ public class ProlificSerialDriver implements UsbSerialDriver {
if (purgeReadBuffers) {
vendorOut(FLUSH_TX_REQUEST, 0, null);
}
return true;
}
}
@@ -152,32 +152,36 @@ public interface UsbSerialPort extends Closeable {
/**
* Gets the CD (Carrier Detect) bit from the underlying UART.
*
* @return the current state, or {@code false} if not supported.
* @return the current state
* @throws IOException if an error occurred during reading
* @throws UnsupportedOperationException if not supported
*/
public boolean getCD() throws IOException;
/**
* Gets the CTS (Clear To Send) bit from the underlying UART.
*
* @return the current state, or {@code false} if not supported.
* @return the current state
* @throws IOException if an error occurred during reading
* @throws UnsupportedOperationException if not supported
*/
public boolean getCTS() throws IOException;
/**
* Gets the DSR (Data Set Ready) bit from the underlying UART.
*
* @return the current state, or {@code false} if not supported.
* @return the current state
* @throws IOException if an error occurred during reading
* @throws UnsupportedOperationException if not supported
*/
public boolean getDSR() throws IOException;
/**
* Gets the DTR (Data Terminal Ready) bit from the underlying UART.
*
* @return the current state, or {@code false} if not supported.
* @return the current state
* @throws IOException if an error occurred during reading
* @throws UnsupportedOperationException if not supported
*/
public boolean getDTR() throws IOException;
@@ -186,22 +190,25 @@ public interface UsbSerialPort extends Closeable {
*
* @param value the value to set
* @throws IOException if an error occurred during writing
* @throws UnsupportedOperationException if not supported
*/
public void setDTR(boolean value) throws IOException;
/**
* Gets the RI (Ring Indicator) bit from the underlying UART.
*
* @return the current state, or {@code false} if not supported.
* @return the current state
* @throws IOException if an error occurred during reading
* @throws UnsupportedOperationException if not supported
*/
public boolean getRI() throws IOException;
/**
* Gets the RTS (Request To Send) bit from the underlying UART.
*
* @return the current state, or {@code false} if not supported.
* @return the current state
* @throws IOException if an error occurred during reading
* @throws UnsupportedOperationException if not supported
*/
public boolean getRTS() throws IOException;
@@ -210,6 +217,7 @@ public interface UsbSerialPort extends Closeable {
*
* @param value the value to set
* @throws IOException if an error occurred during writing
* @throws UnsupportedOperationException if not supported
*/
public void setRTS(boolean value) throws IOException;
@@ -235,11 +243,10 @@ public interface UsbSerialPort extends Closeable {
*
* @param purgeWriteBuffers {@code true} to discard non-transmitted output data
* @param purgeReadBuffers {@code true} to discard non-read input data
* @return {@code true} if the operation was successful, or
* {@code false} if the operation is not supported by the driver or device
* @throws IOException if an error occurred during flush
* @throws UnsupportedOperationException if not supported
*/
public boolean purgeHwBuffers(boolean purgeWriteBuffers, boolean purgeReadBuffers) throws IOException;
public void purgeHwBuffers(boolean purgeWriteBuffers, boolean purgeReadBuffers) throws IOException;
/**
* Returns the current state of the connection.