# OperatingHours

## `OperatingHours` (FB)

FUNCTION\_BLOCK OperatingHours

### Short description

> Counter for operating hours and switch-on operations

### Representation

<figure><img src="https://2592874069-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQR4vCFzt6ixgsqlR3pdR%2Fuploads%2Fgit-blob-fc70544db93771714913ba3d49542e3b95b0df0c%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

### Interfaces

#### Inputs

| Name     | Data type | Value range | Initial value | Function               |
| -------- | --------- | ----------- | ------------- | ---------------------- |
| *xFb*    | BOOL      |             |               | Counter - input        |
| *xReset* | BOOL      |             | FALSE         | Enable - input - reset |

#### Outputs

| Name                | Data type       | Value range | Initial value | Function                                          |
| ------------------- | --------------- | ----------- | ------------- | ------------------------------------------------- |
| *udiOperatingHours* | UDINT           |             |               | Counter - output - operating hours                |
| *udiCountFb*        | UDINT           |             |               | Counter - output - switch-ons                     |
| *dtLastFb*          | DATE\_AND\_TIME |             |               | Date/time of the end of the last counting process |

### Function description

#### General

This function block is used to record the operating hours and switch-on operations at the counter input *xFb*.\
The outputs *udiOperatingHours* and *udiCountFb* are reset to 0 as soon as a rising edge is detected at the input *xReset* A rising edge is detected.\
The counting process is active as long as the state TRUE is present at the counter input *xFb* the state TRUE is present.\
The output *udiOperatingHours* shows the cumulative duration of the counting processes since the last reset in hours.\
The output *udiCountFb* is incremented with each rising edge at the input *xFb* is incremented.\
\
At the output *dtLastFb* the current date/time is available during the counting process.\
At the output *dtLastFb* the date/time at the end of the last counting process is available outside the counting process.\
At the output *dtLastFb* the initialization value DT#1970-1-1-0.0.0 is output before the first counting process.\\

> **Valid counter values are within the limits 0 and 4294967295.**\
> **Incrementing the counter value 4294967295 resets the counter value to 0.**\
> **Subsequently the counter value is continuously incremented again.\&#x20;*****udiOperatingHours*****&#x20;and&#x20;*****udiCountFb***
>
> Reduction factor udiEnergyFactor
>
> **Prerequisite for using the OperatingHours function block**
>
> The use of the TimeRead2 function block is required for correct operation.
>
> **Write access to the counter values**
>
> Via the path ‘InstanceName.\_OperatingHours.udiOperatingHours’ or ‘InstanceName.\_OperatingHours.udiCountFb’, write access to both counter values is possible.\\

### CODESYS

InOut:

| Scope  | Name                | Type    | Initial |
| ------ | ------------------- | ------- | ------- |
| Input  | `xFb`               | `BOOL`  |         |
| Input  | `xReset`            | `BOOL`  | FALSE   |
| Output | `udiOperatingHours` | `UDINT` |         |
| Output | `udiCountFb`        | `UDINT` |         |
| Output | `dtLastFb`          | `DT`    |         |

Methods:

> mReset

Structure:

* mReset (Method)
