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

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

Reinitialization of the outputs eErrorCodeCom or eErrorCodeDev to the error-free state (on every rising edge)

Inout

ModbusClient

ModbusClientBase

Client of the device

Output

eExpectedTypeFb

EXPECTED_TYPE

Feedback - Expected data type for the received Modbus data

Output

eFunctionCodeFb

ReadFunctionCodes

Feedback - Modbus function code for the Modbus telegram

Output

wRegisterAddrFb

WORD

Feedback - start address of the register for the Modbus- telegram

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

Feedback - position of the most significant element in a datum (TRUE = lowest memory location)

Output

xSwapValueFb

BOOL

Feedback - enable / disable swapping the positions of the bytes of a register (TRUE = swap active)

Output

rValue

REAL

Final value (formula: rValue = rawVal * rScaleFactor), parameter: eExpectedType, xSwapValue, xIsBigEndian and rScaleFactor

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

Position of the most significant 16 bits in a datum (TRUE = most significant 16 bits first) (only relevant for 32 / 64 bits)

Input Const

xSwapValue

BOOL

TRUE

Enable / disable swapping the positions of the bytes of a register (TRUE = swap active) (only relevant for 32 / 64 bits)

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

Update interval for the processes influenced by the input xUpdateActual influenced

Last updated