Pages: [1]   Go Down
Author Topic: Combine hex for xbee  (Read 190 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is there a way to combine several Serial.write's into one?

For example, in this DH and DL xbee snippet (I've left off the other parts of the frame)
Code:
 
Serial.write((byte)0x00);
Serial.write((byte)0x13); 
Serial.write((byte)0xA2);
Serial.write((byte)0x00);
Serial.write((byte)0x40);
Serial.write((byte)0xB0);
Serial.write((byte)0x9D);
Serial.write((byte)0x78);
Serial.write(0xFF);
Serial.write(0xFE);

// this would be the checksum
long sum =  0x00 + 0x13 + 0xA2 + 0x00 + 0x40 + 0xB0 + 0x9D + 0x78 + 0xFF + 0xFE;


I've tried building the DH and DL part of the frame like this. But this doesn't work. (I'm just showing the DH and DL part of the frame)

Serial.write(0x0013A200);
Serial.write(0x40B09D78);
and then the checksum
long sum = 0x17 + 0x0013A200 + 0x40B09D78 + 0xFF + 0xFE;

My goal is to combine the high and low byte of the destination xbee into one line.

Can someone help
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 170
Posts: 12487
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Is there a way to combine several Serial.write's into one?
1) yes, make an array of it

uint8_t ar[] = {  0x00 ,0x13 , 0xA2 , 0x00, 0x40, 0xB0, 0x9D , 0x78 , 0xFF, 0xFE};
Serial.print(ar, 10);

2) it wont be substantial faster as the write functionis faster than the serial Port normally
     still it might reduce the footprint of the code/exe

If I recall correctly the calcultion of the checksum is still per byte, so
long sum =  0x00 + 0x13 + 0xA2 + 0x00 + 0x40 + 0xB0 + 0x9D + 0x78 + 0xFF + 0xFE;
is the right way even is you send the bytes like
Serial.write(0x0013A200);

Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Pages: [1]   Go Up
Jump to: