Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Advisory on Continuous Read Stream #22

Open
mathaou opened this issue Jul 12, 2023 · 3 comments
Open

Advisory on Continuous Read Stream #22

mathaou opened this issue Jul 12, 2023 · 3 comments

Comments

@mathaou
Copy link

mathaou commented Jul 12, 2023

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.

@ardera
Copy link
Owner

ardera commented Jul 16, 2023

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
Copy link
Owner

ardera commented Jul 16, 2023

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

@mathaou
Copy link
Author

mathaou commented Jul 18, 2023

Will try soon and verify functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants