MB_GetState block

Short summary

Name

MB_GetState

→POU type

→function

Category

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

Graphical interface

images/download/thumbnails/414780126/MB_GetState-version-1-modificationdate-1534494769105-api-v2.png

Available since

  • version 1.51.0 (for logi.CAD 3) and version 3.0.7 of the →runtime system
    images/s/b2ic8e/9012/1ca6q62/_/images/icons/emoticons/warning.svg This block is supported

    for →Raspberry Pi and
    for the platform WindowsX86 (incl. the built-in PLC under Windows).

  • version 1.109.0 (for logi.CAD 3) and version 3.19.0 of the →runtime 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 determines the state of a given →Modbus connection.

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. – Please also observe the note on the usage as it is specified for the MB_InitTCP block.

Inputs, return value


Identifier

→Data type

Description

Inputs:

MBHandle

DINT

the handle for an existing connection (with initial value -1)

Return value:

SINT

returns the current state of the given connection handle:

  • 0: invalid handle (not allocated)

  • 1: connecting (during connection attempt)

  • 2: connected

  • 3: connection failed

  • 4: connecting (before connection attempt)

  • 5: invalid handle (closing connection)

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

Internal error diagnostic for block

The block checks the following error cases: 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).

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 contains a usage of this block.