How we Read 31 bytes Data in Serial Communication

Does the 31th byte have always the same value?

If yes you could check for this byte as endmarker.
Robin2 has a great tutorial serial input basics updated about this

best regards Stefan