Serial.read: interrupted string

Your suggestion solved the problem

No, it masked the problem. The problem still exists.

Which version of the IDE are you using? If you are using 1.0 or later, the flush() function blocks until the outgoing buffer is empty. I fail to see how that is a useful thing to do.

If you are using 0023 or earlier, flush() dumps random amounts of unread data from the incoming buffer. After verifying that there is data, you dump it all and then proceed to read something. That makes no sense at all.

It appears that the number of characters in a packet is a constant, and that the start of a packet is a known quantity. You should read whatever is available, without a delay(). You know when a packet starts, and how long a packet is, so wasting resources using the String class is unnecessary. When the S arrives, reset index and set the 0th element of a suitably sized char array to NULL.

Then, each time a character arrives, store the character, increment the index, and store another NULL.

Only do something with the serial data when the proper number of characters has been received.

And, clearly that wasn't all of your code.