#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    28
    Rep Power
    0

    Serial Data parsing


    Hi, everybody .. I have a machine that sends data through serial port in this format.

    _____________________ HSU-avg = 00 (HSU)
    K-avg = 0.01
    9 1930 2.8 0.01
    8 1940 2.8 0.01
    7 2190 2.8 0.01
    6 1810 2.8 0.01
    5 1970 18.8 0.02
    4 2190 2.8 0.01
    3 2150 2.8 0.01
    2 2070 13.1 0.01
    1 2150 25.7 0.02
    ------- ---- ----
    MAX.RPM SEC. K.
    OIL.TEMP = 0088
    -----------------------
    AVG :1040 2065
    -------- -------
    6 0830 2080
    5 0660 1890
    4 1340 1960
    3 1330 2320
    2 0690 2170
    1 0840 2190
    -------- -------
    IDLE.RPM MAX.RPM
    -----------------------

    I am very new to parsing and regex. Can anyone guide me in the right direction .. ?? what is the best way to parse this kind of data .. ?? I need to operate on the numbers column wise .
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2016
    Posts
    54
    Rep Power
    2
    A parser is basically just a run through of the line of string you have.
    Generate an object that has the columns as attributes, so 1 line = 1 instance of an object.
    The "object" delimiter is "newline" The attribute delimiter in this example is " "(space).

    you validate in the constructor of the object, that the values from the parser is valid.

    There also seems to be a "section" preluded by "---" characters, use this as a delimiter to change which type of object is being generated for the rows.

    This will let you handle each rows of info in an easy to debug fashion, and generate a data list that is simple to process or pass along.

IMN logo majestic logo threadwatch logo seochat tools logo