# LGF_TimerSwitch (FB / V3.0.1)

Author: Siemens Digital Industry

## Short description

This block is a timer. It is possible to define daily, weekly, monthly, yearly time switch points and time switch points for working days or weekend days.
Mode: Daily: 1, weekly: 2, monthly: 3, yearly: 4, workday: 5, weekend: 6

The time value is always compared with the local time of the PLC, therefore the time value specified at the On and Off parameters must be specified as local time.

### Block Interface

| LGF_TimerSwitch (FB) |
--- | --- | ---
USInt |  |  | onMonth |  | signal |  |  | Bool
USInt |  |  | onDay |  | actLocalTime |  |  | DTL
USInt |  |  | onWeekday |  | error |  |  | Bool
USInt |  |  | onHour |  | status |  |  | Word
USInt |  |  | onMinute |  | subFunctionStatus |  |  | Word
USInt |  |  | offMonth |  |  |  |  |
USInt |  |  | offDay |  |  |  |  |
USInt |  |  | offWeekday |  |  |  |  |
USInt |  |  | offHour |  |  |  |  |
USInt |  |  | offMinute |  |  |  |  |
USInt |  |  | mode |  |  |  |  |

### Input parameter

Identifier | Data type | Default value | Description
--- | --- | --- | ---
onMonth | USInt | 0 | Month, in which the signal shall be set.
onDay | USInt | 0 | Day, at which the signal shall be set.
onWeekday | USInt | 0 | Day of the week on which the signal will be set; Sunday: 1, Monday: 2, Tuesday: 3, ...
onHour | USInt | 0 | Hour, at which the signal shall be set.
onMinute | USInt | 0 | Minute, at which the signal shall be set.
offMonth | USInt | 0 | Month, in which the signal shall be reset.
offDay | USInt | 0 | Day, at which the signal shall be reset.
offWeekday | USInt | 0 | Day of the week on which the signal will be reset; Sunday: 1, Monday: 2, Tuesday: 3, ...
offHour | USInt | 0 | Hour, at which the signal shall be reset.
offMinute | USInt | 0 | Minute, at which the signal shall be reset.
mode | USInt | 0 | Specifies the mode (see Principle of operation); Daily: 1, weekly: 2, monthly: 3, yearly: 4, workday: 5, weekend: 6

### Output parameter

Identifier | Data type | Description
--- | --- | ---
signal | Bool | Output signal
actLocalTime | DTL | Current local time
error | Bool | FALSE: No error / TRUE: An error occurred during the execution of the FB
status | Word | 16#0000-16#7FFF: Status of the FB / 16#8000-16#FFFF: Error identification (see following Table)
subFunctionStatus | Word | Sub function status code

### Status & Error codes

Code / Value | Identifier / Description
--- | ---
16#0000 | STATUS_NO_ERROR Status: no error occurred
16#8200 | ERR_NO_MODE_SELECTED Error: No suitable mode is selected, check input "mode"
16#8600 | ERR_RD_LOC_T Error in function RD_LOC_T, see in `subFunctionStatus`

## Functional description

NOTE
  The status of called commands is output in `subFunctionStatus`. In this case, the output value in `status` indicates which command caused the error. In this case, refer to the TIA Portal Online Help section for information on the respective commands.

The block offers various timer types, which are determined in the `mode` parameter:

- Daily timer (mode = 1)
- Weekly timer (mode = 2)
- Monthly timer (mode = 3)
- Yearly timer (mode = 4)
- Weekdays, Monday to Friday (mode = 5)
- Weekend, Saturday and Sunday (mode = 6)

The time value is always compared with the local time of the PLC, therefore the time value specified at the On and Off parameters must be specified as local time.

Depending on the mode, the following formal parameters must be interconnected:

Mode | Mode | Required formal parameters
--- | --- | ---
1 . | Daily timer | onHour / offHour onMinute / offMinute
2 . | Weekly timer | onWeekday / offWeekday onHour / offHour onMinute / offMinute
3 . | Monthly timer | onDay / offDay onHour / offHour onMinute / offMinute
4 . | Yearly timer | onMonth / offMonth onDay / offDay onHour / offHour onMinute / offMinute
5 . | Weekdays | onHour / offHour onMinute / offMinute
6 . | Weekend | onHour / offHour onMinute / offMinute

If the set start time equals the current local time of the controller, the output `signal` is set to `TRUE`. If the set switch-off time equals the current local time of the controller, the `signal` output is reset again.

NOTE
  Please note that the block can be used in the “Monthly timer” modes (mode = 3) or “yearly timer” (mode = 4) the block only switches if the days that you specify at the input parameters, “onDay” and “offDay”, actually occur in this month.

## Change log

Version & Date | Change description
--- | ---
| 01.00.00 | Siemens Industry Online Support
| 19.08.2015 | First released version
| 01.00.01 | Siemens Industry Online Support
| 16.11.2015 | Fix in mode 2
| 01.01.00 | Siemens Industry Online Support
| 23.05.2016 | New mode 5 + 6 New output: actLocalTime
| 01.01.01 | Siemens Industry Online Support
| 02.01.2017 | Upgrade: TIA V14 Update 1
| 01.01.02 | Siemens Industry Online Support
| 14.09.2018 | Fix in modes 1, 3, 5, 6
| 01.01.03 | Siemens Industry Online Support
| 17.09.2018 | Upgrade: TIA V15 Update 2
| 01.01.04 | Siemens Industry Online Support
| 10.10.2018 | Connection to type restored
| 01.01.05 | Siemens Industry Online Support
| 23.11.2018 | Upgrade: TIA V15.1
| 01.01.10 | Simatic Systems Support
| 13.11.2019 | Magic numbers removed, tag naming added, code reworked
| 03.00.00 | Simatic Systems Support
| 23.04.2020 | Set version to V3.0.0, harmonize the version of the whole library
| 03.00.01 | Simatic Systems Support
| 19.01.2020 | Insert documentation