usbserial
usbserial copied to clipboard
java.lang.InterruptedException on close invocation
When I try to close connection with port.close();
I get the following error in console:
D/UsbDeviceConnectionJNI(28094): close
W/System.err(28094): java.lang.InterruptedException
W/System.err(28094): at java.lang.Object.wait(Native Method)
W/System.err(28094): at java.lang.Object.wait(Object.java:386)
W/System.err(28094): at java.lang.Object.wait(Object.java:524)
W/System.err(28094): at com.felhr.usbserial.SerialBuffer$SynchronizedBuffer.get(SerialBuffer.java:117)
W/System.err(28094): at com.felhr.usbserial.SerialBuffer.getWriteBuffer(SerialBuffer.java:72)
W/System.err(28094): at com.felhr.usbserial.UsbSerialDevice$WriteThread.doRun(UsbSerialDevice.java:402)
W/System.err(28094): at com.felhr.usbserial.AbstractWorkerThread.run(AbstractWorkerThread.java:21)
there is something that I'm doing wrong?
Thank you
Hi, can you provde a small code example, how you use the lib? Some information about the used hardware is helpful, too. Thanks
i have same problem android-arm • Android 9 (API 28) CH34xSerialDevice Flutter 3.16.9 Dart version 3.2.6
my code is like this
final port = usbDevice.create();
if (await port.open()) {
debugPrint("connection success");
port.setPortParameters(
9600, UsbPort.DATABITS_8, UsbPort.STOPBITS_1, UsbPort.PARITY_NONE);
debugPrint("port parameter: ${port.toString()}");
final anser = <int>[];
Timer? timeoutTimer;
bool success = false;
final completer = Completer<void>();
late final StreamSubscription<Uint8List> sub;
sub = port.inputStream!.listen((event) {
anser.addAll(event);
debugPrint("event: $event, anser: $anser");
if (response.isEmpty ||
(response.isNotEmpty && anser.containsAll(response))) {
debugPrint("success");
sub.cancel();
success = true;
if (timeoutTimer != null) timeoutTimer.cancel();
completer.complete();
}
});
await port.write(dataSend);
timeoutTimer = Timer(Duration(milliseconds: timeOut), () {
if (!success) {
debugPrint('Timeout: Did not find the required data within 3 seconds');
sub.cancel(); //cancel Stream
completer.complete(); // finish Completer
}
});
await completer.future;
// all task finished.
port.close(); // exception is here
}
Does your android device work with the CH34xSerialDevice when using the example app? What does the error look like?