beautypg.com

Library routines – Rockwell Automation 6008-SI IBM PC I/O SCNNR 6008-SI User Manual

Page 59

background image

Chapter 6

Discrete I/O

6-4

Let’s look at this example. We defined the rack and group of the module
that controls an alarm, and the specific terminal (note the leading zero for
octal notation). To turn on an output terminal, we shifted a 1 bit left by the
terminal number and ORed that into the output image table.

By the way, you may be wondering about efficiency. Most C compilers do
all arithmetic on constants at compile time. So at run time there would be
no difference in execution speed between the above statement and

g_oit[40] |= 0x8000;

but the first way is certainly easier to understand and maintain.

We provide you with several library routines and macros to access the I/O
image tables. Execution is not as efficient as with the direct addressing
techniques in the previous section, but the difference should be negligible
in most applications compared to the time for transferring data across the
link.

getbit

Use this routine to get a bit from the input or output image table.

Calling sequence:

value = getbit(

inout, rack, group, bit

);

Arguments:

inout:

the constant IN (1) for input image or OUT (0) for output

image.

rack:

an integer 0 to 7, the logical rack number.

group:

an integer 0 to 7, the module group number.

bit:

an integer 0 to 15 (octal 0 to 017), the bit or terminal number.

Returned values:

an integer, the value of the bit, 1 or 0.

Example:

sens_bit = getbit(SENS_RACK, SENS_GRP, SENS_BIT);

obtains an on or off value from the sensor, assuming that you have
defined the symbolic constants in your program.

Library Routines