Pages: [1]   Go Down
Author Topic: SerialDataParser library  (Read 137 times)
0 Members and 4 Guests are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
#include <SerialDataParser.h>

SerialDataParser sdp('^', '$', ',');

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

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

and you should see the following output:

Code:
myParser:
  val 1
  val 2
  val 3

Regards,
Mathias
« Last Edit: Today at 04:07:01 am by mdjarv » Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 86
Posts: 3466
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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?

Quote
^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?
Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Pages: [1]   Go Up
Jump to: