MB_InitTCP block
Short summary
Name |
MB_InitTCP |
→POU type |
|
Category |
more system blocks, blocks for Modbus, block with internal error diagnostic |
Graphical interface |
|
Available since |
|
Functionality
The block initializes a →Modbus/TCP connection and returns a handle which is used with other Modbus blocks to communicate with a Modbus TCP 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 |
Description |
|
Inputs: |
IPAddress |
STRING |
IP address of the Modbus TCP bus coupler |
Port |
DINT |
Modbus port of the Modbus TCP bus coupler (with initial value 502) |
|
TimeoutRW |
TIME |
timeout for reading/writing calls of the Modbus blocks (with initial value T#50ms) |
|
Outputs: |
MBHandle |
DINT |
a handle which identifies the connection (with initial value -1) |
RC |
DINT |
return code of the function call:
|
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:
"Blocks for safe logic" whether this block is supported for developing safety-relevant applications.
"Highlighting safe logic in the FBD-editor" for the effects when using the block as a block for safe logic .
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 contains a usage of this block.