MB_InitRTU block

Short summary

Name

MB_InitRTU

→POU type

→function

Category

more system blocks, blocks for Modbus, block with internal error diagnostic

Graphical interface

images/download/thumbnails/414780131/MB_InitRTU-version-1-modificationdate-1534494786113-api-v2.png

Available since

version 2.0.9 (for library System)
images/s/b2ic8e/9012/1ca6q62/_/images/icons/emoticons/warning.svg This block is supported

for Raspberry Pi as well as
for the platforms WindowsX86 (incl. the built-in PLC under Windows) and LinuxX86.

Functionality

The block initializes a →Modbus/RTU connection and returns a handle which is used with other Modbus blocks to communicate with a Modbus RTU bus coupler.

Note on the usage

In order to determine the state of a Modbus connection, use this block always together with the block MB_GetState . This is for the following reasons:

  • The connection has not been established yet, when logi.CAD 3 returns from the block.

  • Usually, it is possible to use the connection for the actual communication only within the next cycle of the application.

Hence, this is valid : It is imperative that you are using MB_GetState in order to determine the state of a Modbus connection within each cycle of the application. Make sure that the application contains the required steps depending on the return code of MB_GetState. Do not use internal variables within the application for determining the state of a connection.

Inputs, outputs


Identifier

→Data type

Description

Inputs:

Device

STRING

device name of the Modbus RTU bus coupler

Baud

DINT

transmission speed for this connection (with initial value 115200)

Parity

MB_PARITY

usage of an error detecting bit for this connection as specified in data type MB_PARITY

DataBit

DINT

number of data bits for this connection (with initial value 8)

StopBit

DINT

number of stop bits for this connection (with initial value 1)

TimeoutRW

TIME

timeout for read/write function calls (with initial value T#500ms)

Outputs:

MBHandle

DINT

a handle which identifies the connectiont (with initial value -1)

RC

DINT

return code of the function call:

  • 0: call of the block succeeded
    images/s/b2ic8e/9012/1ca6q62/_/images/icons/emoticons/information.svg This return code does not represent any information that the Modbus connection has successfully been established. See the above note on usage of this block .

  • -1: The resources necessary to establish the connection (e.g. memory) are not available.

  • -2: The requested function of the Modbus stack could not be executed.

  • -3: The forwarded handle is not valid (anymore).

  • -5: There are no more handles to establish the connection (up to 256 connections can be established at present).

  • -6: An internal problem of the Modbus connection occurred.

  • -7: The LibModbus system service has not been loaded and/or you have no permissions to use Modbus (no enabled feature in the license for the →runtime system ).

Input EN and output ENO are available when →calling the block. See "Execution control: EN, ENO" for information on input EN and output ENO.

See:

Internal error diagnostic for block

The block checks the following error cases (if applicable for the block):

  • The resources necessary to establish the connection (e.g. memory) are not available.

  • The requested function of the Modbus stack could not be executed.

  • The forwarded handle is not valid (anymore).

  • The requested amount of data cannot be processed by the Modbus connection.

  • There are no more handles to establish the connection (up to 256 connections can be established at present).

  • An internal problem of the Modbus connection occurred.

  • The LibModbus system service has not been loaded and/or you have no permissions to use Modbus (no enabled feature in the license for the →runtime system).

In such an error case, the output ENO of the block is set to value FALSE (or an equivalent). Moreover, the output RC returns the appropriate code (see the above table under RC).

Example for usage within ST-editor

Best practice in order to get to know the usage of the Modbus blocks: Create a new project based on the project template Moving Light with Modbus Access and study this sample project. This project does not contain a usage of this block but of other blocks. Please study those in order to get to know how to use this block.