Rockwell Automation 1771-DMC_DMC1_DMC4_DXPS Control Coprocessor User Manual User Manual

Page 76

Advertising
background image

Chapter 5

Developing Programs

5-16

/**********************************************************************
* DTL_W_R.C — This program uses both the DTL_WRITE_W and DTL_READ_W
* functions. It writes a single word to the PLC5’s N7:0 file and then
* reads it back. The copro then copies the data to the 4-digit display
* on the expander module. It will do this forever until the program
* is terminated with a CTRL-E or a kill command from the OS-9 command line.
***********************************************************************/
#include <stdio.h>
#include <copro.h>
char * CC_ERROR();
main()
{
register unsigned ret_val; /* private variable declarations */
unsigned iostat;
unsigned id_n7;
unsigned short buffer[1];
CC_INIT(); /* initialize the coprocessor */
ret_val = DTL_INIT (1); /* just 1 definition */
if (ret_val != DTL_SUCCESS)
{
print_error (ret_val); /* print error... */
exit(-1); /* and exit */
}
ret_val = DTL_C_DEFINE (&id_n7, “N7:0,1,WORD,MODIFY”); /* init for n7:0 */
if (ret_val != DTL_SUCCESS)
{
print_error (ret_val);
exit (-1);
}
buffer[0] = 0; /* initialize data word */
while (1) /* let’s do this forever */
{
ret_val = DTL_WRITE_W (id_n7, buffer, &iostat); /* write to PLC5 */
if (ret_val != DTL_SUCCESS) /* check ret_val */
break;
ret_val = DTL_READ_W (id_n7, buffer, &iostat); /* read back data */
if (ret_val != DTL_SUCCESS) /* check ret_val */
break;
CC_DISPLAY_DEC (buffer[0]); /* display buffer[0] */
buffer[0] += 1; /* keep incrementing */
if (buffer[0] == 9999) /* we are past the limit of the */
buffer[0] = 0; /* 4 digit display */
tsleep (10); /* give us time to see the display */
}
print_error (ret_val); /* oops, we got an error - print it out */
print_status (iostat); /* print status also */
exit (-3); /* get out of here */
}
print_error (err) /* process error code */
int err;
{
char *errptr;
errptr = CC_ERROR (err); /* get pointer to string */
printf (“\n Return Value = %4d - %s \n”, err, errptr); /* print it */
}
print_status (stat) /* process status code */
int stat;
{
char *errptr;
errptr = CC_ERROR (stat); /* get pointer to string */
printf (“\n Status Value = %4d - %s \n”, stat, errptr); /* print it */
}

Use CC_INIT

first and once in

every program

Advertising