
The screenshot below details all of the parameters of the TCON_IP_v4 structure. I'm going to use the TCON_IP_v4 structure, but you can learn more about the TCON_Configured set up in the block documentation (which can be accessed by pressing `F1` on your keyboard while the MB_CLIENT block is highlighted in TIA Portal). TCON_Configured uses a connection already set up by the PLC (by downloading the hardware configuration with your server connection in it). TCON_IP_v4 allows you to define the exact connection parameters in this variable, and the connection is set up by the MB_CLIENT block call. You can use either the TCON_IP_v4 or the TCON_Configured structure. It is also possible to use a memory area and reference it using the ANY format, "P#bit address" "data type" "length".ĬONNECT: This input is a variant that defines the connection between your PLC (the client) and the device you are communicating with (the server). In my experience, I've had the best luck using a global data block with an array of booleans or words. MB_DATA_PTR: This input is a variant that acts as a pointer to where the data that is being communicated is stored. The exact breakdown of this parameter, along with the MB_MODE and MB_DATA_ADDR parameters and how they correspond to Modbus function codes can be found in the block documentation (which can be accessed by pressing `F1` on your keyboard while the MB_CLIENT block is highlighted in TIA Portal). MB_DATA_LEN: This input is a UINT that represents the numbers of bits or words of data being handled by this request. The exact breakdown of this parameter, along with the MB_MODE and MB_DATA_LEN parameters and how they correspond to Modbus function codes can be found in the block documentation (which can be accessed by pressing `F1` on your keyboard while the MB_CLIENT block is highlighted in TIA Portal). A common start value for Modbus holding registers is often 40,001, but it will vary based on your data setup and server. MB_DATA_ADDR: This input is a UDINT for the location of the start of the data being read or written. The exact breakdown of this parameter, along with the MB_DATA_ADDR and MB_DATA_LEN parameters and how they correspond to Modbus function codes can be found in the block documentation (which can be accessed by pressing `F1` on your keyboard while the MB_CLIENT block is highlighted in TIA Portal). Generally, a value of 0 is used for reading data from the server, and a value of 1 or 2 is used for sending (writing) data to the server. MB_MODE: This is a USINT input that designates what type of communication request should be sent. This input needs to be false in order to communicate with the server. If this block changes to false in the middle of a communication request, the block will finish that request, but it will not send a new request until REQ becomes true again.ĭISCONNECT: This is a boolean input that controls the connection to the Modbus server. When this input is true, the block will continuously send requests to the server with the parameters indicated by the other inputs. REQ: This is a boolean input that controls when Modbus communication requests are being sent to the server. Now, let's take a look at the block's inputs. It is important to note that if you are trying to build a program that communicates with multiple Modbus servers simultaneously, each instance of MB_CLIENT must have its own instance data block. In this case, I created an instance data block, named "MB_CLIENT_DB" for the block call.

It is located under the Communication category in the Instructions window, as shown below.Īfter dragging in the MB_CLIENT instruction to OB1 in a blank project, this is what it looks like.

So we need to use the MB_CLIENT instruction, provided by Siemens.

In this case, since we are trying to access data from a Server, our PLC will be acting as the Client. I find it hard to keep track of these terms, so it's always helpful to have them defined. The Slave, or Server, is responsible for responding to commands from a Master/Client. The Master, or Client, is responsible for sending commands, such as reading or writing data. Master and Client can be used interchangeably here, as can Slave and Server. The roles played by the two devices exchanging data can be classified as Master-Slave or Client-Server. Terminologyįirst, a clarification on the terminology I'm using. If you are trying to make data available from your PLC to a Modbus TCP Client, then take a look at this blog, or to a Modbus RTU Client, this one. Do you need to access data from a Modbus TCP Server on your S7-1500 PLC? If so, then do not fret, I will walk through setting up your PLC as a Modbus TCP Client to do just that.
