Rockwell Automation 1771-DMC_DMC1_DMC4_DXPS Control Coprocessor User Manual User Manual

Page 105

Advertising
background image

Chapter 6

Using the Ethernet Interface

6-24

#include <copro.h>

typedef struct

{

unsigned make;

char model;

char type;

char color;

unsigned year;

}CAR;

main(){

unsigned id; /* id for tag definition */

CAR car; /* car structure pointed to by tag */

CC_INIT(); /* init the coprocessor */

TAG_DEFINE (&id,&car,”Car”,sizeof(car),TG_MODIFY); /* define the tag */

car.make = car.model = car.type = car.color = car.year = 0; /* init data */

while (1) {

TAG_LOCK (id,CC_FOREVER); /* prevent concurrent access on tagged data */

car.make += 1; /* increment make */

car.model += 2; /* and model */

car.type += 3; /* an year */

TAG_UNLOCK (id,CC_FOREVER); /* allow access to tag */

sleep (1);} /* sleep for 1 second */

}

The INTERCHANGE host program does the following:

1.

reads and displays the entire Car TAG

2.

writes a 0x99 to only the color element of the Car TAG

3.

reads and displays the entire Car TAG

4.

writes a 0x88 to the color element and increments the year element of
the Car TAG

5.

reads and displays the entire Car TAG

Note that the display routine takes the 4 bytes of the unsigned variables
and places them in a temporary union variable before storing them.
This—or another similar method—is necessary when the host requires that
data larger than a byte be on even-address boundaries but the data for those
variables in the byte stream are on odd-address boundaries.

Advertising