VC ++ 6.0 serial communication

In vC ++ I am using MScomm for serial communication, I got the data in this format 02120812550006050.0, I don't get how to read it, what format it is in, starting the start of the frame and at the end of the file end, remaing, I don't know.

EDIT 1:

it contains date and data on how I can separate this

0


source to share


2 answers


Funny characters are markers that indicate things like start of record, end of record, field separator, etc. Without knowing the actual protocol, this is a bit difficult to tell.

The data is much simpler.

Between marks 000f and 0002, you have a date / time field, Dec 2, 2008 12:55:00 PM.

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

To separate it, I am assuming you read it into a variable character array. Just find the markers and extract the margins in between.

Date / time is a fixed size, and probably this value is also (since it has a leading 0), so you could just use memcpy to pull the information you want from the buffer, null terminate them, convert the value to float and voila ...



If it's a 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 a fixed format, you just need to write code to determine the positions of the field separators and extract from them.

+2


source


It is unlikely that you will understand this if you do not know what you are communicating with and how he communicates with you. (hint - you can try to tell us)



0


source







All Articles