Closed yong5354 closed 2 years ago
I think you are right. I was always confused about random wrong [255,...255] data.It seems like that the problem was solved by your method.
/// [_read] is a fundamental read function/
Future<Uint8List> _read(int bytesSize) async {
final lpBuffer = calloc<Uint16>(bytesSize);
Uint8List uint8list;
try {
readOnBeforeFunction();
ReadFile(handler!, lpBuffer, bytesSize, _bytesRead, _over);
} finally {
/// Uint16 need to be casted for real Uint8 data
var u8l = lpBuffer.cast<Uint8>().asTypedList(_bytesRead.value);
uint8list = Uint8List.fromList(u8l);
free(lpBuffer);
}
return uint8list;
}
The following are the two problems I met when using:
I'm not sure if this is the correct solution, please point it out if I'm wrong, thanks again for sharing