# LGF_TimerSwitch (FB / 3.1.0)

Overview

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: Permanently off: 0, Daily: 1, Weekly: 2, Monthly: 3, Yearly: 4, Workday: 5, Weekend: 6, Permanently on: 10

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); Permanently off: 0, Daily: 1, Weekly: 2, Monthly: 3, Yearly: 4, Workday: 5, Weekend: 6, Permanently on: 10

### 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.

NOTE
  The function uses internally the system function `RD_LOC_T` to read the local time of the CPU, for the correct function it is therefore necessary that the local time of the CPU is set correctly.

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

- Permanently off (mode = 0)
- 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)
- Permanently on (mode = 10)

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
--- | --- | ---
0 . | Permanently OFF | none
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
10 . | Permanently ON | none

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
--- | ---
| 1.0.0 | Siemens Industry Online Support
| 19.08.2015 | First released version
| 1.0.1 | Siemens Industry Online Support
| 16.11.2015 | Fix in mode 2
| 1.1.0 | Siemens Industry Online Support
| 23.05.2016 | New mode 5 + 6 New output: actLocalTime
| 1.1.1 | Siemens Industry Online Support
| 02.01.2017 | Upgrade: TIA V14 Update 1
| 1.1.2 | Siemens Industry Online Support
| 14.09.2018 | Fix in modes 1, 3, 5, 6
| 1.1.3 | Siemens Industry Online Support
| 17.09.2018 | Upgrade: TIA V15 Update 2
| 1.1.4 | Siemens Industry Online Support
| 10.10.2018 | Connection to type restored
| 1.1.5 | Siemens Industry Online Support
| 23.11.2018 | Upgrade: TIA V15.1
| 1.1.10 | Simatic Systems Support
| 13.11.2019 | Magic numbers removed, tag naming added, code reworked
| 3.0.0 | Simatic Systems Support
| 23.04.2020 | Set version to V3.0.0, harmonize the version of the whole library
| 3.0.1 | Simatic Systems Support
| 19.01.2020 | Insert documentation
| 3.1.0 | Simatic Systems Support
| 03.06.2022 | Insert mode `permanently On`: `10`, `permanently Off`: `0`