Arduino Serial Connection

Thanks @alexmonro. I might have written it a bit differently myself here and there.

The purpose of the two lines

if (ndx >= numChars) {                               // if the output array is full
         ndx = numChars - 1;                               // fudge it
}

is not a fudge. They are there simply to prevent writing past the end of the array. If the array size is correctly chosen those lines should never come into play.

@yowusgudfam, a high-level description of the code is something like this

  • check what has been received
  • if we don't see a start-marker just throw stuff away
  • when we see a start-marked start saving the data (recvInProgress will be true)
  • keep saving data until we see the end-marker
  • when we see the end-marker set the variable newData = true so that the main program knows that the message is complete.

...R