mirror of
https://github.com/mik3y/usb-serial-for-android.git
synced 2026-08-11 08:22:52 +00:00
retain input control line error until connection closed
This commit is contained in:
+11
-1
@@ -1970,10 +1970,20 @@ public class DeviceTest {
|
||||
} else {
|
||||
usb.serialPort.getRI();
|
||||
}
|
||||
fail("error expected");
|
||||
fail("connection closed expected");
|
||||
} catch (IOException ignored) {
|
||||
} catch (UnsupportedOperationException ignored) {
|
||||
}
|
||||
try {
|
||||
usb.serialPort.getRI();
|
||||
fail("connection closed expected");
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
// reset error
|
||||
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.serialPort.getRI();
|
||||
usb.serialPort.setRTS(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+6
-11
@@ -278,7 +278,7 @@ public class CdcAcmSerialDriver implements UsbSerialDriver {
|
||||
private void readControlLinesThreadFunction() {
|
||||
try {
|
||||
byte[] buffer = new byte[Math.max(SERIAL_STATE_PACKET_SIZE, mControlEndpoint.getMaxPacketSize())];
|
||||
while (!mStopReadControlLinesThread) {
|
||||
while (!mStopReadControlLinesThread && mConnection!=null) {
|
||||
long endTime = MonotonicClock.millis() + 500;
|
||||
int readBytesCount = mConnection.bulkTransfer(mControlEndpoint, buffer, buffer.length, 500);
|
||||
if (readBytesCount == -1) {
|
||||
@@ -296,14 +296,14 @@ public class CdcAcmSerialDriver implements UsbSerialDriver {
|
||||
Log.d(TAG, "control line state " + Arrays.toString(buffer));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (isOpen()) {
|
||||
mReadControlLinesException = e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int getSerialState() throws IOException {
|
||||
if ((mReadControlLinesThread == null) && (mReadControlLinesException == null)) {
|
||||
if(mConnection == null)
|
||||
throw new IOException("connection closed");
|
||||
if (mReadControlLinesThread == null) {
|
||||
synchronized (mReadControlLinesThreadLock) {
|
||||
if (mReadControlLinesThread == null) {
|
||||
mSerialState = 0;
|
||||
@@ -313,17 +313,12 @@ public class CdcAcmSerialDriver implements UsbSerialDriver {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Exception readControlLinesException = mReadControlLinesException;
|
||||
if (readControlLinesException != null) {
|
||||
mReadControlLinesException = null;
|
||||
throw new IOException(readControlLinesException);
|
||||
if (mReadControlLinesException != null) {
|
||||
throw new IOException(mReadControlLinesException);
|
||||
}
|
||||
|
||||
return mSerialState;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void closeInt() {
|
||||
try {
|
||||
|
||||
+2
-8
@@ -218,14 +218,13 @@ public class ProlificSerialDriver implements UsbSerialDriver {
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (isOpen())
|
||||
mReadStatusException = e;
|
||||
}
|
||||
//Log.d(TAG, "end control line status thread " + mStopReadStatusThread + " " + (mReadStatusException == null ? "-" : mReadStatusException.getMessage()));
|
||||
}
|
||||
|
||||
private int getStatus() throws IOException {
|
||||
if ((mReadStatusThread == null) && (mReadStatusException == null)) {
|
||||
if (mReadStatusThread == null) {
|
||||
synchronized (mReadStatusThreadLock) {
|
||||
if (mReadStatusThread == null) {
|
||||
mStatus = 0;
|
||||
@@ -249,14 +248,9 @@ public class ProlificSerialDriver implements UsbSerialDriver {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* throw and clear an exception which occurred in the status read thread */
|
||||
Exception readStatusException = mReadStatusException;
|
||||
if (mReadStatusException != null) {
|
||||
mReadStatusException = null;
|
||||
throw new IOException(readStatusException);
|
||||
throw new IOException(mReadStatusException);
|
||||
}
|
||||
|
||||
return mStatus;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user