I'm having difficulty understanding how Arduino reads incoming information via serial. My current project has me transmitting information from Windows over serial. I've sent 3 short ints (i.e.: 6 bytes of information on Windows) which I want Arduino to receive as ints. The short ints were stored in an array of ints (int buffer) and I intend to be able to extract those 3 ints so I can use them for whatever later on in my program.
Here are the things that are preventing me from proceeding:
1) I believe that Serial.readBytes() is a better option for me because Serial.read() only reads a single byte of information and I want to store more than one byte. Is this correct or is there a way to manipulate Serial.read() to work for me?
Assuming Serial.readBytes( val1, val2 ) is the way to go, I'd like some clarification because the tutorial on this website leaves a bit of ambiguity in my opinion:
2) the function itself returns the number of bytes that have been transmitted. However, it also stores all of the bytes read in the buffer val1. In my case, is val1 going to have to be at least 6 bytes to contain it all? If so, does the following appear the correct way of setting this up?
int val1; int val2 = 6;
int numberOfBytes = Serial.readBytes( val1 , val2 );
The variable numberOfBytes should contain 6 bytes. The array val1 should contain 3 ints received by Arduino and Arduino will stop reading information once it receives 6 bytes (val2). Correct?
3) Can val2 be longer than 6 bytes? If it can, is it safe to assume that the information will just not be considered in my program?
4) The Arduino tutorial indicates that the data is stored as chars or bytes. Does this mean I need to cast the data as ints to read it?
I have been playing around with Serial communication for the last little while and I feel there is a flaw in my understanding somewhere because what I'm attempting doesn't appear to work. I can post the entirety of my code but I'm trying to understand the "theory" behind it so I can proceed with more ambitious projects with the correct understanding.
Thank you! Let me know if further clarification is required.