Rockwell-automation 1771-DMC_DMC1_DMC4_DXPS Control Coprocessor User M Manual de usuario Pagina 105

  • Descarga
  • Añadir a mis manuales
  • Imprimir
  • Pagina
    / 312
  • Tabla de contenidos
  • MARCADORES
  • Valorado. / 5. Basado en revisión del cliente
Vista de pagina 104


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.
Vista de pagina 104
1 2 ... 100 101 102 103 104 105 106 107 108 109 110 ... 311 312

Comentarios a estos manuales

Sin comentarios