beautypg.com

Directly accessing receive message variable data – Wavetronix Click 500 (programmable controller) (CLK-500) - Developer Guide User Manual

Page 85

background image

84

CHAPTER 8 • SERIAL MESSAGE SUPPORT

The maximum value that a variable can represent is 4,294,967,296 as the value transferred

is stored in a 4-byte field. Of course to send this high of a decimal number you would need

10 digits of ASCII characters.

Note

If you need to receive a signed integer, try receiving it as an unsigned long and then
copying it into the desired data type using a type cast.

The advantage of sending data as ASCII is that it is human readable or writable in serial

terminal programs that do not have a way to intelligently display binary data. However,

many serial terminal programs display binary data in hexadecimal byte format. If you elect

to transfer data as binary information, your data messages can be much shorter. To transfer

data as binary, use a variable array (%B) to receive the bytes into the correct data type. Pay

attention to byte order when mapping bytes between an array of bytes and a desired data

type.

Directly Accessing Receive Message Variable Data

ClickMsgReadVar and ClickMsgWriteVar provide a simple way to access variable data

within a receive message. However, in some cases it may be advantageous to have direct

access to the buffer of receive data. The function ClickMsgGetRxSnapshot gives you access

to all the bytes of the last received message on each virtual port. This function allows you

to create a snapshot of the last received message. This snapshot will not be overwritten if

another message is received on the port while you are still processing the snapshot.

ClickMsgGetRxSnapshot has three parameters. The first parameter allows you to select

which virtual port data you want to read. The second parameter is a pointer that will be set

to the start of a snapshot of the receive buffer for this virtual port. The third parameter al-

lows you to create a snapshot of the last message in the receive buffer (value = 1), or simply

to access a previous snapshot (value = 0). The function returns the number of bytes cur-

rently in the snapshot receive buffer.

ClickMsgReadVar(“sec1”,&u32tmp);
newTime.Second = (unsigned char)u32tmp;
ClickMsgReadVar(“ms1”,&u32tmp);
newTime.MSec = (int)u32tmp;

ClickUtilSetTime(&newTime);

BuildTimeResponseMsg();
ClickMsgTransmit(TimeResponseMsg,V1);