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

Chapter 6
Discrete I/O
6-2
Subscript Calculation
The image tables are tables of words, where each 16-bit word corresponds
to the 16 terminals of a module group. Terminal 17 octal (15 decimal)
corresponds to bit 017 (15 decimal) of the word, and so on down to
terminal 0 and bit 0. (16 bits times 64 words gives 1024 output terminals
and 1024 input terminals. Though possible, it is very unlikely that any
given application would use all I/O points.)
To address a particular module group in either the output or the input
image table, the subscript is 8 times the rack plus the group. For instance,
if you wanted to return the 16-bit contents of rack 2, group 7 from the
input image table, you could code it this way:
value = g_ipt[8*2+7];
Single Terminal
To access a single input terminal, you need to shift the word value and
AND a 1 to mask off the other bits. Remember to specify terminal
numbers in decimal, or use a leading zero if you’re specifying terminal
numbers in octal.
Example: to obtain the value of terminal 12 octal (10 decimal) from rack 3,
group 5, either of these statements works:
bit = g_ipt[8*3+5]>>012 & 1; or
bit = (g_ipt[8*3+5]>>10) & 1;
The first statement as coded depends on the C language’s operator priority:
shifts are done before ANDs. You may feel more comfortable adding
parentheses to emphasize the order of operations, as we did in the second
statement.
If you’re simply going to use a terminal value in an if test, you can shift it
as we did above, or you can use a one bit mask like this:
if ( g_ipt[8*3+5] & (1<<012) ) . . .
This doesn’t look much better than the previous construct, but if you define
symbolic constants (as we recommend) the code becomes clearer:
#define SENS_RACK 3 . . . if ( g_ipt[8*SENS_RACK+SENS_GRP] & SENS_MASK ) . . .
#define SENS_GRP 5
#define SENS_BIT 012
#define SENS_MASK (1<