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

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

Update of actual values ( on each rising edge )

Input

xResError

BOOL

FALSE

Reinitialization of the outputs 'eErrorCodeCom' and/or 'eErrorCodeDev' to the no-error 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 of the byte position swap of a register ( TRUE = swap active )

Output

rValue

REAL

Final value ( formula: rValue = rawVal * rScaleFactor ), parameters: 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 bit )

Input Const

xSwapValue

BOOL

TRUE

Enable/disable of the byte position swap of a register ( TRUE = swap active ) ( only relevant for 32 / 64 bit )

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 affected by the input ‘xUpdateActual’

Last updated