beautypg.com

BECKHOFF CX1100-000x User Manual

Page 23

background image

Product overview

Embedded PC

21

PROGRAM MAIN

VAR

Taster AT %IB0 : USINT;

END_VAR

A simple CASE statement can then be used to evaluate the switch, and the desired function can be initiated, e.g.:

CASE Taster OF

0:

ACTION := NONE;

1:

ACTION := UP;

2:

ACTION := DOWN;

4:

ACTION := LEFT;

8:

ACTION := RIGHT;

16:

ACTION := SELECT;

END_CASE;

In this case, "ACTION" is a newly defined ENUM type. It is also possible for the desired action to be activated
immediately.

The sum of the numerical values is used for the combined functions. In other words, UP (1) and RIGHT (8) would be
8 + 1 = 9. In this way, only sensible combinations are possible. In other words, switch positions that are opposite to
one another cannot be selected without damaging the switch.

If the programmer does not want to carry out the evaluation, the TwinCAT System provides a library function that
implements conversion of the switch input into an ENUM type. For this purpose, the library for the CX Systems,
TcSystemCX.lib, must be integrated into the library manager. The function is called "F_CXNaviSwitch(iCX1100_IN :
USINT)", and returns an ENUM type. This encodes the direction of the switch that has been pressed as names, for
example e_CX1100_NaviSwitch_MIDDLE for . The full list of valid possibilities is:

e_CX1100_NaviSwitch_IDLE

e_CX1100_NaviSwitch_MIDDLE

e_CX1100_NaviSwitch_TOP

e_CX1100_NaviSwitch_TOPRIGHT

e_CX1100_NaviSwitch_RIGHT

e_CX1100_NaviSwitch_BOTTOMRIGHT

e_CX1100_NaviSwitch_BOTTOM

e_CX1100_NaviSwitch_BOTTOMLEFT

e_CX1100_NaviSwitch_LEFT

e_CX1100_NaviSwitch_TOPLEFT

e_CX1100_NaviSwitch_MIDDLE_TOP

e_CX1100_NaviSwitch_MIDDLE_TOPRIGHT

e_CX1100_NaviSwitch_MIDDLE_RIGHT

e_CX1100_NaviSwitch_MIDDLE_BOTTOMRIGHT

e_CX1100_NaviSwitch_MIDDLE_BOTTOM

e_CX1100_NaviSwitch_MIDDLE_BOTTOMLEFT

e_CX1100_NaviSwitch_MIDDLE_LEFT