Take a look at the Receive example in this thread

http://www.picbasic.co.uk/forum/showthread.php?t=6261

It's very similar to what you need to do.