03-07-2008 05:11 AM
03-07-2008 07:00 AM
03-07-2008 07:37 AM
03-07-2008 08:10 AM
03-07-2008 08:11 AM
03-07-2008 08:21 AM
In my opinion all of your code could be simplified as follows:
strncpy (EndCode, buffer + 1, 2); EndCode[2] = 0;
strncpy (Parameter, buffer + 4, 2); Parameter[2] = 0;
strncpy (Data, buffer + 10, 4); Data[4] = 0;
As you can see I am forcing a termination byte on every target string since, as stated in the online documentation, strncpy DOES NOT add it.
After this, you will have to decode the measurement string Data, that could be solved this way:
char buf[32];
double val;
if (Data[0] == 'F')
sprintf (buf, "-%s", Data + 1);
else if (Data[0] == 'A')
sprintf (buf, "-1%s", Data + 1);
else
strcpy (buf, Data);
val = atof (buf) / 10.0; // <=== ???
DebugPrintf ("%s = %f\n", Data, val);
But it remains an uncertainty on the "/ 10.0" since it does not sound good in decoding F015 to -15...
03-07-2008 08:39 AM
03-07-2008 08:45 AM