pezi / dart_periphery

dart_periphery is a Dart port of the native c-periphery library
BSD 3-Clause "New" or "Revised" License
36 stars 9 forks source link

Can't read more than one byte at time from Serial #3

Closed mortenboye closed 3 years ago

mortenboye commented 3 years ago

Hi, I'm trying to use this library for various I/O in my project, but im struggling to read serial data of arbitrary length.

If I run this code in a periodic timer:

SerialReadEvent sre = serial.read(100, 0);
if (sre.count > 0) {
  print("serial has data ${sre.count}");
}

I can never read more than one byte at a time, despite sending multiple. Also the byte value doesn't match any of the sent values. My system is based on a RPI CM4 running flutter-pi and I have dtoverlay=midi-uart0 enabled in the config (mapping 38400bps to 31200 for MIDI).

Any clues as to what is causing this or a good working example?

pezi commented 3 years ago

1.) What happends, if you increase the timeout parameter? https://pub.dev/documentation/dart_periphery/latest/dart_periphery/Serial/read.html The original c-periphery documentation says: timeout can be positive for a blocking read with atimeout in milliseconds, zero for a non-blocking read, or negative for a blocking read that will block until length number of bytes are read

2.) I ported the test unit from the original c-periphery project. https://github.com/pezi/dart_periphery/blob/main/test/serial_test.dart I tested this code with the standad UART of the PI and a loop back connection. Perhaps this code is useful for your problem.

mortenboye commented 3 years ago

Thank you for your suggestions. I found an issue on my hardware so I believe Im back on track. Closing