tags:

views:

289

answers:

3

hai in vc++ i am using MScomm for serial communication, i received data in this format 02120812550006050.0, i am not gettng how to read this ,in which format it is, begning starting frame and at the end ending file, remaing i dont know.

EDIT 1:

it contains date time and data how i can seperate this one

A: 

It is unlikely that you will figure it out unless you know what you are communicating with and how it communicates with you. (hint -- you can try telling us)

A: 

it contains date time and data how i can seperate this one

Pls delete this 'answer', it should have beenm edited into the question.
paxdiablo
+1  A: 

The funny characters are markers indicating things like record start, record end, field separator and so on. Without knowing the actual protocol, it's a little hard to tell.

The data is a lot easier.

Between the 000f and 0002 markers you have a date/time field, 2nd of December 2008, 12:55:00.

Between 0002 and 0003 marker, it looks like a simple float which could be a dollar value or anytrhing really, it depends on what's at the other end of the link.

To separate it, I'm assuming you've read it into a variable character array of some sort. Just look for the markers and extract the fields in between them.

The date/time is fixed size and the value probably is as well (since it has a leading 0), so you could probably just use memcpy's to pull out the information you need from the buffer, null terminate them, convert the value to a float, and voila.

If it is fixed format, you can use something like:

static void extract (char *buff, char *date, char *time, float *val) {
    // format is "\x01\x0fDDMMYYhhmmss\x02vvvvvvv\x03\x04"
    char temp[8];
    memcpy (date, buff +  2, 6); date[6] = '\0';
    memcpy (time, buff +  8, 6); time[6] = '\0';
    memcpy (temp, buff + 15, 7); temp[7] = '\0';
    *val = atof (temp);
}

and call it with:

char buff[26]; // must be pre-filled before calling extract()
char dt[8];
char tm[8];
float val;
extract (buffer, dt, tm, &val);

If not fixed format, you just have to write code to detect the positions of the field separators and extract what's between them.

paxdiablo