disconnect method
Close the active connection and release all resources.
Prefer calling dispose when the service will not be used again.
Implementation
Future<void> disconnect() async {
if (Platform.isAndroid) {
await _usbPort?.close();
_usbPort = null;
} else if (Platform.isWindows) {
// Cancel the persistent reader subscription first so the isolate stops
// forwarding bytes before we close the port underneath it.
await _winReaderSub?.cancel();
_winReaderSub = null;
_winReader = null;
_winPort?.close();
_winPort?.dispose();
_winPort = null;
}
}