Very interesting ideas Richard which I will take a little time to study and mull over.
In the meantime, a couple of things I do in my own Arduino-Processing serial comms are:
- When Processing opens the COM port the Arduino should respond with an identifier string that the Processing code can recognize as a valid response. If it doesn’t get it (It should look for it in the serialEvent() handler) then an error message could be displayed. Actually what I am doing is having a text field in the app window that says “Not Connected” and this changes to “Connected” if the correct identifier was received.
- To allow the end user to select the correct COM port I populate a drop-list with the available COM ports on the system and let them choose hopefully the correct one. If they do select the right port then the “Not Connected” text can be changed to “Connected”.
Idea #2 breaks your suggested requirement of not requiring any libraries as I use @quark 's excellent G4P library to handle the drop-list and user’s selection. If you are aiming your idea at coders rather than end-users of the finished apps, then maybe it’s not necessary to let the user select the COM port and it can be hard-coded as in your example.
Regards
Phil.