Format string reference – Measurement Computing LogBook Series User Manual
Page 96

6-8 GPS and Serial Device Data Collection
958396
LogBook User’s Manual
In this case, the simple format string %f would instruct the LogBook to start at the 1
st
character in the serial input
string sentence. It would then begin the conversion to a floating point number until a character was encountered
that could not be converted. If a %I, for integer, was used instead of %f,
the LogBook would record +12 instead of +12.32.
Format String Reference
The format string provides instructions to the LogBook’s internal parser allowing it to parse, then to convert
numerically a specified section of an ASCII string from a serial device. The format string contains directives for
accepting and rejecting parts of the string. Only one section of each ASCII string can be accepted and converted for
each serial channel.
The parsing and converting process begins when the LogBook senses the serial input string sentence, a string from
the serial device that is terminated by a CR and/or LF. Each enabled Serial Channel will attempt to parse the entire
serial input string. To successfully parse and convert a number or character in a string, all of the characters up to
the desired field must be accounted for in the format string. The first character encountered that does not match the
format string will cause the parsing operation to fail with no conversion process. The serial channel associated with
a failed parsing operation will remain unchanged.
Each format string contains directives to ignore all the characters except those of interest. A format string can
contain several optional “ignore” directives, but must contain one and only one “accept and convert” directive. The
“accept and convert” directive must be the last item in the format string. A format string can contain any or all of
the following:
Format
directive
Description
Example
Comment
%Xy
The “%” character signifies the
beginning of a conversion directive.
“X” is a decimal integer specifying the
maximum length of the desired field,
while “y” is a character that specifies
the conversion type.
%3i
%c
%6f
Convert 1-3 character integer.
Convert 1 character.
Convert 1-6 character float.
%*Xy
The “%” followed by the “*” character
signifies the beginning of a rejecting
directive. “X” and “y” are the same as
above.
%*7c%i
%*i,%i
Reject 7 characters, convert an
integer.
Reject 1 integer and a comma,
convert 2
nd
integer.
White space
Tabs or spaces to be taken literally then
rejected
.
%*i %f
Reject 1 integer and a space,
convert a float.
Regular
characters
Literal characters that are to be
matched exactly in the serial input
string, then rejected
$GPGGA,%f Match and reject “$GPGGA,”
exactly, convert a float.
Format string examples:
LOAD:%f
Match the literal “LOAD:” then start converting a float.
%*14c%i
Ignore
the
1
st
14 characters, then start converting an integer.
%*i,%*i,%*i,%f
Ignore 3 integers followed by commas, then start converting a float.