# SimpleReadValue

## `SimpleReadValue` (FB)

`FUNCTION_BLOCK` SimpleReadValue

#### Short description

Used to read a Modbus value of various function codes as well as various data types up to 64-bit values. The addresses to be read are automatically expanded to up to 4 registers for values larger than 16 bits. The raw values can always be processed directly via an array. As a parameter, there is the option to scale values directly.

#### Representation

<figure><img src="https://2592874069-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQR4vCFzt6ixgsqlR3pdR%2Fuploads%2Fr4hWO3tFJC8uQAQ5S90W%2FSimpleReadValue.png?alt=media&#x26;token=5b68cc72-95c7-442b-86a9-f5faa2f176cf" alt=""><figcaption></figcaption></figure>

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

### Evaluation of the actual values for function codes 01 (Read Coils) or 02 (Read Discrete Inputs)

When evaluating the actual values, only the output `arwRawValue` Note. This is an array consisting of four variables `arwRawValue[0]` - `arwRawValue[3]` of type `WORD` (= 16 bits). The specification of the bits to be transmitted is determined primarily by the choice of the function code (eFunctionCode) and the start address (wRegisterAddr). The number of bits to be transmitted is determined by the choice of the expected data type (eExpectedType). Depending on the data type, 16, 32 or 64 consecutive bits are therefore transmitted. At least 16 consecutive bits are always transmitted.

The actual values are available as follows:

16 transmitted bits: actual values in `arwRawValue[0]` 32 transmitted bits: actual values in `arwRawValue[0]` and `arwRawValue[1]` 64 transmitted bits: actual values in `arwRawValue[0]`, `arwRawValue[1]`, `arwRawValue[2]` and `arwRawValue[3]`

Task: Read the actual value of coil 17

Settings: eFunctionCode: ReadFunctionCodes.FC01\_ReadCoils wRegisterAddr = 17 eExpectedType = EXPECTED\_TYPE.TYPE\_BYTE (= 8 bits)

Due to the fact that at least 16 consecutive bits are always transmitted, the actual values of coils 17 - 32 are requested. After successful transmission, the actual values are available in the variable `arwRawValue[0]` available:

`arwRawValue[0].0`: Actual value of coil 17 `arwRawValue[0].1`: actual value of Coil 18 `arwRawValue[0].2`: actual value of Coil 19 `arwRawValue[0].3`: actual value of Coil 20 `arwRawValue[0].4`: actual value of Coil 21 `arwRawValue[0].5`: actual value of Coil 22 `arwRawValue[0].6`: actual value of Coil 23 `arwRawValue[0].7`: actual value of Coil 24 `arwRawValue[0].8`: actual value of Coil 25 `arwRawValue[0].9`: actual value of Coil 26 `arwRawValue[0].10`: actual value of Coil 27 `arwRawValue[0].11`: actual value of Coil 28 `arwRawValue[0].12`: actual value of Coil 29 `arwRawValue[0].13`: actual value of Coil 30 `arwRawValue[0].14`: actual value of Coil 31 `arwRawValue[0].15`: actual value of Coil 32

### CODESYS

InOut:

