In Function

Returns the status of the specified Byte port. Each port contains 8 input channels.

Syntax
In(byteportNumber)

Parameters

byteportNumber
Specifies the I/O byte port.

Return Values
Integer between 0 and 255. The return value is 8 bits, with each bit corresponding to 1 input channel.

Description
In provides the ability to look at the value of 8 input channels at the same time. The In instruction can be used to store the 8 I/O channels status into a variable or it can be used with the Wait instruction to Wait until a specific condition which involves more than 1 I/O channel is met.

Since 8 channels are checked at a time, the return values range from 0 to 255. Please review the chart below to see how the integer return values correspond to individual input channels.

Input Channel Result (Using Byte port #0)

Return Values 7 6 5 4 3 2 1 0
1 Off Off Off Off Off Off Off On
5 Off Off Off Off Off On Off On
15 Off Off Off Off On On On On
255 On On On On On On On On

Input Channel Result (Using Byte port #2)

Return Values 23 22 21 20 19 18 17 16
3 Off Off Off Off Off Off On On
7 Off Off Off Off Off On On On
32 Off Off On Off Off Off Off Off
255 On On On On On On On On

See Also
InBCD, MemIn, MemOff, MemOn, MemSw, Off, On, OpBCD, Oport, Out, Sw, Wait

In Function Example
For the example below let’s assume that input channels 20, 21, 22, and 23 are all connected to sensory devices such that the application should not start until each of these devices are returning an On signal indicating everything is OK to start. The program example gets the 8 input channels status of byte port 2 and makes sure that channels 20, 21, 22, and 23 are each On before proceeding. If they are not On (i.e. returning a value of 1) an error message is given to the operator and the task is stopped.

In the program, the variable “var1” is compared against the number 239 because in order for inputs 20, 21, 22, and 23 to all be On, then the result of In(2) will be 240 or larger. (We don’t care about Inputs 16, 17, 18, and 19 in this case so any values between 240-255 will allow the program to proceed.)

Function main
    Integer var1
    var1 = In(2)   'Get 8 input channels status of byte port 2
    If var1 > 239 Then
        Go P1
        Go P2
        'Execute other motion statements here
        '.
        '.
    Else
        Print "Error in initialization!"
        Print "Sensory Inputs not ready for cycle start"
        Print "Please check inputs 20,21,22, and 23 for"
        Print "proper state for cycle start and then"
        Print "start program again"
    EndIf
Fend

We cannot set inputs from the command window but we can check them. For the examples shown below, we will assume that the Input channels 1, 5, and 15 are On. All other inputs are Off.

> print In(0)
34
> print In(1)
128
> print In(2)
0