Serial.write only sending one byte of 2-byte Integer?

I am trying to establish Binary communication from arduino to a PC program (in VB6).

I have gotten binary comms working but it only seems to write the Least Significant Byte of the 2-byte Integer.

To my dismay this seems to be what the Arduino sends, according to the Reference for Serial.Write which states:
Serial.write(val) where val: a value to send as a single byte

Am I missing something here?
Surely if you tell it to send an Integer it will send the whole 16 bits and not just the LSByte?

thanx in advance
Socco

Surely if you tell it to send an Integer it will send the whole 16 bits and not just the LSByte

Wishing for something and it being as you wish it is not how things work in the real world.
The serial UART is a byte-wide device.
Recommended reading:
http://arduino.cc/en/Reference/LowByte
http://arduino.cc/en/Reference/HighByte

(BTW, a byte or char is an integer - perhaps you meant "int")

Serial.write can take 3 forms.

Serial.write(val)
Serial.write(str)
Serial.write(buf, len)

You might want to use the 3rd.
buf is a pointer, probably a byte pointer but I think you can cast your way around that and point to an int.
In that case, len would = 2.
Just what order the bytes would be sent shouldn't take long to find out.

ps/btw -- if you have an array, you could send it along with one command.

Oh, I see: I must call it twice using HighByte(int) and LowByte(int) in order to send the complete int.
Thank you for the guidance.

So, even though the Serial.Write command will happily accept an int it will only write a portion of it.
And the compiler will happily accept and compile without any warning to the user.

That IS a trap for new players.
I will learn from this and hopefully others may also learn from this post.
I would suggest the reference be augmented here to make it clear at first read that only a byte is sent. Maybe some extra examples for sending multi-byte number types.

So, even though the Serial.Write command will happily accept an int it will only write a portion of it.
And the compiler will happily accept and compile without any warning to the user.

No, the compiler does not happily accept it.
It probably generates tons of warnings for each and every one of your sketches.
And mine too, most likely.
But, for the sake of sanity here on the forum, they're suppressed.
C allows you to do lots of things that can (and do) trap the unwary. Most of the time, they're harmless.

If you want to know what parameters a function accepts, either look at the Reference page over at the Main Site, or have a look at the header files that contain the function prototypes.

void setup(void) {
  Serial.begin(9600);
  Serial.println("testing...");
  int test[16];
  for (byte i=0; i<16; i++) {
    test[i] = i * i;
    Serial.print( test[i] );
    Serial.print( " " );
  }
  Serial.println();
  byte *buf;
  buf = (byte *) test;
  Serial.write( buf, 32 );
}

void loop(void) {
};

:stuck_out_tongue:

 Serial.write( buf, 32 );

A lot of non-printing codes in there :frowning:

Yes, you need a program that can make sense of them and know when the data stream ends, etc.
But you can send binary data through the serial connection using Serial.write().