Sw Function
Returns or displays the selected input port status. (i.e. Discrete User I/O)
Syntax
Sw(bitNumber)
Parameters
- bitNumber
- Specify the input bits of I/O as an integer or expression.
Return Values
Returns a 1 when the specified input is On and a 0 when the specified input is Off.
Description
Sw provides a status check for hardware inputs. Sw is most commonly used to check the status of one of the inputs which could be connected to a feeder, conveyor, gripper solenoid, or a host of other devices which works via discrete I/O. Obviously the input checked with the Sw instruction has 2 states (1 or 0). These indicate whether the device is On or Off.
See Also
In, InBCD, MemOn, MemOff, MemSw, Off, On, OpBCD, Oport, Out, Wait
Sw Function Example
The example shown below simply checks the discrete input #5 and branches accordingly. On is used instead of 1 for more clarity.
Function main
Integer i, feed5Ready
feed5Ready = Sw(5)
'Check if feeder is ready
If feed5Ready = On Then
Call mkpart1
Else
Print "Feeder #5 is not ready. Please reset and"
Print "then restart program"
EndIf
Fend
Other simple examples from the Command window are as follows:
> print sw(5)
1
>