Processing – Arduino message queue
When I was working on the software for my graduation project, I found I needed a way for Processing and Arduino to communicate safely, so that no messages would be overwritten, lost or sent in the wrong order. To this end I wrote a messaging system, the code for which can be downloaded here: http://www.rockabit.com/downloads/message queueing.zip
It basically works like this: processing sends numerical messages to the arduino I/O-board over a serial connection. To ensure safe messaging, every message is preceded by another message that specifies the type of message that follows. Arduino then first receives this type identifier, knows what type of message should follow, and then receives that message and sends back a confirmation to let processing know that the message was received. Only when a message is confirmed will processing send the next message in line. Also, if a message is not received for 2 seconds, it is resent, and if resending has no effect then it is placed at the back of the queue to be tried again later on