Rockwell Automation 1771-DMC_DMC1_DMC4_DXPS Control Coprocessor User Manual User Manual

Page 124

Advertising
background image

Chapter 7

Using the Serial Ports

7-16

/*** Report that watchdog timed out. All characters not sent in time ***/

if (watchdog == -1)

{

if (tmp_count > 0){

if ((status = read(path, tmp_buff, tmp_count)) == -1)

{

fprintf(stderr, “**** ERROR flushing input buffer ***\n”);

return(-1);

}

}

fprintf(stderr, “**** ERROR transmitting all characters - timeout ***\n”);

if (tmp_count != sent

fprintf(stderr, “**** ERROR flushing buffer not equal to characters sent ***\n”);

return(-1);

}

/*** Disable the transmitter ***/

if ((status = _ss_enrts(path)) == -1)

{

fprintf(stderr, “**** ERROR turning off the transmitter ***\n”);

return(-1);

}

/*** Flush the echo from the input buffer ***/

if ((status = read(path, tmp_buff, tmp_count)) == -1)

{

fprintf(stderr, “**** ERROR flushing input buffer ***\n”);

return(-1);

}

return(sent); /* Return the number of bytes sent */

} /* End of function */

#include <modes.h>

main(argc, argv)

int argc;

char *argv[];

{

int status;

int x=5;

int time=0;

int path;

char output[20];

char input[25];

int timeout;

strcpy(output, “abcdefghijklmnopq”);

x = atoi(argv[2]);

timeout = atoi(argv[3]);

path = open (argv[1], (S_IREAD | S_IWRITE));

init_485(path);

while(x--){

write_485(path, output, 17);

read_485(path, input, 22, timeout);

printf (“Received --> %s\n”, input);

tsleep(5);

}

}

Advertising