mirror of
https://github.com/mik3y/usb-serial-for-android
synced 2025-06-07 16:06:10 +00:00
throw UnsupportedOperationException instead of returning false
This commit is contained in:
parent
954295456c
commit
a664082f23
@ -15,6 +15,10 @@ android {
|
|||||||
'rfc2217_server_nonstandard_baudrates': 'true', // true false false
|
'rfc2217_server_nonstandard_baudrates': 'true', // true false false
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
compileOptions {
|
||||||
|
sourceCompatibility JavaVersion.VERSION_1_8
|
||||||
|
targetCompatibility JavaVersion.VERSION_1_8
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
@ -32,6 +32,7 @@ import static org.junit.Assert.assertEquals;
|
|||||||
import static org.junit.Assert.assertNotEquals;
|
import static org.junit.Assert.assertNotEquals;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.Assert.assertThat;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
import static org.junit.Assume.assumeTrue;
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
public class CrossoverTest {
|
public class CrossoverTest {
|
||||||
@ -51,6 +52,9 @@ public class CrossoverTest {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
|
assumeTrue("ignore test for device specific coverage report",
|
||||||
|
InstrumentationRegistry.getArguments().getString("test_device_driver") == null);
|
||||||
|
|
||||||
context = InstrumentationRegistry.getContext();
|
context = InstrumentationRegistry.getContext();
|
||||||
usbManager = (UsbManager) context.getSystemService(Context.USB_SERVICE);
|
usbManager = (UsbManager) context.getSystemService(Context.USB_SERVICE);
|
||||||
List<UsbSerialDriver> availableDrivers = UsbSerialProber.getDefaultProber().findAllDrivers(usbManager);
|
List<UsbSerialDriver> availableDrivers = UsbSerialProber.getDefaultProber().findAllDrivers(usbManager);
|
||||||
|
@ -960,7 +960,13 @@ public class DeviceTest {
|
|||||||
|
|
||||||
usb.write(buf);
|
usb.write(buf);
|
||||||
Thread.sleep(50); // ~ 12 bytes
|
Thread.sleep(50); // ~ 12 bytes
|
||||||
boolean purged = usb.serialPort.purgeHwBuffers(true, false);
|
boolean purged;
|
||||||
|
try {
|
||||||
|
usb.serialPort.purgeHwBuffers(true, false);
|
||||||
|
purged = true;
|
||||||
|
} catch (UnsupportedOperationException ex) {
|
||||||
|
purged = false;
|
||||||
|
}
|
||||||
usb.write("bcd".getBytes());
|
usb.write("bcd".getBytes());
|
||||||
Thread.sleep(50);
|
Thread.sleep(50);
|
||||||
while(data.length()==0 || data.charAt(data.length()-1)!='d')
|
while(data.length()==0 || data.charAt(data.length()-1)!='d')
|
||||||
@ -984,7 +990,8 @@ public class DeviceTest {
|
|||||||
telnet.setParameters(19200, 8, 1, UsbSerialPort.PARITY_NONE);
|
telnet.setParameters(19200, 8, 1, UsbSerialPort.PARITY_NONE);
|
||||||
telnet.write("x".getBytes());
|
telnet.write("x".getBytes());
|
||||||
Thread.sleep(10); // ~ 20 bytes
|
Thread.sleep(10); // ~ 20 bytes
|
||||||
purged = usb.serialPort.purgeHwBuffers(false, true);
|
if(purged)
|
||||||
|
usb.serialPort.purgeHwBuffers(false, true);
|
||||||
Log.d(TAG, "purged = " + purged);
|
Log.d(TAG, "purged = " + purged);
|
||||||
telnet.write("y".getBytes());
|
telnet.write("y".getBytes());
|
||||||
Thread.sleep(10); // ~ 20 bytes
|
Thread.sleep(10); // ~ 20 bytes
|
||||||
@ -1299,6 +1306,9 @@ public class DeviceTest {
|
|||||||
inputLinesSupported = true;
|
inputLinesSupported = true;
|
||||||
inputLinesConnected = true;
|
inputLinesConnected = true;
|
||||||
}
|
}
|
||||||
|
Boolean inputLineFalse = inputLinesSupported ? Boolean.FALSE : null;
|
||||||
|
Boolean inputLineTrue = inputLinesConnected ? Boolean.TRUE : inputLineFalse;
|
||||||
|
|
||||||
EnumSet<UsbSerialPort.ControlLine> supportedControlLines = EnumSet.of(UsbSerialPort.ControlLine.RTS, UsbSerialPort.ControlLine.DTR);
|
EnumSet<UsbSerialPort.ControlLine> supportedControlLines = EnumSet.of(UsbSerialPort.ControlLine.RTS, UsbSerialPort.ControlLine.DTR);
|
||||||
if(inputLinesSupported) {
|
if(inputLinesSupported) {
|
||||||
supportedControlLines.add(UsbSerialPort.ControlLine.CTS);
|
supportedControlLines.add(UsbSerialPort.ControlLine.CTS);
|
||||||
@ -1331,12 +1341,12 @@ public class DeviceTest {
|
|||||||
? EnumSet.of(UsbSerialPort.ControlLine.RI)
|
? EnumSet.of(UsbSerialPort.ControlLine.RI)
|
||||||
: EnumSet.noneOf(UsbSerialPort.ControlLine.class),
|
: EnumSet.noneOf(UsbSerialPort.ControlLine.class),
|
||||||
usb.serialPort.getControlLines());
|
usb.serialPort.getControlLines());
|
||||||
assertFalse(usb.serialPort.getRTS());
|
assertThat(usb.getControlLine(usb.serialPort::getRTS), equalTo(Boolean.FALSE));
|
||||||
assertFalse(usb.serialPort.getCTS());
|
assertThat(usb.getControlLine(usb.serialPort::getCTS), equalTo(inputLineFalse));
|
||||||
assertFalse(usb.serialPort.getDTR());
|
assertThat(usb.getControlLine(usb.serialPort::getDTR), equalTo(Boolean.FALSE));
|
||||||
assertFalse(usb.serialPort.getDSR());
|
assertThat(usb.getControlLine(usb.serialPort::getDSR), equalTo(inputLineFalse));
|
||||||
assertFalse(usb.serialPort.getCD());
|
assertThat(usb.getControlLine(usb.serialPort::getCD), equalTo(inputLineFalse));
|
||||||
assertEquals(usb.serialPort.getRI(), inputLinesConnected);
|
assertThat(usb.getControlLine(usb.serialPort::getRI), equalTo(inputLineTrue));
|
||||||
telnet.write(data);
|
telnet.write(data);
|
||||||
if(usb.serialDriver instanceof CdcAcmSerialDriver)
|
if(usb.serialDriver instanceof CdcAcmSerialDriver)
|
||||||
// arduino: control line feedback as serial_state notification is not implemented.
|
// arduino: control line feedback as serial_state notification is not implemented.
|
||||||
@ -1354,12 +1364,12 @@ public class DeviceTest {
|
|||||||
? EnumSet.of(UsbSerialPort.ControlLine.RTS, UsbSerialPort.ControlLine.CTS)
|
? EnumSet.of(UsbSerialPort.ControlLine.RTS, UsbSerialPort.ControlLine.CTS)
|
||||||
: EnumSet.of(UsbSerialPort.ControlLine.RTS),
|
: EnumSet.of(UsbSerialPort.ControlLine.RTS),
|
||||||
usb.serialPort.getControlLines());
|
usb.serialPort.getControlLines());
|
||||||
assertTrue(usb.serialPort.getRTS());
|
assertThat(usb.getControlLine(usb.serialPort::getRTS), equalTo(Boolean.TRUE));
|
||||||
assertEquals(usb.serialPort.getCTS(), inputLinesConnected);
|
assertThat(usb.getControlLine(usb.serialPort::getCTS), equalTo(inputLineTrue));
|
||||||
assertFalse(usb.serialPort.getDTR());
|
assertThat(usb.getControlLine(usb.serialPort::getDTR), equalTo(Boolean.FALSE));
|
||||||
assertFalse(usb.serialPort.getDSR());
|
assertThat(usb.getControlLine(usb.serialPort::getDSR), equalTo(inputLineFalse));
|
||||||
assertFalse(usb.serialPort.getCD());
|
assertThat(usb.getControlLine(usb.serialPort::getCD), equalTo(inputLineFalse));
|
||||||
assertFalse(usb.serialPort.getRI());
|
assertThat(usb.getControlLine(usb.serialPort::getRI), equalTo(inputLineFalse));
|
||||||
telnet.write(data);
|
telnet.write(data);
|
||||||
assertThat(Arrays.toString(data), usb.read(4), equalTo(data));
|
assertThat(Arrays.toString(data), usb.read(4), equalTo(data));
|
||||||
usb.write(data);
|
usb.write(data);
|
||||||
@ -1372,12 +1382,12 @@ public class DeviceTest {
|
|||||||
? EnumSet.of(UsbSerialPort.ControlLine.RTS, UsbSerialPort.ControlLine.DTR, UsbSerialPort.ControlLine.CD)
|
? EnumSet.of(UsbSerialPort.ControlLine.RTS, UsbSerialPort.ControlLine.DTR, UsbSerialPort.ControlLine.CD)
|
||||||
: EnumSet.of(UsbSerialPort.ControlLine.RTS, UsbSerialPort.ControlLine.DTR),
|
: EnumSet.of(UsbSerialPort.ControlLine.RTS, UsbSerialPort.ControlLine.DTR),
|
||||||
usb.serialPort.getControlLines());
|
usb.serialPort.getControlLines());
|
||||||
assertTrue(usb.serialPort.getRTS());
|
assertThat(usb.getControlLine(usb.serialPort::getRTS), equalTo(Boolean.TRUE));
|
||||||
assertFalse(usb.serialPort.getCTS());
|
assertThat(usb.getControlLine(usb.serialPort::getCTS), equalTo(inputLineFalse));
|
||||||
assertTrue(usb.serialPort.getDTR());
|
assertThat(usb.getControlLine(usb.serialPort::getDTR), equalTo(Boolean.TRUE));
|
||||||
assertFalse(usb.serialPort.getDSR());
|
assertThat(usb.getControlLine(usb.serialPort::getDSR), equalTo(inputLineFalse));
|
||||||
assertEquals(usb.serialPort.getCD(), inputLinesConnected);
|
assertThat(usb.getControlLine(usb.serialPort::getCD), equalTo(inputLineTrue));
|
||||||
assertFalse(usb.serialPort.getRI());
|
assertThat(usb.getControlLine(usb.serialPort::getRI), equalTo(inputLineFalse));
|
||||||
telnet.write(data);
|
telnet.write(data);
|
||||||
assertThat(Arrays.toString(data), usb.read(4), equalTo(data));
|
assertThat(Arrays.toString(data), usb.read(4), equalTo(data));
|
||||||
usb.write(data);
|
usb.write(data);
|
||||||
@ -1390,12 +1400,12 @@ public class DeviceTest {
|
|||||||
? EnumSet.of(UsbSerialPort.ControlLine.DTR, UsbSerialPort.ControlLine.DSR)
|
? EnumSet.of(UsbSerialPort.ControlLine.DTR, UsbSerialPort.ControlLine.DSR)
|
||||||
: EnumSet.of(UsbSerialPort.ControlLine.DTR),
|
: EnumSet.of(UsbSerialPort.ControlLine.DTR),
|
||||||
usb.serialPort.getControlLines());
|
usb.serialPort.getControlLines());
|
||||||
assertFalse(usb.serialPort.getRTS());
|
assertThat(usb.getControlLine(usb.serialPort::getRTS), equalTo(Boolean.FALSE));
|
||||||
assertFalse(usb.serialPort.getCTS());
|
assertThat(usb.getControlLine(usb.serialPort::getCTS), equalTo(inputLineFalse));
|
||||||
assertTrue(usb.serialPort.getDTR());
|
assertThat(usb.getControlLine(usb.serialPort::getDTR), equalTo(Boolean.TRUE));
|
||||||
assertEquals(usb.serialPort.getDSR(), inputLinesConnected);
|
assertThat(usb.getControlLine(usb.serialPort::getDSR), equalTo(inputLineTrue));
|
||||||
assertFalse(usb.serialPort.getCD());
|
assertThat(usb.getControlLine(usb.serialPort::getCD), equalTo(inputLineFalse));
|
||||||
assertFalse(usb.serialPort.getRI());
|
assertThat(usb.getControlLine(usb.serialPort::getRI), equalTo(inputLineFalse));
|
||||||
telnet.write(data);
|
telnet.write(data);
|
||||||
assertThat(Arrays.toString(data), usb.read(4), equalTo(data));
|
assertThat(Arrays.toString(data), usb.read(4), equalTo(data));
|
||||||
usb.write(data);
|
usb.write(data);
|
||||||
@ -1412,12 +1422,12 @@ public class DeviceTest {
|
|||||||
if(outputRetained) retainedControlLines.add(UsbSerialPort.ControlLine.DTR);
|
if(outputRetained) retainedControlLines.add(UsbSerialPort.ControlLine.DTR);
|
||||||
if(inputRetained) retainedControlLines.add(UsbSerialPort.ControlLine.DSR);
|
if(inputRetained) retainedControlLines.add(UsbSerialPort.ControlLine.DSR);
|
||||||
assertEquals(retainedControlLines, usb.serialPort.getControlLines());
|
assertEquals(retainedControlLines, usb.serialPort.getControlLines());
|
||||||
assertFalse(usb.serialPort.getRTS());
|
assertThat(usb.getControlLine(usb.serialPort::getRTS), equalTo(Boolean.FALSE));
|
||||||
assertFalse(usb.serialPort.getCTS());
|
assertThat(usb.getControlLine(usb.serialPort::getCTS), equalTo(inputLineFalse));
|
||||||
assertEquals(usb.serialPort.getDTR(), outputRetained);
|
assertThat(usb.getControlLine(usb.serialPort::getDTR), equalTo(outputRetained));
|
||||||
assertEquals(usb.serialPort.getDSR(), inputRetained);
|
assertThat(usb.getControlLine(usb.serialPort::getDSR), equalTo(inputRetained ? inputLineTrue : inputLineFalse));
|
||||||
assertFalse(usb.serialPort.getCD());
|
assertThat(usb.getControlLine(usb.serialPort::getCD), equalTo(inputLineFalse));
|
||||||
assertFalse(usb.serialPort.getRI());
|
assertThat(usb.getControlLine(usb.serialPort::getRI), equalTo(inputLineFalse));
|
||||||
|
|
||||||
usb.close(EnumSet.of(UsbWrapper.OpenCloseFlags.NO_CONTROL_LINE_INIT));
|
usb.close(EnumSet.of(UsbWrapper.OpenCloseFlags.NO_CONTROL_LINE_INIT));
|
||||||
usb.open(EnumSet.of(UsbWrapper.OpenCloseFlags.NO_CONTROL_LINE_INIT, UsbWrapper.OpenCloseFlags.NO_IOMANAGER_THREAD));
|
usb.open(EnumSet.of(UsbWrapper.OpenCloseFlags.NO_CONTROL_LINE_INIT, UsbWrapper.OpenCloseFlags.NO_IOMANAGER_THREAD));
|
||||||
@ -1436,28 +1446,35 @@ public class DeviceTest {
|
|||||||
// get... error
|
// get... error
|
||||||
try {
|
try {
|
||||||
usb.serialPort.getRI();
|
usb.serialPort.getRI();
|
||||||
if (!inputLinesSupported)
|
if (usb.serialDriver instanceof ProlificSerialDriver)
|
||||||
;
|
|
||||||
else if (usb.serialDriver instanceof ProlificSerialDriver)
|
|
||||||
; // todo: currently not possible to detect, as bulkTransfer in background thread does not distinguish timeout and error
|
; // todo: currently not possible to detect, as bulkTransfer in background thread does not distinguish timeout and error
|
||||||
else
|
else
|
||||||
fail("error expected");
|
fail("error expected");
|
||||||
} catch (IOException ignored) {
|
} catch (IOException ignored) {
|
||||||
|
} catch (UnsupportedOperationException ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void deviceConnection() throws Exception {
|
public void deviceConnection() throws Exception {
|
||||||
byte buf[] = new byte[256];
|
byte[] buf = new byte[256];
|
||||||
usb.open(EnumSet.of(UsbWrapper.OpenCloseFlags.NO_IOMANAGER_THREAD));
|
usb.open(EnumSet.of(UsbWrapper.OpenCloseFlags.NO_IOMANAGER_THREAD));
|
||||||
usb.setParameters(115200, 8, 1, UsbSerialPort.PARITY_NONE);
|
usb.setParameters(115200, 8, 1, UsbSerialPort.PARITY_NONE);
|
||||||
|
|
||||||
usb.write("x".getBytes());
|
usb.write("x".getBytes());
|
||||||
usb.serialPort.read(buf, 1000);
|
usb.serialPort.read(buf, 1000);
|
||||||
usb.serialPort.setRTS(true);
|
usb.serialPort.setRTS(true);
|
||||||
usb.serialPort.getRI();
|
try {
|
||||||
boolean purged = usb.serialPort.purgeHwBuffers(true, true);
|
usb.serialPort.getRI();
|
||||||
|
} catch (UnsupportedOperationException ignored) {
|
||||||
|
}
|
||||||
|
boolean purged;
|
||||||
|
try {
|
||||||
|
usb.serialPort.purgeHwBuffers(true, true);
|
||||||
|
purged = true;
|
||||||
|
} catch (UnsupportedOperationException ex) {
|
||||||
|
purged = false;
|
||||||
|
}
|
||||||
usb.deviceConnection.close();
|
usb.deviceConnection.close();
|
||||||
try {
|
try {
|
||||||
usb.setParameters(115200, 8, 1, UsbSerialPort.PARITY_NONE);
|
usb.setParameters(115200, 8, 1, UsbSerialPort.PARITY_NONE);
|
||||||
@ -1481,13 +1498,12 @@ public class DeviceTest {
|
|||||||
fail("setRts error expected");
|
fail("setRts error expected");
|
||||||
} catch (IOException ignored) {
|
} catch (IOException ignored) {
|
||||||
}
|
}
|
||||||
if(usb.serialPort.getSupportedControlLines().contains(UsbSerialPort.ControlLine.RI) ) {
|
try {
|
||||||
try {
|
usb.serialPort.getRI();
|
||||||
usb.serialPort.getRI();
|
if(!(usb.serialDriver instanceof ProlificSerialDriver))
|
||||||
if(!(usb.serialDriver instanceof ProlificSerialDriver))
|
fail("getRI error expected");
|
||||||
fail("getRI error expected");
|
} catch (IOException ignored) {
|
||||||
} catch (IOException ignored) {
|
} catch (UnsupportedOperationException ignored) {
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if(purged) {
|
if(purged) {
|
||||||
try {
|
try {
|
||||||
|
@ -20,6 +20,7 @@ import java.nio.ByteBuffer;
|
|||||||
import java.util.Deque;
|
import java.util.Deque;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
@ -223,6 +224,15 @@ public class UsbWrapper implements SerialInputOutputManager.Listener {
|
|||||||
Thread.sleep(1);
|
Thread.sleep(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* return TRUE/FALSE/null instead of true/false/<throw UnsupportedOperationException> */
|
||||||
|
public Boolean getControlLine(Callable<?> callable) throws Exception {
|
||||||
|
try {
|
||||||
|
return (Boolean)callable.call();
|
||||||
|
} catch (UnsupportedOperationException t) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNewData(byte[] data) {
|
public void onNewData(byte[] data) {
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
|
@ -239,21 +239,6 @@ public class CdcAcmSerialDriver implements UsbSerialDriver {
|
|||||||
sendAcmControlMessage(SET_LINE_CODING, 0, msg);
|
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
|
@Override
|
||||||
public boolean getDTR() throws IOException {
|
public boolean getDTR() throws IOException {
|
||||||
return mDtr;
|
return mDtr;
|
||||||
@ -265,11 +250,6 @@ public class CdcAcmSerialDriver implements UsbSerialDriver {
|
|||||||
setDtrRts();
|
setDtrRts();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean getRI() throws IOException {
|
|
||||||
return false; // TODO
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean getRTS() throws IOException {
|
public boolean getRTS() throws IOException {
|
||||||
return mRts;
|
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;
|
public abstract void setParameters(int baudRate, int dataBits, int stopBits, int parity) throws IOException;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract boolean getCD() throws IOException;
|
public boolean getCD() throws IOException { throw new UnsupportedOperationException(); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract boolean getCTS() throws IOException;
|
public boolean getCTS() throws IOException { throw new UnsupportedOperationException(); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract boolean getDSR() throws IOException;
|
public boolean getDSR() throws IOException { throw new UnsupportedOperationException(); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract boolean getDTR() throws IOException;
|
public boolean getDTR() throws IOException { throw new UnsupportedOperationException(); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract void setDTR(boolean value) throws IOException;
|
public void setDTR(boolean value) throws IOException { throw new UnsupportedOperationException(); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract boolean getRI() throws IOException;
|
public boolean getRI() throws IOException { throw new UnsupportedOperationException(); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract boolean getRTS() throws IOException;
|
public boolean getRTS() throws IOException { throw new UnsupportedOperationException(); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract void setRTS(boolean value) throws IOException;
|
public void setRTS(boolean value) throws IOException { throw new UnsupportedOperationException(); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract EnumSet<ControlLine> getControlLines() throws IOException;
|
public abstract EnumSet<ControlLine> getControlLines() throws IOException;
|
||||||
@ -242,8 +242,8 @@ public abstract class CommonUsbSerialPort implements UsbSerialPort {
|
|||||||
public abstract EnumSet<ControlLine> getSupportedControlLines() throws IOException;
|
public abstract EnumSet<ControlLine> getSupportedControlLines() throws IOException;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean purgeHwBuffers(boolean purgeWriteBuffers, boolean purgeReadBuffers) throws IOException {
|
public void purgeHwBuffers(boolean purgeWriteBuffers, boolean purgeReadBuffers) throws IOException {
|
||||||
return false;
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -305,15 +305,13 @@ public class Cp21xxSerialDriver implements UsbSerialDriver {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
// note: only working on some devices, on other devices ignored w/o error
|
// 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)
|
int value = (purgeReadBuffers ? FLUSH_READ_CODE : 0)
|
||||||
| (purgeWriteBuffers ? FLUSH_WRITE_CODE : 0);
|
| (purgeWriteBuffers ? FLUSH_WRITE_CODE : 0);
|
||||||
|
|
||||||
if (value != 0) {
|
if (value != 0) {
|
||||||
setConfigSingle(SILABSER_FLUSH_REQUEST_CODE, value);
|
setConfigSingle(SILABSER_FLUSH_REQUEST_CODE, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -337,7 +337,7 @@ public class FtdiSerialDriver implements UsbSerialDriver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean purgeHwBuffers(boolean purgeWriteBuffers, boolean purgeReadBuffers) throws IOException {
|
public void purgeHwBuffers(boolean purgeWriteBuffers, boolean purgeReadBuffers) throws IOException {
|
||||||
if (purgeWriteBuffers) {
|
if (purgeWriteBuffers) {
|
||||||
int result = mConnection.controlTransfer(REQTYPE_HOST_TO_DEVICE, RESET_REQUEST,
|
int result = mConnection.controlTransfer(REQTYPE_HOST_TO_DEVICE, RESET_REQUEST,
|
||||||
RESET_PURGE_RX, mPortNumber+1, null, 0, USB_WRITE_TIMEOUT_MILLIS);
|
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);
|
throw new IOException("purge read buffer failed: result=" + result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLatencyTimer(int latencyTime) throws IOException {
|
public void setLatencyTimer(int latencyTime) throws IOException {
|
||||||
|
@ -464,7 +464,7 @@ public class ProlificSerialDriver implements UsbSerialDriver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean purgeHwBuffers(boolean purgeWriteBuffers, boolean purgeReadBuffers) throws IOException {
|
public void purgeHwBuffers(boolean purgeWriteBuffers, boolean purgeReadBuffers) throws IOException {
|
||||||
if (purgeWriteBuffers) {
|
if (purgeWriteBuffers) {
|
||||||
vendorOut(FLUSH_RX_REQUEST, 0, null);
|
vendorOut(FLUSH_RX_REQUEST, 0, null);
|
||||||
}
|
}
|
||||||
@ -472,8 +472,6 @@ public class ProlificSerialDriver implements UsbSerialDriver {
|
|||||||
if (purgeReadBuffers) {
|
if (purgeReadBuffers) {
|
||||||
vendorOut(FLUSH_TX_REQUEST, 0, null);
|
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.
|
* 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 IOException if an error occurred during reading
|
||||||
|
* @throws UnsupportedOperationException if not supported
|
||||||
*/
|
*/
|
||||||
public boolean getCD() throws IOException;
|
public boolean getCD() throws IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the CTS (Clear To Send) bit from the underlying UART.
|
* 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 IOException if an error occurred during reading
|
||||||
|
* @throws UnsupportedOperationException if not supported
|
||||||
*/
|
*/
|
||||||
public boolean getCTS() throws IOException;
|
public boolean getCTS() throws IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the DSR (Data Set Ready) bit from the underlying UART.
|
* 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 IOException if an error occurred during reading
|
||||||
|
* @throws UnsupportedOperationException if not supported
|
||||||
*/
|
*/
|
||||||
public boolean getDSR() throws IOException;
|
public boolean getDSR() throws IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the DTR (Data Terminal Ready) bit from the underlying UART.
|
* 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 IOException if an error occurred during reading
|
||||||
|
* @throws UnsupportedOperationException if not supported
|
||||||
*/
|
*/
|
||||||
public boolean getDTR() throws IOException;
|
public boolean getDTR() throws IOException;
|
||||||
|
|
||||||
@ -186,22 +190,25 @@ public interface UsbSerialPort extends Closeable {
|
|||||||
*
|
*
|
||||||
* @param value the value to set
|
* @param value the value to set
|
||||||
* @throws IOException if an error occurred during writing
|
* @throws IOException if an error occurred during writing
|
||||||
|
* @throws UnsupportedOperationException if not supported
|
||||||
*/
|
*/
|
||||||
public void setDTR(boolean value) throws IOException;
|
public void setDTR(boolean value) throws IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the RI (Ring Indicator) bit from the underlying UART.
|
* 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 IOException if an error occurred during reading
|
||||||
|
* @throws UnsupportedOperationException if not supported
|
||||||
*/
|
*/
|
||||||
public boolean getRI() throws IOException;
|
public boolean getRI() throws IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the RTS (Request To Send) bit from the underlying UART.
|
* 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 IOException if an error occurred during reading
|
||||||
|
* @throws UnsupportedOperationException if not supported
|
||||||
*/
|
*/
|
||||||
public boolean getRTS() throws IOException;
|
public boolean getRTS() throws IOException;
|
||||||
|
|
||||||
@ -210,6 +217,7 @@ public interface UsbSerialPort extends Closeable {
|
|||||||
*
|
*
|
||||||
* @param value the value to set
|
* @param value the value to set
|
||||||
* @throws IOException if an error occurred during writing
|
* @throws IOException if an error occurred during writing
|
||||||
|
* @throws UnsupportedOperationException if not supported
|
||||||
*/
|
*/
|
||||||
public void setRTS(boolean value) throws IOException;
|
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 purgeWriteBuffers {@code true} to discard non-transmitted output data
|
||||||
* @param purgeReadBuffers {@code true} to discard non-read input 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 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.
|
* Returns the current state of the connection.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user