flutter_packages icon indicating copy to clipboard operation
flutter_packages copied to clipboard

Advisory on Continuous Read Stream

Open mathaou opened this issue 1 year ago • 3 comments

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.

mathaou avatar Jul 12 '23 19:07 mathaou

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(() {});
});

ardera avatar Jul 16 '23 15:07 ardera

though this is probably a common enough use case that I could just add a SerialPortHandle.textStream shortcut for this

ardera avatar Jul 16 '23 15:07 ardera

Will try soon and verify functionality.

mathaou avatar Jul 18 '23 13:07 mathaou