8 years, 9 months ago.

Difficulties with Serial documentation

I am having some difficulties with the Serial class documentation here https://developer.mbed.org/users/mbed_official/code/mbed/docs/252557024ec3/classmbed_1_1Serial.html

Serial::read() function

  1. This function is listed in the documentation under Public Member Functions. However, the compiler complains that it is inaccessible.
  2. I also cannot make any sense out of the callback parameter of this function. I understand that this is suppose to be a function with specific parameter type.
  • Exactly what format should the callback function conforms to?
  • Where is "event_callback_t" documented? The hyperlink leads to a generic unhelpful article about callback function.

Cannot find documentation of some functions

I cannot find any documentation of the following functions:

  • getc()
  • gets()
  • putc()
  • puts()
  • scanf()
  • printf()

Are they documented anywhere? I had to view various example to even learn that I can use those functions. Meanwhile scanf() gets() also does not have the same parameters expectation like its normal C++ counterpart. I find it really weird and bothersome that it is not documented in the class documentation page.

1 Answer

8 years, 9 months ago.

The read functions only works when the async functions are implemented, which is only done on a few SiliconLabs boards (and yes, no argument from me there that that is really confusing).

Everything else is not documented since it is not implemented in the mbed lib, it is also inherited from the C++ standard lib. (They could still document them in the serial class though, that would help). I have no idea why scanf wouldn't take the normal arguments since it simply is inherited from the C++ lib of the compiler. Possibly because your targets use the ARM microlib (which is smaller than the regular one), it might lack some things of the complete C++ standard.

My apology on the scanf() note. It is gets() that does not take in the same parameter as its counterpart does in C++. But can I assume your guess still holds for gets()? I will update my question to correct that.

posted by Hieu Vo 25 Feb 2016

Yes, for the regular Serial lib the same holds true for gets. Which difference do you see?

posted by Erik - 25 Feb 2016

Normal gets() in C++ only expects a pointer to the buffer, as shown here http://www.cplusplus.com/reference/cstdio/gets/

However when I use gets() in an ST Nucleo project, the compiler expects two parameter. The first being the same buffer pointer. The second is a kind of int. I could only guess that the second parameter is the buffer size.

posted by Hieu Vo 25 Feb 2016

It is also interesting to note that the reference prompt that appear when I put the cursor on the "gets" keyword shows a reference where only one parameter is expected. But if I only provide one parameter the compiler will surely complain.

Just to clarify myself, if the second parameter is indeed supposed to be buffer size, then I think it is a good idea, because it makes gets() safer. What I am trying to do here is simply requesting a clearer documentation regarding these functions availability and difference.

posted by Hieu Vo 25 Feb 2016

Your guess is probably correct, if they are being consistent with fgets then the second parameter will be the maximum size including the null terminator. All logical and understandable and generally a good thing but weird that that documentation is incorrect.

posted by Andy A 25 Feb 2016

I checked it for the LPC1768, which uses the normal ARM lib, and that shows the same behavior. Weird part is mainly that it is different from the standard, while this should simply come from the Keil compiler.

posted by Erik - 25 Feb 2016