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 {
|
} else {
|
||||||
usb.serialPort.getRI();
|
usb.serialPort.getRI();
|
||||||
}
|
}
|
||||||
fail("error expected");
|
fail("connection closed expected");
|
||||||
} catch (IOException ignored) {
|
} catch (IOException ignored) {
|
||||||
} catch (UnsupportedOperationException 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
|
@Test
|
||||||
|
|||||||
+7
-12
@@ -278,7 +278,7 @@ public class CdcAcmSerialDriver implements UsbSerialDriver {
|
|||||||
private void readControlLinesThreadFunction() {
|
private void readControlLinesThreadFunction() {
|
||||||
try {
|
try {
|
||||||
byte[] buffer = new byte[Math.max(SERIAL_STATE_PACKET_SIZE, mControlEndpoint.getMaxPacketSize())];
|
byte[] buffer = new byte[Math.max(SERIAL_STATE_PACKET_SIZE, mControlEndpoint.getMaxPacketSize())];
|
||||||
while (!mStopReadControlLinesThread) {
|
while (!mStopReadControlLinesThread && mConnection!=null) {
|
||||||
long endTime = MonotonicClock.millis() + 500;
|
long endTime = MonotonicClock.millis() + 500;
|
||||||
int readBytesCount = mConnection.bulkTransfer(mControlEndpoint, buffer, buffer.length, 500);
|
int readBytesCount = mConnection.bulkTransfer(mControlEndpoint, buffer, buffer.length, 500);
|
||||||
if (readBytesCount == -1) {
|
if (readBytesCount == -1) {
|
||||||
@@ -296,14 +296,14 @@ public class CdcAcmSerialDriver implements UsbSerialDriver {
|
|||||||
Log.d(TAG, "control line state " + Arrays.toString(buffer));
|
Log.d(TAG, "control line state " + Arrays.toString(buffer));
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
if (isOpen()) {
|
mReadControlLinesException = e;
|
||||||
mReadControlLinesException = e;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getSerialState() throws IOException {
|
private int getSerialState() throws IOException {
|
||||||
if ((mReadControlLinesThread == null) && (mReadControlLinesException == null)) {
|
if(mConnection == null)
|
||||||
|
throw new IOException("connection closed");
|
||||||
|
if (mReadControlLinesThread == null) {
|
||||||
synchronized (mReadControlLinesThreadLock) {
|
synchronized (mReadControlLinesThreadLock) {
|
||||||
if (mReadControlLinesThread == null) {
|
if (mReadControlLinesThread == null) {
|
||||||
mSerialState = 0;
|
mSerialState = 0;
|
||||||
@@ -313,17 +313,12 @@ public class CdcAcmSerialDriver implements UsbSerialDriver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (mReadControlLinesException != null) {
|
||||||
Exception readControlLinesException = mReadControlLinesException;
|
throw new IOException(mReadControlLinesException);
|
||||||
if (readControlLinesException != null) {
|
|
||||||
mReadControlLinesException = null;
|
|
||||||
throw new IOException(readControlLinesException);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return mSerialState;
|
return mSerialState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void closeInt() {
|
protected void closeInt() {
|
||||||
try {
|
try {
|
||||||
|
|||||||
+3
-9
@@ -218,14 +218,13 @@ public class ProlificSerialDriver implements UsbSerialDriver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
if (isOpen())
|
mReadStatusException = e;
|
||||||
mReadStatusException = e;
|
|
||||||
}
|
}
|
||||||
//Log.d(TAG, "end control line status thread " + mStopReadStatusThread + " " + (mReadStatusException == null ? "-" : mReadStatusException.getMessage()));
|
//Log.d(TAG, "end control line status thread " + mStopReadStatusThread + " " + (mReadStatusException == null ? "-" : mReadStatusException.getMessage()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getStatus() throws IOException {
|
private int getStatus() throws IOException {
|
||||||
if ((mReadStatusThread == null) && (mReadStatusException == null)) {
|
if (mReadStatusThread == null) {
|
||||||
synchronized (mReadStatusThreadLock) {
|
synchronized (mReadStatusThreadLock) {
|
||||||
if (mReadStatusThread == null) {
|
if (mReadStatusThread == null) {
|
||||||
mStatus = 0;
|
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) {
|
if (mReadStatusException != null) {
|
||||||
mReadStatusException = null;
|
throw new IOException(mReadStatusException);
|
||||||
throw new IOException(readStatusException);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return mStatus;
|
return mStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user