Request/response examples – Echelon Neuron C User Manual
Page 152

140
How Devices Communicate Using Application Messages
To use this field, you must include the
> files . Request/Response Examples This example shows sending a request and asynchronously receiving the responses. The code for receiving this request and responding to it follows in the next example. msg_tag tag1; Here is the code for the responder to this request: #define DATA_REQUEST 0 int x, y; x = msg_in.data[0]; y = get_response(x); resp_out.code = OK; // msg_in no longer available resp_out.data[0] = y; resp_send(); The following example shows sending a request and receiving the responses directly: int x;
#define DATA_REQUEST 0
when (io_changes(toggle))
{
msg_out.tag = TAG1;
msg_out.code = DATA_REQUEST;
msg_out.service = REQUEST;
msg_send();
}
when (resp_arrives(TAG1))
{
if (resp_in.code == OK)
process_response(resp_in.data[0]);
}
#define OK 1
when (msg_arrives(DATA_REQUEST))
{
}
msg_tag motor;
#define MOTOR_ON 0
#define DO_MOTOR_ON 3
when (command == DO_MOTOR_ON)
{
// send a request
msg_out.tag = motor; // construct the message
msg_out.code = MOTOR_ON;
msg_out.service = REQUEST;