

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. Basically the same as the Arduino's C++ functions. The arduino gets them, looks at the first 2 bytes, and uses that to identify the command.Ĭommands are setMode, digitalWrite, digitalRead, etc. There are about 9 commands, each with an integer identifier and a couple bytes of data along with them.
#PA035 SERIAL COMMUNICATION PROTOCOL CODE#
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? It probably wouldn't be disordered (sending is synchronized on the Scala side), but I could see a byte missing here and there. 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. Where does the "disordered data" originate? The Arduino or the PC? I don't understand the question, I guess. I read your whole post, twice, to make sure I didn't miss anything. It works with interrupts as well, exactly the same except it uses Arduino's interrupt mechanism and does not check within the loop. If and only if the input from that pin has changed from its previous value, a notification is sent back to the computer which triggers the listener function. The way it works is that these "listeners" are sent to the arduino with identifiers, the arduino checks the appropriate pins in the loop. Mute.listenOn(execute("amixer set \"Master\" toggle")) Volume.attachInterrupt(InterruptType.Change) This is a Scala class that listens to a number of input pins and sends out appropriate responses and issues commands directly on the computer it runs on. Right now I have an extremely simple command protocol that will fail upon disordered data.Īny suggestions on what I can use just for the communication? Looking for something like a very primitive version of TCP that works over serial and protects data integrity.Īnd just for kicks here's how it works (this is all working now perfectly besides the data transfer issues) in Scala code. I'm working on an Arduino -> Scala/Java bridge and am having some issues with serial communication.
