Skip to main content

Function Block: ModbusRequest

Library: IoDrvModbusTCP

In addition to the predefined Modbus commands defined in the tab Modbus Server Channel, this function block allows to execute dynamically additional commands in the application. For this programmatically created commands CODESYS does not provide an I/O mapping but input/output data ranges of type ARRAY OF BYTE or ARRAY OF WORD.

Table 13. Inputs (VAR_INPUT)

Name

Data Type

Initial Value

Description

Slave

ModbusTCPSlave

xExecute

BOOL

Rising edge: The action starts.

Falling edge: The outputs are reset when a falling edge occurs before the function block has ended the action. The outputs behave as usual and are reset only if the action is ended or has been aborted (xAbort), or if an error has occurred. In this case, the corresponding output values (xDone, xError, iError) exist at the outputs for exactly one cycle.

xAbort

BOOL

TRUE: The action is aborted immediately and all outputs are set to their initial values.

usiUnitID

UINT

16#FF

The unit ID is only used for forwarding (gateway) to a Modbus Serial Bus.

For TCP/IP, the MODBUS-Server is addressed by means of the IP address. In this case, the MODBUS unit ID is not used (the value 0xFF has to be used).

For a serial connection, the Modbus devices are addressed with unit IDs from 1 to 247 (0 is used for broadcast addresses).

ModbusCommand

ModbusCommand

The Modbus command to be executed. Function blocks for bit and word access are supported.

pSendData

POINTER TO BYTE

Pointer to a buffer with data which is sent to the server.

For register access, the buffer is of type Array[0..ModbusCommand.uiWriteLen - 1] OF WORD. For bit access, the buffer is of type ARRAY[0..ModbusCommand.uiWriteLen / 8] OF BYTE.

pRecvData

POINTER TO BYTE

Pointer to a buffer where the data which has been received by the server is written.

For register access, the buffer is of type ARRAY[0..ModbusCommand.uiReadLen - 1] OF WORD. For bit access, the buffer is of type ARRAY[0..ModbusCommand.uiReadLen / 8] OF BYTE.



Table 14. Outputs (VAR_OUTPUT)

Name

Data Type

Initial Value

Description

xDone

BOOL

FALSE

TRUE when a request has been ended successfully

xBusy

BOOL

FALSE

TRUE as long as the request is being processed

xError

BOOL

FALSE

TRUE when a request has been ended with errors

xAborted

BOOL

FALSE

TRUE when the request has been aborted by the user

ModbusError

MB_ErrorCodes

Current error; defined in the MB_ErrorCodes enumeration.