beautypg.com

Receiving data – Wavetronix Click 500 (programmable controller) (CLK-500) - Developer Guide User Manual

Page 89

background image

88

CHAPTER 8 • SERIAL MESSAGE SUPPORT

Note

At the slowest baud rates (e.g. 300 bps) you may need to delay between transmis-
sion of bytes. This can be accomplished using a blocking or non-blocking delay mech-
anism.

Receiving Data

Configuring the message watch list used by the receive message processor to handle the

reception of elected messages on a serial port is accomplished with the ClickMsgAddRe-

ceiveTaskToVPort function. The ClickMsgAddReceiveTaskToVPort function accepts a

ClickMsgString object, a function pointer, and a virtual port identifier. The ClickMsgString

object is the message type you want to listen for, the function pointer is a callback function

you want to be called upon receiving the specified message type, and the virtual port identi-

fier indicates on which port to look for this message. It is recommended to use this function

instead of the older ClickMsgAddReceiveTask function to prevent watch list memory buf-

fers from errantly interleaving partial messages received simultaneously on different virtual

ports.

A Boolean value is returned from the ClickMsgAddReceiveTaskToVPort function indicat-

ing success or failure. A failure will occur when the receive task list is full.

The following code block contains the function Setup1, which shows how to add the Ti-

meRequestMsg string to the watch list. If this message is received on V1, the SetTime call-

back function will be called. The corresponding checksum function DateChecksum is also

added to the checksum array.

void Setup1(void)
{

ClickSerialPortDisconnectAll();

ClickSerialPortConnect(V1, _485TOP);
//ClickSerialPortConnect(V1, _232FRONT);
ClickSerialPortConfigureVirtual(V1, 9600, DATABIT_8,
PARITY_N);

ClickMsgRemoveAllReceiveTask();