jpnurmi / libserialport.dart

Serial Port for Dart
https://pub.dev/packages/libserialport
GNU Lesser General Public License v3.0
85 stars 34 forks source link

SerialPortReader's stream listener gets cropped data #40

Open tdrkDev opened 3 years ago

tdrkDev commented 3 years ago

I need to get this data from serial: {"test":"very_big_text_very_big_text_very_big_text_very_big_text_very_big_text"}

But SerialPortReader's stream listener event variable contains only this: {"test":"very_big_text_very_big_text_very_big_text_very_big_text_ver

If I am reading value with cat /dev/ttyUSB0, everything is fine.

If needed, serial port baud is 57600 and I set it in my code with workaround from one of issues. Platform: Linux, Fedora 34, kernel 5.13.9-200.fc34.x86_64

Also, cropped part and its length are always different.

Part of my code:

final serial = SerialPort("/dev/ttyUSB0");

Uint8List rawRequest = Uint8List.fromList(
  utf8.encode(
    jsonEncode(data),
  ),
);
serial.write(rawRequest);
serial.flush();

final reader = SerialPortReader(serial);

reader.stream.listen((event) {
  Uint8List raw = event;
  String utf = utf8.decode(raw);

  print("$utf");
  print("$raw");
}

So, how can I fix that?

k10dev commented 2 years ago

@tdrkDev Try to adjust the SerialPortReader timeout to see if it works. The default is 500 ms if not set.

final timeout = const Duration(seconds: 1).inMilliseconds
final reader = SerialPortReader(serial, timeout: timeout);
tdrkDev commented 2 years ago

@tdrkDev Try to adjust the SerialPortReader timeout to see if it works. The default is 500 ms if not set.

final timeout = const Duration(seconds: 1).inMilliseconds
final reader = SerialPortReader(serial, timeout: timeout);

tried that before writing the issue, not helped

elgansayer commented 2 years ago

I have this same issue. Any solutions?

pgfeng commented 1 year ago

Is there a solution to this problem?

nilotpalkapri commented 1 year ago

So, I found a workaround by adding a delimitator at the end of the data sending from arduino or other device, and in the application concatenating data till the delimitator received & splitting using the same.