I suggest that you read Robin's Serial Input Basics - updated
You might get some ideas how to approach your problem.