| Scope       | Name                | Type                             | Initial                                      | Comment                                                                                                                                                                      |
| ----------- | ------------------- | -------------------------------- | -------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Input       | `xEn`               | `BOOL`                           | TRUE                                         | Enable / disable communication (TRUE = enable)                                                                                                                               |
| Input       | `byUnitId`          | `BYTE`                           | 0                                            | Device address                                                                                                                                                               |
| Input       | `xUpdateActual`     | `BOOL`                           | FALSE                                        | Update of actual values (on every rising edge)                                                                                                                               |
| Input       | `xResError`         | `BOOL`                           | FALSE                                        | <p>Reinitialization of the outputs <code>eErrorCodeCom</code> or<br><code>eErrorCodeDev</code> to the error-free state (on every<br>rising edge)</p>                         |
| Inout       | `ModbusClient`      | `ModbusClientBase`               |                                              | Client of the device                                                                                                                                                         |
| Output      | `eExpectedTypeFb`   | EXPECTED\_TYPE                   |                                              | <p>Feedback - Expected data type for the received<br>Modbus data</p>                                                                                                         |
| Output      | `eFunctionCodeFb`   | ReadFunctionCodes                |                                              | Feedback - Modbus function code for the Modbus telegram                                                                                                                      |
| Output      | `wRegisterAddrFb`   | `WORD`                           |                                              | <p>Feedback - start address of the register for the Modbus-<br>telegram</p>                                                                                                  |
| Output      | `arwRawValue`       | `ARRAY` \[0 .. 3] `OF` `WORD`    |                                              | Raw values of the registers of the Modbus telegram                                                                                                                           |
| Output      | `rScaleFactorFb`    | `REAL`                           |                                              | <p>Feedback - scaling factor — formula: rValue = rawVal<br>\* rScaleFactor</p>                                                                                               |
| Output      | `xBigEndianFb`      | `BOOL`                           |                                              | <p>Feedback - position of the most significant element in a<br>datum (TRUE = lowest memory location)</p>                                                                     |
| Output      | `xSwapValueFb`      | `BOOL`                           |                                              | <p>Feedback - enable / disable swapping the positions of the<br>bytes of a register (TRUE = swap active)</p>                                                                 |
| Output      | `rValue`            | `REAL`                           |                                              | <p>Final value (formula: rValue = rawVal \* rScaleFactor),<br>parameter: <em>eExpectedType</em>, <em>xSwapValue</em>, <em>xIsBigEndian</em> and<br><em>rScaleFactor</em></p> |
| Output      | `xAlarm`            | `BOOL`                           |                                              | Collective fault (TRUE = fault)                                                                                                                                              |
| Output      | `xAlarmCom`         | `BOOL`                           |                                              | Collective fault - communication (TRUE = fault)                                                                                                                              |
| Output      | `eErrorCodeCom`     | ModbusErrorCode                  |                                              | Error code - communication (0 = no error)                                                                                                                                    |
| Output      | `eErrorCodeDev`     | SIMPLE\_READ\_VALUE\_ERROR\_CODE |                                              | Error code - device (0 = no error)                                                                                                                                           |
| Output      | `xBusy`             | `BOOL`                           |                                              | Communication indicator (TRUE = communication)                                                                                                                               |
| Input Const | `xBigEndian`        | `BOOL`                           | FALSE                                        | <p>Position of the most significant 16 bits in a datum (TRUE =<br>most significant 16 bits first) (only relevant for 32 / 64<br>bits)</p>                                    |
| Input Const | `xSwapValue`        | `BOOL`                           | TRUE                                         | <p>Enable / disable swapping the positions of the bytes of a<br>register (TRUE = swap active) (only relevant for 32 /<br>64 bits)</p>                                        |
| Input Const | `rScaleFactor`      | `REAL`                           | 1.0                                          | Scaling factor — formula: rValue = rawVal \* rScaleFactor                                                                                                                    |
| Input Const | `eExpectedType`     | EXPECTED\_TYPE                   | EXPECTED\_TYPE.TYPE\_UINT16                  | Expected data type for the received Modbus data                                                                                                                              |
| Input Const | `eFunctionCode`     | ReadFunctionCodes                | ReadFunctionCodes.FC03\_ReadHoldingRegisters | Modbus function code for the Modbus telegram                                                                                                                                 |
| Input Const | `wRegisterAddr`     | `WORD`                           |                                              | Start address of the register for the Modbus telegram                                                                                                                        |
| Input Const | `tTimeUpdateActual` | `TIME`                           | TIME#3s0ms                                   | <p>Update interval for the processes influenced by the input<br><code>xUpdateActual</code> influenced</p>                                                                    |
