libserialport.dart
libserialport.dart copied to clipboard
read throws exception when sp_nonblocking_read returns negative number in case of error
This piece of code in util.dart
does not handle error code in case sp_nonblocking_read fails
static Uint8List read(int bytes, UtilFunc<ffi.Uint8> readFunc) {
return ffi.using((arena) {
final ptr = arena<ffi.Uint8>(bytes);
final len = call(() => readFunc(ptr));
return Uint8List.fromList(ptr.asTypedList(len));
});
}
This will fix the error:
return Uint8List.fromList(ptr.asTypedList(len < 0 ? 0 : len));