libserialport.dart
libserialport.dart copied to clipboard
SerialPortReader's stream listener gets cropped data
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?
@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 Try to adjust the
SerialPortReader
timeout to see if it works. The default is500 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
I have this same issue. Any solutions?
Is there a solution to this problem?
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.