-
Notifications
You must be signed in to change notification settings - Fork 10
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
Stream Byte Array Fragmentation in Flutter Platform Channel #23
Comments
hi @saurabh-ifmt, can you share what device did you use for inbound & outbound data? |
Device used - Arduino |
no I mean what kind of arduino device did you use (be detailed)? and what android device did you use? |
temporary solution is that you can pool your data within specific time frame, so for like in a 50ms scope all data will be combined into one: 0ms: [170, 1] |
This behavior is normal and expected. On a bare serial port, there is no concept of "message boundaries". To handle this, you'll need to implement your own logic to reconstruct messages. The easiest is using a "Delimiter-Based Protocol" (\n aka newline in this case) final serialStream = _flutterSerialCommunicationPlugin
.getSerialMessageListener()
.receiveBroadcastStream();
await for (final message in serialStream
.toStringStream() // Convert to string
.transform(const LineSplitter())) { // Split on newlines
print(message); // Process each message as a complete unit
} On the Arduino, you can use println("Hello World") to append a newline character (\n) automatically to your messages. This will allow the Dart code to correctly separate them. |
I am experiencing an issue with byte array fragmentation when receiving data from the native side to the Flutter side via a platform channel. The data sent from the native side is received in chunks, breaking the expected byte array into fragments. Below is an example of the
Received From Native: [104]
Received From Native: [105, 32, 115, 97, 117, 114, 97, 98, 104, 13, 10]
The text was updated successfully, but these errors were encountered: