Go Down

Topic: Sending byte streams over Serial (Read 704 times) previous topic - next topic


Jun 04, 2009, 05:08 pm Last Edit: Jun 04, 2009, 05:09 pm by ArduinoBerlin Reason: 1
Hi, I have an external device connected via serial (hardware serial on tx pin) to the Arduino and want to send c structs as byte streams over the connection. The built-in Serial.print() function fails at this as it expects arrays of ASCII-formatted chars. It won't print an array of uint8_t.

In order for this to work, I hat to add the following to Print.cpp in the Arduino Core:

Added to Print.h:
Code: [Select]

void printRaw(uint8_t b[], int len);

Added to Print.cpp:
Code: [Select]

void Print::printRaw(uint8_t  b[], int len)

Is there any way this could be included in the nex Arduino release? I think a feature for sending byte arrays is sorely missed in the Serial.print() function.


You should just use:

Code: [Select]
void Print::write(const uint8_t *buffer, size_t size)

This is already in the Print class.

Code: [Select]
Serial.write(mybuffer, 10);


(yes, this topic is almost 2 months old, but no one answered)


)I missed this one first time too)

want to send c structs as byte streams over the connection.

Be aware that this may not always work as you expect for two main reasons:
1) Different architecture machines may have different endianness, and
2) even similarly endian machines may have different alignment requirements resulting in unseen packing bytes in structures, so always check that the "sizeof" operator returns the same value on both machines.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131