SerialDataParser library

I’ve just published a library that takes care of a lot of the heavy lifting that is involved in parsing commands over the serial port

The library can be found on GitHub: https://github.com/mdjarv/serialdataparser

A short usage example taken from the README

#include <SerialDataParser.h>

SerialDataParser sdp('^', '

Open a serial terminal and send in the string

^CMD,val 1,val 2,val 3$

and you should see the following output:

myParser:
  val 1
  val 2
  val 3

Regards,
Mathias, ‘,’);

void myParser(String *values, int valueCount)
{

Serial.println(“myParser:”);
   for(int i = 1; i < valueCount; i++)
   {
       Serial.print("  ");
       Serial.println(values[i]);
   }
}

void setup()
{
   Serial.begin(9600);

sdp.addParser(“CMD”, myParser);
}

void loop()
{
   sdp.readSerialData();
}


Open a serial terminal and send in the string

§DISCOURSE_HOISTED_CODE_1§


and you should see the following output:

§DISCOURSE_HOISTED_CODE_2§


Regards,
Mathias

SerialDataParser sdp(’^’, ‘$’, ‘,’);

Not to be nit-picky but why have the delimiter at the end instead of the middle?

I say this because when your sending an encapsulated packet of data, you first see the StartOfData character ‘^’, followed but the delimiter(s) ‘,’, and finally the EndOfData character ‘$’. So why not keep it in the same format?

^CMD,val 1,val 2,val 3$

One other thing, does your library know what data its receiving? Can it determine if your sending mixed type data(floats, int char), or does it just split the incoming data into parts and the user must specify what to do with those parts?

void myParser(String *values, int valueCount)

Using Strings (capital S) is not a good idea in the Arduino due to the limited memory available.

I've spent a little bit of time thinking about the problem you are trying to solve and I have written a couple of demo sketches here and here.

It seems to me that it is very difficult to generalize about users' data input needs and I reckon teaching them how it is done allows them to adapt solutions to their own requirements whereas a Library forces them to fit their needs to somebody else's concept.

The other thing that bothers me about Libraries is the problems they cause for users when they go wrong or don't do what the user expects. This is less likely with, for example, the Servo Library which has a very narrow remit compared to a Library that attempts to parse data.

...R

I've spent a little bit of time thinking about the problem you are trying to solve and I have written a couple of demo sketches here and here.

? Was this meant for me, because I already have my own methods that work, but I was asking if mdjarv's library could distinguish the incoming data into different types or just split it up like strtok()

HazardsMind: ? Was this meant for me,

Sorry for the confusion. I was addressing myself to the OP.

...R

Oh ok.