Name

cyg_ccb_build_message — Construct message

Synopsis

#include <cyg/io/ccb.h>

cyg_uint32 cyg_ccb_build_message(ccb_msg_t *msg, cyg_uint8 slave_addr, cyg_uint8 tag, const char *cmdreq);

Description

This function allows a standard client-application message to be constructed. The msg parameter is used to reference a message object to be filled. The slave_addr and tag parameters describe the destination address and client-application “message tracking number” respectively. The final parameter cmdreq is the NUL-terminated ASCII command or request. The passed cmdreq string should NOT contain a terminating CR (Carriage-Return). Any command/request terminators needed are added by this function.

The following pseudocode example shows the use of the function to construct a message and then send this message via the write function to a previously opened CCB handle.

cyg_uin32 mlen = cyg_ccb_build_message(msg,slave_addr,tag,"*IDN0?");
if (mlen) {
  write(fd,msg,mlen);
} else {
  raise_error();
}

Return value

The function returns the total number of bytes written to the passed msg buffer, or zero (0) if an error is detected.