PaulS:
I read your whole post, twice, to make sure I didn't miss anything. I don't understand the question, I guess. Where does the "disordered data" originate? The Arduino or the PC?
It could originate from either side, my point is I'm looking for a bit more reliability than just hoping that all of the data sent from PC -> Arduino or Arduino -> PC gets to the other side.
It probably wouldn't be disordered (sending is synchronized on the Scala side), but I could see a byte missing here and there.
PaulS:
What, exactly, does that code cause the Arduino object to send to the serial port? Where is the Arduino code that handles the data that the Arduino object sends?
There are about 9 commands, each with an integer identifier and a couple bytes of data along with them. The arduino gets them, looks at the first 2 bytes, and uses that to identify the command.
Commands are setMode, digitalWrite, digitalRead, etc. Basically the same as the Arduino's C++ functions.
PeterH:
Those are pretty sketchy requirements and nowhere near enough information to design a protocol, but it sounds to me as if your problem is essentially how to detect complete and valid message frames out of a byte stream. You could achieve that by defining start/end flags to denote your message boundary, define a message structure that incorporates a checksum, and if your start/end flags could legitimately appear within the message then also provide a mechanism to escape them.
I don't need anything fancy, just the most basic packet protocol.
I just went ahead and threw a very basic one together with a start/length/checksum.