Open camillobucciarelli opened 4 months ago
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?
When I try to close connection with
port.close();
I get the following error in console:there is something that I'm doing wrong?
Thank you