Simple and Robust {Computer — Arduino} Serial Communication

I have had a bit of spare time so out of curiosity I took the trouble to download some of your Arduino code. I downloaded the 4 files order.h, parameters.h, slave.cpp and slave.h from ..../araffin/arduino-robust-serial

I changed the name of slave.cpp to slave ,ino and it compiled without any error. Then I realized that it does not need the file slave.h so I commented out the line #include "slave.h" and it compiles fine.

I have to say I do not believe your code is as robust as you would like to think because you have no means to identify the start and end of a message or to validate the content of a message. And you attempt to read multiple bytes even though you only check that there is at least one available.

IMHO the system in the 3rd example in Serial Input Basics is considerably more robust as it does not try to interpret any part of a message until it has a complete message. That makes it easy to extend it to include a checksum.

As you mentioned earlier it is designed to work with text rather than binary data but it is equally possible to implement a similar system for binary data. I have also used a system in one of my own projects that converts numbers to a sort of base64 code and sends them as ascii data - 3 characters can represent numbers up to about 266,000. By sticking with human readable characters debugging is much easier and the conversion to "proper" numbers is much faster than the atoi() function.

Another problem I have with your code is the use of wait_for_bytes() to wait for a number of bytes to arrive. Serial is very slow by Arduino standards (even at 500,000 baud) and it is a waste of resources to wait for data to arrive.

...R