SerialOTG Extension Receive Length

In this AI extension, when the serial connection is read and there is data, regardless of the length of the actual string received, the length of receiving field returns 256. If there is no data the length returned is 0.

  • Is 256 the size of the serial buffer ?
  • Is there a way to determine the actual length of data received ?
  • I tried scanning for \0 as a terminating char and did not get a hit.

In this extension when you use the PrintSerial block, \n (10) is sent as the end of the message.

You just need to read the data quickly because the data is corrupted after a buffer overflow.

In my test case, there is no time issue, as I am sending a SINGLE short message of few characters and I am correctly receiving it at the other end.

I was questioning the buffer size results with and without a received message, and trying to find out if there is way to get to the size of the actual received data, rather than the entire buffer size.

I have just updated SerialOTG with a new function Serial.ReadLn() to receive a message terminated with a new_line char. The function returns an empty string, until a complete message is received. This together with SerialPrint() makes ascii message communication simpler to implement.
This version also includes a function to get the number of bytes in the library read buffer at the time you call the function, BytesToRead().
The library buffer size is 1024b.
The setting of buffersize is redundent and will be removed in next release.
The extension with some examples can be found at: