MB_SetSlave block

Short summary

Name

MB_SetSlave

→POU type

→function

Category

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

Graphical interface

images/download/thumbnails/414780166/MB_SetSlave-version-1-modificationdate-1534495220648-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 sets the →Modbus slave address used for Modbus read and write functions.

Some Modbus devices can act as a gateway to other slave devices that are connected over e.g. an RS-485 serial interface. In order to read from or write to these devices, you must set the slave address by using this function. All further read and write requests will access the slave with that address. To access the Modbus gateway again, set the slave address to the default value (see below description of the input Slave).

Inputs, outputs


Identifier

→Data type

Description

Inputs:

MBHandle

DINT

the handle provided by the MB_InitTCP block (with initial value -1)

Slave

INT

the slave address

Possible range: 0 to 255 Valid slave addresses are:

  • 0: the broadcast address (reaches all slaves)
    images/s/b2ic8e/9012/1ca6q62/_/images/icons/emoticons/warning.svg Always use the slave addresse 0 with caution!

  • 1 bis 254: individual slave addresse

  • 255: default value (used to address the Modbus gateway directly)

Outputs:

RC

DINT

return code of the function call:

  • 0: call of the block succeeded

  • -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.