SimpleReadCoilInput

SimpleReadCoilInput (FB)

FUNCTION_BLOCK SimpleReadCoilInput

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 arxValue must be considered. This is an array with 64 elements of type BOOL (1 - 64 Coils / Inputs).

The specification of the bits to be transmitted is primarily determined by the choice of the function code (eFunctionCode), the start address (wStartAddr) and the desired number of Coils / Inputs (wNumberOfCoils) in the range 1 - 64.

The actual values are available as follows:

The first element arxValue[0] contains the state of the coil with the number wStartAddress The second element arxValue[1] contains the state of the coil with the number wStartAddress + 1 The third element arxValue[2] contains the state of the coil with the number wStartAddress + 2, etc. Unused elements of arxValue are described with FALSE.

Task: Read the actual value of coil 17

Settings: eFunctionCode: ReadFunctionCodesCoilInput.FC01_ReadCoils wStartAddr = 17 wNumberOfCoils = 1

arxValue[0]: Actual value of coil 17 arxValue[1]: FALSE arxValue[2]: FALSE … arxValue[63]: FALSE

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

eFunctionCodeFb

ReadFunctionCodesCoilsInputs

Feedback - Modbus function code for the Modbus telegram

Output

wStartAddrFb

WORD

Feedback - Start address of the coils/inputs to be read

Output

wNumberOfCoilsFb

WORD

Feedback - Number of coils/inputs to be read (1 - 64)

Output

arxValue

ARRAY [0 .. 63] OF BOOL

Array with the current coil/input states

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_COIL_INPUT_ERROR_CODE

Error code - device (0 = no error)

Output

xBusy

BOOL

Communication indicator (TRUE = communication)

Input Const

wNumberOfCoils

WORD

1

Number of coils/inputs to be read (1 - 64)

Input Const

eFunctionCode

ReadFunctionCodesCoilsInputs

ReadFunctionCodesCoilsInputs.FC01_ReadCoils

Modbus function code for the Modbus telegram

Input Const

wStartAddr

WORD

Start address of the coils/inputs to be read

Input Const

tTimeUpdateActual

TIME

TIME#3s0ms

Update interval for the processes influenced by the input xUpdateActual influenced

Last updated