# TwoPointFun

## `TwoPointFun` (FUN)

FUNCTION TwoPointFun : INT

### Short description

> Linear conversion of a numeric input value using a characteristic curve defined by two points.\
> \
> Typical application: Scaling of raw process values\\

### Interfaces

#### Inputs

| Name            | Data type | Value range | Initial value | Function                                                 |
| --------------- | --------- | ----------- | ------------- | -------------------------------------------------------- |
| *rIn\_X*        | REAL      |             |               | Analog value input                                       |
| *rX1*           | REAL      |             | 0             | Point 1 of the input range                               |
| *rY1*           | REAL      |             | 0             | Point 1 of the output characteristic                     |
| *rX2*           | REAL      |             | 100           | Point 2 of the input range                               |
| *rY2*           | REAL      |             | 100           | Point 2 of the output characteristic                     |
| *xMinMaxLimit*  | BOOL      |             |               | Enable / disable the limiting on the analog value output |
| *iMinMaxOffset* | INTEGER   |             |               | Values of the limits on the analog value output          |

#### Outputs

| Name          | Data type | Value range | Initial value | Function                                                                                                                   |
| ------------- | --------- | ----------- | ------------- | -------------------------------------------------------------------------------------------------------------------------- |
| *TwoPointFun* | REAL      |             |               | Linear conversion of a numerical input value                                                                               |
| *xErr*        | BOOL      |             |               | <p>\* <strong>FALSE:</strong><br>Conversion error-free<br>\* <strong>TRUE:</strong><br>Error in the conversion process</p> |

### Function description

#### Analog value output

The analog value output is from the analog value input *rIn\_X* calculated depending on the linear characteristic defined by the two points P1(*rX1*/*rY1*) and P2(*rX2*/*rY2*).\
In case of a conversion error ( *xErr* = TRUE ) the analog value output remains unchanged.\\

> **Formula**
>
> rOut\_Y = (((rX1-rIn\_X)\*(rY2-rY1))/(rX1-rX2))+rY1\\
>
> **Limitations**
>
> The analog value output is of data type REAL. By an unsuitable selection of the parameters *rX1*, *rX2*, *rY1* and *rY2* as well as of the value of the analog value input *rIn\_X* it can lead to exceeding the bounds of the data type.\\

#### Enable / disable limits *xMinMaxLimit*

The limits of the analog value output can generally be enabled and disabled with this input.\\

| *xMinMaxLimit* | Limits            | Notes                                       |
| -------------- | ----------------- | ------------------------------------------- |
| FALSE          | none              | Analog value output without absolute limits |
| TRUE           | Y\_min and Y\_max | Limit of the analog value output active     |

#### Values of the limits *iMinMaxOffset*

The limits of the analog value output are only active if the input *xMinMaxLimit* is active ( = TRUE ).\
The limit values Y\_min and Y\_max are then calculated as follows:\\

> **Formulas**
>
> > Y\_min = rY1 - ((ABS(rY2-rY1))\*iMinMaxOffset)/100\
> > Y\_max = rY2 + ((ABS(rY2-rY1))\*iMinMaxOffset)/100\\

| *rY1* | *rY2* | *rY2* - *rY1* | *iMinMaxOffset* | *Y\_min* | *Y\_max* | Notes           |
| ----- | ----- | ------------- | --------------- | -------- | -------- | --------------- |
| 0     | 100   | 100           | 0               | 0        | 100      | Default limits  |
| 0     | 100   | 100           | 10              | -10      | 110      | Positive offset |
| 0     | 100   | 100           | -10             | 10       | 90       | Negative offset |

#### Digital output *xErr*

The digital output *xErr* signals an error in the conversion process. The following errors are taken into account:\
\\

* *rX1* AND *rX2* = 0
* *rX1* = *rX2*
* *rY1* AND *rY2* = 0
* *rY1* = *rY2*

| Error in the conversion process | *xErr* | Notes                           |
| ------------------------------- | ------ | ------------------------------- |
| FALSE                           | FALSE  | Conversion error-free           |
| TRUE                            | TRUE   | Error in the conversion process |

Legend: X = any

### Codesys

InOut:

| Scope  | Name            | Type   | Initial | Comment                                                                                             |
| ------ | --------------- | ------ | ------- | --------------------------------------------------------------------------------------------------- |
| Return | `TwoPointFun`   | `INT`  |         |                                                                                                     |
| Input  | `iIn_X`         | `INT`  |         | Analog value input                                                                                  |
| Input  | `iX1`           | `INT`  | 0       | Point 1 of the input range                                                                          |
| Input  | `iX2`           | `INT`  | 100     | Point 2 of the input range                                                                          |
| Input  | `iY1`           | `INT`  | 0       | Point 1 of the output characteristic                                                                |
| Input  | `iY2`           | `INT`  | 100     | Point 2 of the output characteristic                                                                |
| Input  | `xMinMaxLimit`  | `BOOL` |         | Enable / disable the limiting on the analog value output                                            |
| Input  | `iMinMaxOffset` | `INT`  |         | Values of the limits on the analog value output                                                     |
| Output | `xErr`          | `BOOL` |         | <p>FALSE: Conversion without error<br><br><br>TRUE: Error during the conversion process<br><br></p> |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://support.powerio.com/hub/codesys-hvac/en/hvac-knx-library/funktionen/twopointfun.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
