I recently wrote some message queueing functionality to ensure good communication between Processing and Arduino.
It works like this:
- Processing stores all the messages it wants to send in an array
- messages in the queue are sent one by one, and Arduino sends back a confirmation after each one it receives
- make sure that Processing only sends the next message after receiving confirmation about the previous one
I've also added a timeout so that a lack of confirmation for a given time triggers the same message to be sent again. Also, if after a couple of tries the message is still not confirmed, it is put at the end of the queue to retry later when the other messages have been sent.
It's mostly a matter now of deciding on a 'language' for Processing and Arduino to communicate with (e.g. I use the message '999' for confirmation and I precede each message from Processing with a number to specify the type of message that will follow). The exact nature of this language is up to you.
If anyone wants an example, let me know. I can post it here, but it'll take a little while to clean up the code and unless anybody wants it I won't go through the trouble