Wavetronix Click 500 (programmable controller) (CLK-500) - Developer Guide User Manual
Page 81
80
CHAPTER 8 • SERIAL MESSAGE SUPPORT
The example code below shows the power and flexibility of the Click 500 message library.
This example incorporates several variable parameters, a checksum and other formatting
and control characters into a message.
ClickMsgString message3;
Message3 = ClickMsgCreate(“
“%4x[address]*GHI” \
“%10B[]#005W\x61#%##%4CSUM[0]>”);
The “\” characters at the end of the first two lines of the Message3 creation string are a Dy-
namic C pre-compiler directive used to concatenate the quoted strings on the ensuing lines.
Table 8.2 below contains the message format from the preceding example.
Message Segment
Explanation
ABC
Three literal ASCII characters used as a preamble
%2B[index]
A two-byte binary variable field associated with a two-byte variable
array labeled “index”
%L[msg]
The byte-length of the subsequent variable-length field with the
matching “msg” label
DEF
Three literal ASCII characters (the separation between %L and %V
shows that these fields do not need to be back-to-back)
%V[msg]
A non-fixed-length binary variable field. The byte-length of this field
is specified by the preceding byte field with the matching label name
(i.e. %L [msg]) .
%8c[password]
An eight-character ASCII field associated with a null terminated C
string variable labeled “password”
%4d[numAccesses]
A four-character ASCII string representing a decimal value associated
with an unsigned 32-bit variable labeled “numAccesses”. Since 4 char-
acters or digits are specified in this example, the maximum possible
value is decimal 9999.
%4x[address]
A four-character ASCII string representing a hexadecimal value associ-
ated with an unsigned 32-bit variable labeled “address”. Since 4 char-
acters or digits are specified in this example, the maximum possible
value is hexadecimal FFFF (decimal 65535).
*GHI
The “*” is a wildcard character that will receive a variable number of
bytes until the literal-footer-sequence “GHI” is found.
%10B[]
A ten-byte binary variable field that is received and discarded
#005W
Five literal ASCII ‘W’ characters. This shorthand can be used to insert a
series of literal characters into message.
\x61
A literal hexadecimal byte with the decimal value of 97
#%##
A literal ASCII’ %’ character followed by a literal ASCII ‘#’ character