Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
7 years, 9 months ago.
Why I can't find any example using Serial.write() function ?
When sending data by serial, all the examples use putc(). Why no one uses write() function. If I want to send something like: g|counter, where counter is an int variable, can I use write() function ?
I used the printf to send it, i.e: device.printf("g|"%d,counter) but I am not sure if this is a good way.
Thank you for any help.
2 Answers
7 years, 9 months ago.
The write function is a relative new one, which is only supported on part of the devices. It sends it completely asynchronously on the background, similar to BufferedSerial or MODSERIAL user libraries do. Although they are both easier to use since for them you don't need seperate commands. Also in your example, you would first need to create a string with sprintf, and then you can send that string using the write function.
But to answer your question: No one uses it, since vast majority sticks to the 'old' functions that work on every target.
And to answer your next question: Your Disco board should support write, your LPC1768 won't.
7 years, 9 months ago.
Here is a very handy reference that can help with your questions. http://www.cplusplus.com/