Download TelePACE C Tools User Manual

Transcript
The calling task monitors the status of the command sent using the get_protocol_status
function. The command field of the prot_status structure is set to MM_SENT if a master
message is sent. It will be set to MM_RECEIVED when the response to the message is
received with the proper length. It will be set to MM_RECEIVED_BAD_LENGTH when a
response to the message is received with the improper length.
Notes
Refer to the communication protocol manual for more information.
Users of TeleSAFE BASIC and the TeleSAFE 6000 C compiler should note that the address
parameter now specifies the actual database address, when used with the Modbus protocol.
This parameter specified the address offset on these older TeleSAFE products.
To optimize performance, minimize the length of messages on com3 and com4. Examples
of recommended uses for com3 and com4 are for local operator display terminals, and for
programming and diagnostics using the TelePACE program.
The IO_SYSTEM resource must be requested before calling this function.
See Also
clear_protocol_status
Example Using Modbus Protocol
This program sends a master message, on com2, using the Modbus protocol, then waits for
a response from the slave. The number of good and failed messages is printed to com1.
/* -------------------------------------------poll.c
Polling program for Modbus slave.
-------------------------------------------- */
#include <ctools.h>
/* -------------------------------------------wait_for_response
The wait_for_response function waits for a
response to be received to a master_message on
the serial port specified by stream. It returns
when a response is received, or when the period
specified by time (in tenths of a second)
expires.
-------------------------------------------- */
void wait_for_response(FILE *stream, unsigned time)
{
struct prot_status status;
static unsigned long good, bad;
interval(0, 1);
settimer(0, time);
do {
/* Allow other tasks to execute */
release_processor();
status = get_protocol_status(stream);
}
while (timer(0) && status.command == MM_SENT);
if (status.command == MM_RECEIVED)
TelePACE C Tools User and Reference Manual
May 9, 2007
325