Rockwell Automation 6008-SI IBM PC I/O SCNNR 6008-SI User Manual
Page 58

Chapter 6
Discrete I/O
6-3
To set a single output terminal, you simply OR a 1 bit in the appropriate
position within the output image table word. Here’s an example, for
terminal 3 of rack 0, group 7:
g_oit[88*0+7] |=1<<3;
The next time the scanner scans that rack, the new value is transferred to
the scanner’s output image table and, the time after that, the value goes on
the I/O link to the module.
To reset (clear) a terminal is a little trickier: you have to AND a mask that
contains 1 bits everywhere except in the bit position of the terminal to be
cleared. The C language operator ~ is made for this kind of operation:
g_oit[8*0+7] &= ~(1<<3);
Access by Byte
If you need to access one slot within a module group, say to reset all eight
terminals in a single operation, you have two ways to do it. You could use
a cast operator to access the image table as an array of 128 character
values, or you could use the masking technique shown above.
Example: to clear slot 12 (the left hand slot of group 6) of rack 2, you can
do either
g_oit[8*2+6] &= 0xFF00; or
*((char *)g_oit + 16*2+12) = 0;
Notice in the first example that the low byte of a constant occurs at the
right, even though the low slot is physically at the left in the chassis. (The
bytes within a word are stored with the low byte at the lower address,
backward from the way the numbers occur in computations.) In the second
example, notice that we have 16 bytes rather than 8 words per rack.
Programming Hint
We suggest that you define constants for the addresses of your I/O
modules. This makes your programs easier to understand, and helps you in
debugging. For example:
#define ALARM_RACK 5
#define ALARM_GRP 0
#define ALARM_TERM 017
. . .
g_oit[8*ALARM_RACK+ALARM_GRP] |= 1<