# SimpleReadValue

## `SimpleReadValue` (FB)

FUNCTION\_BLOCK SimpleReadValue

#### Short description

Used to read a Modbus value of different function codes as well as different data types up to 64-bit values. Addresses to be read are automatically expanded to up to 4 registers for values larger than 16 bits. Via an array the raw values can always be processed directly. 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%2Fgit-blob-b3d534af59f704829fb203974d775154255b19bb%2Fimage.png?alt=media" alt="" width="218"><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) and 02 (Read Discrete Inputs)

When evaluating the actual values, only the output 'arwRawValue' should be considered. It is an array consisting of four variables 'arwRawValue\[0]' - 'arwRawValue\[3]' of type WORD ( = 16 bit ).\
The determination of the bits to be transmitted is primarily made by the choice of the function code ( eFunctionCode ) and the start address ( wRegisterAddr ).\
The number of bits to be transmitted is defined by the choice of the expected data type ( eExpectedType ). Depending on the data type, therefore, 16, 32 or 64 consecutive bits are 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 bit )\
\
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]':\
\
'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 of communication ( TRUE = enabled )                                                                                                                            |
| Input       | `byUnitId`          | `BYTE`                           | 0                                            | Address of the device                                                                                                                                                           |
| Input       | `xUpdateActual`     | `BOOL`                           | FALSE                                        | <p>Update of actual values ( on each rising edge<br>)</p>                                                                                                                       |
| Input       | `xResError`         | `BOOL`                           | FALSE                                        | <p>Reinitialization of the outputs 'eErrorCodeCom' and/or<br>'eErrorCodeDev' to the no-error 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`                           |                                              | Feedback - scaling factor — formula: rValue = rawVal \* rScaleFactor                                                                                                            |
| 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 of the byte position swap of a<br>register ( TRUE = swap active )</p>                                                                              |
| Output      | `rValue`            | `REAL`                           |                                              | <p>Final value ( formula: rValue = rawVal \* rScaleFactor ),<br>parameters: <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>bit )</p>                                    |
| Input Const | `xSwapValue`        | `BOOL`                           | TRUE                                         | <p>Enable/disable of the byte position swap of a register ( TRUE = swap active ) ( only relevant for 32 /<br>64 bit )</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 affected by the input<br>‘xUpdateActual’</p>                                                                                               |
