printing bytes in an object???

I am trying to print the forty-eight bytes in an object to the serial port but syntax is kicking my ass!

here is the code. I have commented the area where I am trying to send the contents of the sd to the serial port. It is an array of structures so trying to do it using a for loop is kind of a pain and seems pretty inefficient! I am hoping there is a way to convert the sd array into a flat byte array and use Serial.send(x,sizeof(x)); ???

typedef struct sensorDat
{
	byte statusColor;
	byte val[2];
} sensorDat;

enum statusColors{
	scGOOD,
	scERROR,
	scNODATA
};

void setup()
{

	// initial Random number generator
	randomSeed(analogRead(0));
	
	// open the serial port (COM9)
	Serial.begin(115200,SERIAL_8N1);

}

void loop()
{

	// create a good packet with 16 random values between 10 and 50
	sensorDat sd[16];

	for (int i=0; i<16; i++)
	{
		sd[i].statusColor = scGOOD;
		sd[i].val[0]=random(10,51);
		sd[i].val[1]=random(10,51);
	}
	
	// debug print the size the the sd object to verify that it contains 
	// 48 bytes
	Serial.print("size of sd = ");
	Serial.println(sizeof(sd),DEC);

//====================== PROBLEM AREA =========================================
	
	// Write each byte of sd to serial port ????
	
	// Serial.print(sd,sizeof(sd));     THIS DOES NOT WORK!!! HELP!!!!
	
	// How do I convert the sensorDat[] into just a flat byte array?  I do not want to 
	// have to make a loop and xmit the contents byte by byte!!!!

//====================== PROBLEM AREA =========================================
	
	
	// Close the serial port
	Serial.end();
}

Hi ctbram

Does this work any better?

Serial.write((uint8_t*)sd, sizeof(sd));

Edit: ... assuming that sizeof(sd) returns 48.

Regards

Ray

I do not want to // have to make a loop and xmit the contents byte by byte!!!!

Why? That's 4 simple lines of code, including the two curly braces as lines of code!

Hackscribble: Hi ctbram

Does this work any better?

Serial.write((uint8_t*)sd, sizeof(sd));

Edit: ... assuming that sizeof(sd) returns 48.

Regards

Ray

Unfortunately no.

I tried

Serial.print((uint8_t*)sd, sizeof(sd));

and get

PEDataGenerator.ino:44: error: call of overloaded 'print(uint8_t*, unsigned int)' is ambiguous

I also tried casting the (byte*). I am getting really frustrated as I am becoming up on over 6 hours tryiing to get this tiny piece of code working!

Just tried this and it compiles OK for me.

Serial.write((uint8_t*)sd,sizeof(sd));

Make sure you change from print to ``write.