Creating simple messages, Creating messages with variables and checksums – Wavetronix Click 500 (programmable controller) (CLK-500) - Developer Guide User Manual
Page 80
CHAPTER 8 • SERIAL MESSAGE SUPPORT 79
Creating Simple Messages
A message is created by calling the ClickMsgCreate function. The first parameter passed to
this function is a serial string, which is formatted according to the Click messaging speci-
fication. The function returns a pointer to an object of type ClickMsgString. The string
used to define the function can be created during the function call or can be predefined
and passed to the function as a pointer. Simple examples of both methods are shown below.
ClickMsgString message1;
message1 = ClickMsgCreate(“
const char InitArray[] = {“
ClickMsgString message2;
message2 = ClickMsgCreate((ClickMsgString) InitArray);
The Click message string format specification requires a “<” character at the beginning of
the message and a “>” character at the end of the message. The example messages in the
code above consist simply of literal bytes and have no variable fields or checksums. Mes-
sage2 starts out with the lowercase ASCII characters “abc” and ends with three literal bytes
equal to decimal 10, 11 and 12 respectively. These last three bytes are specified using the
standard C format sequence “\x” to append one literal hex byte into the string at a time.
Creating Messages with Variables and Checksums
The Click format (%) and literal control (#) characters are used to specify where variables,
checksums and reserved characters appear within a message (see Table 8.1).
Character
Type of Message Segment Inserted Into the Message
%B
Variable byte array
%L … %V
Variable-length byte array starting at the location indicated by %V, with
length specified by preceding byte at location indicated by %L
%c
Variable ASCII character array
%d
Variable decimal value as an ASCII string
%x
Variable hexadecimal value as an ASCII string
%CSUM
Variable checksum field
*
Wildcard indicator followed by a predetermine sequence of literal characters
#
Literal instance of reserved characters ‘#’,’<’,’>’, ‘%”, ‘\’, or ‘”’
#007T
Literal instance of a series of 7 ASCII ‘T’ characters. The number 7 and ‘T’
character are just examples.
\x
Literal hexadecimal byte
Table 8.1 – Character Placement