Invalid definition example, C example, Basic example – Rockwell Automation 1771-DMC_DMC1_DMC4_DXPS Control Coprocessor User Manual User Manual

Page 206: References

Advertising
background image

API Library of Routines

Appendix B

DTL_RMW_W_IDX

B-75

Invalid Definition Example

DTL_C_DEFINE (&idl, “N34:3”)

/* not specified to element 0 */

DTL_C_DEFINE (&idl, “N34:0,3,long”) /* number of items not 1 */

C Example

/*

* Suppose there are 5 16-bit “status words” in binary file 10, elements

* 0 through 4, each describing the current status of 5 machines. Bits

* 0 through 3 of each word contain a code for the “current mode” (0-F)

* of the machine. This example changes the “current mode” to a value

* of 2 without modifying bits 5-31 for machines 0 and 4.

*/

#define MODE_AND_MASK 0xFFF0 /* preserve bits 5-31 */

#define MODE_OR_MASK 0x0002 /* set bit 1*/

#define MAC_0 0x0000 /* machine 0 index */

#define MAC_2 0x0004 /* machine 4 index */

unsigned id;

unsigned iostat;

DTL_C_DEFINE (&id, “B10:0, 1, WORD, MODIFY”);

DTL_RMW_W_IDX (id, MODE_AND_MASK, MODE_OR_MASK, &iostat, MAC_0);

DTL_RMW_W_IDX (id, MODE_AND_MASK, MODE_OR_MASK, &iostat, MAC_4);

BASIC Example

The BASIC function code is 22.

procedure COPRO

DIM status : INTEGER

DIM id : INTEGER

DIM iostat : INTEGER

DIM and_mask : INTEGER

DIM or_mask : INTEGER

rem * Define the data file

RUN AB_BAS (2, status, ADDR(id), “B10;), 1, LONG, MODIFY”)

and_mask := $FFF0

or_mask := $2

RUN AB_BAS (22, status, id, and_mask, or_mask, ADDR(iostat), 0))

RUN AB_BAS (22, status, id, and_mask, or_mask, ADDR(iostat), 4))

References

DTL_C_DEFINE(); DTL_READ_W_IDX();
DTL_WRITE_W_IDX();

Advertising