Count number of bytes transmited with Serial.print

Hello to all;

I'm totally new in Arduino and I don't have experience in programming, so I hope you can help me.

I'm making a communication with two Xbee and serial.print() in Simulink, but I need to know the exactly number of bytes transmitted. I'm sending an array where the values change constantly, so every time I send something I need to count the number bytes.

I found the function size_t (long): print() , but I don't have any idea of how to implement it, and the information in the web are very advanced for me.

This is my actual code, it works fine but I need to implement the transmitter count:

int as=0;    
Serial1.print('

The rest of the code are declaration of simulink but the Arduinos code is very simple.

Can you give me some idea of how implement that?

Thanks);
for (as=0;as<u_width;as=as+1){
   
Serial1.print(UART_1[as],6);
    if (as!=(u_width-1)){
        Serial1.print(',');
    }
}
Serial1.println('%');


The rest of the code are declaration of simulink but the Arduinos code is very simple.

Can you give me some idea of how implement that?

Thanks

Instead of serial.print, use either the sprintf() or the snprintf() function to format the data. Then you can determine the exact size of the buffer before sending it anywhere.

Or you could write a simple function to iterate through the array and send each byte one at a time, counting as you go.

I'm curious to know why it is necessary to know the number of bytes sent?

...R

Can you give me some idea of how implement that?

Here's a hint. Serial.print() returns a value. Can you guess what that value is? If you guessed "the number of characters it printed", you win.

int count = 0;

int as=0;   
count += Serial1.print('

);
for (as=0;as<u_width;as=as+1){
 
count += Serial1.print(UART_1[as],6);
    if (as!=(u_width-1)){
        count += Serial1.print(',');
    }
}
count += Serial1.println('%');

// count characters have been sent to the serial port...

PaulS:
Serial.print() returns a value. Can you guess what that value is? If you guessed "the number of characters it printed", you win.

Thanks. I had never taken any notice of that as I was never concerned to know.

...R