Sming - Open Source framework for high efficiency native ESP8266 development

User avatar
By helpme
#37441 This code was adapted from the Basic_Serial example. I am interested in receiving characters on the UART.

Code: Select allvoid init()
{
   Serial.begin(SERIAL_BAUD_RATE); // 115200 by default
   Serial.setCallback(onDataCallback);
}

void onDataCallback(Stream& stream, char arrivedChar, unsigned short availableCharsCount)
{
   unsigned charReceived = 0;
   unsigned numCallback = 0;
   bool useRxFlag = true;

   Serial.print("Class Delegate Demo Time = ");
   Serial.print(micros());
   Serial.print(" char = 0x");
   Serial.print(String(arrivedChar, HEX)); // char hex code
   Serial.print(" available = ");
   Serial.println(availableCharsCount);

   numCallback++;

   if (arrivedChar == '\n') // Lets show data!
   {
      Serial.println("<New line received>");
      while (stream.available())
      {
         char cur = stream.read();
         charReceived++;
         Serial.print(cur);
      }
      Serial.println();
   }
}


- How does one know that the function parameters of onDataCallback(Stream& stream, char arrivedChar, unsigned short availableCharsCount) is like that?
- Where are one get the documentation for stream? Is it the same as Arduino stream? Documentation for Arduino stream found https://www.arduino.cc/en/Reference/Stream
- After receiving many characters, availableCharsCount stops at 255. Why can't it go above 255? Where can I find the documentation?

Are there any comprehensive documentation for Serial.setCallback()?
User avatar
By hreintke
#37806 Late but still a reply.

Yes, we are seriously lacking on documentation.
For your questions :

1/ Currently only in code
HardwareSerial.h ->
typedef Delegate<void(Stream &source, char arrivedChar, uint16_t availableCharsCount)> StreamDataReceivedDelegate;

2/ I am not fully aware of the Arfuino Stream functionality so cannot answer now.

3/ The internal buffer of HardwareSerial is 255 characters. When this is reached, the callback will be used bt the received char not saved.
If you want larger buffer you need to use own/local buffer. So either read and use/ save before HardwareSerial buffer reaches 255 or use : Serial.setCallback(onDataCallback, false) which disables use of the HardwareSerial internal buffer and save each received char in callback.

FYI : There is a known issue in the Serial Callback causing reset when receiving on uart. This is already solved in the develop branch and will be released in Sming V2.1 shortly.
User avatar
By helpme
#37921 Thanks for the reply.

I assume SMING libraries are derived from the Arduino libraries. Is it ok to use Arduino documentation in cases when SMING documentation is still not yet finished?

May I ask what is the difference between using HardwareSerial internal buffer versus saving each received char in callback? What are the downsides, if any, of using
Code: Select allSerial.setCallback(onDataCallback, false)
?

I am waiting eagerly for the release of Sming V2.1 :) Thanks for the great work!