flutter_packages
flutter_packages copied to clipboard
Advisory on Continuous Read Stream
Hello!
I'm trying to get some form of continuous read from a serial port going. Ideally I just listen to the stream that the SerialPortHandle
after open()
contains, but that doesn't seem to be working how I expect.
I'm able to read fine, I just want to have a psuedo serial console for the user. Not fully interactive, since the payloads that get written to port are predefined, but I do want to just keep reading and never stop - continually adding to TextField in read only mode.
Hey,
maybe something like this would work:
import 'dart:convert';
// ...
final textBuffer = StringBuffer();
final Stream<String> textStream = serialPortHandle.stream.transform(ascii.decoder);
textStream.listen((chunk) {
textBuffer.write(chunk);
setState(() {});
});
though this is probably a common enough use case that I could just add a SerialPortHandle.textStream
shortcut for this
Will try soon and verify functionality.