<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Noam Ayalon, Author at DMC, Inc.</title>
	<atom:link href="https://static.dmcinfo.com/blog/author/noama/feed/index.xml" rel="self" type="application/rss+xml" />
	<link></link>
	<description></description>
	<lastBuildDate>Tue, 26 May 2026 22:00:53 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.2</generator>

<image>
	<url>https://static.dmcinfo.com/wp-content/uploads/2025/04/site-icon-150x150.png</url>
	<title>Noam Ayalon, Author at DMC, Inc.</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Getting Started with the Siemens Modbus Extended Library for TIA Portal</title>
		<link>https://static.dmcinfo.com/blog/44660/siemens-modbus-extended-library-for-tia-portal/</link>
		
		<dc:creator><![CDATA[Noam Ayalon]]></dc:creator>
		<pubDate>Thu, 28 May 2026 11:00:00 +0000</pubDate>
				<category><![CDATA[Manufacturing Automation & Intelligence]]></category>
		<category><![CDATA[Siemens PLC]]></category>
		<category><![CDATA[Siemens Open Library]]></category>
		<guid isPermaLink="false">https://static.dmcinfo.com/?p=44660</guid>

					<description><![CDATA[<p>The rexhip Modbus library–part of the Siemens Open Library–is an open-source extension to the base Modbus functions included in TIA Portal. It provides user-friendly Modbus master function blocks (FBs) for both TCP and RTU applications, as well as a host of pre-configured device profiles called “station blocks” (SBs), which include all the necessary queries to [&#8230;]</p>
<p>The post <a href="https://static.dmcinfo.com/blog/44660/siemens-modbus-extended-library-for-tia-portal/">Getting Started with the Siemens Modbus Extended Library for TIA Portal</a> appeared first on <a href="https://static.dmcinfo.com/">DMC, Inc.</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">The rexhip Modbus library–part of the Siemens Open Library–is an open-source extension to the base Modbus functions included in TIA Portal. It provides user-friendly Modbus master function blocks (FBs) for both TCP and RTU applications, as well as a host of pre-configured device profiles called “station blocks” (SBs), which include all the necessary queries to communicate with various common hardware. This guide will cover how to set up Modbus communications in TIA Portal using this library and the tools it provides for troubleshooting.</p>



<p class="wp-block-paragraph">This guide focuses on using the rexhip library, not on general Modbus theory. Topics such as Modicon addressing details, data length inference, byte/word ordering, concurrency limits, and protocol-level RTU vs TCP differences are intentionally omitted where they are handled internally by the library or are covered in standard Modbus documentation.</p>



<h2 class="wp-block-heading" id="h-the-mb-query-function-block">The “mb_query” Function Block</h2>



<h3 class="wp-block-heading" id="h-concept">Concept</h3>



<p class="wp-block-paragraph">The mb_query FB defines a Modbus request that gets sent by a Modbus master FB. Each defined query gets passed into the master block, where it is automatically handled one at a time. Queries can be defined independent of Station Blocks (SBs), but are often defined within SBs because of their improved diagnostic and troubleshooting features. We will cover this more in-depth later.</p>



<h3 class="wp-block-heading" id="h-mb-query-fb-input-parameters">mb_query FB Input Parameters</h3>



<p class="wp-block-paragraph">The following parameters are passed into mb_query to define a query:</p>



<p class="wp-block-paragraph"><strong>mb_addr: </strong>Modbus device address (slave address/unit identifier)</p>



<p class="wp-block-paragraph" style="padding-bottom:var(--wp--preset--spacing--40)"><strong>mode: </strong>This is the Modbus function code. The following are pre-defined tags in mb_query for the supported function codes:</p>



<p class="has-text-align-center wp-block-paragraph"><em>Table 1: mb_query Modes</em></p>



<figure class="wp-block-table aligncenter" style="padding-bottom:var(--wp--preset--spacing--40)"><table class="has-fixed-layout"><tbody><tr><td><strong>Struct</strong></td><td><strong>Tag(Mode)</strong></td><td><strong>Type</strong></td><td><strong>Modbus Function Code</strong></td></tr><tr><td>Read</td><td>“discrete_output”</td><td>Coil</td><td>01</td></tr><tr><td>Read</td><td>“discrete_input”</td><td>Discrete Input</td><td>02</td></tr><tr><td>Read</td><td>“holding_reg”</td><td>Register</td><td>03</td></tr><tr><td>Read</td><td>“input_reg”</td><td>Register</td><td>04</td></tr><tr><td>Write</td><td>“single_discrete_output”</td><td>Coil</td><td>05</td></tr><tr><td>Write</td><td>“single_holding_reg”</td><td>Register</td><td>06</td></tr><tr><td>Write</td><td>“discrete_output”</td><td>Coil</td><td>15</td></tr><tr><td>Write</td><td>“holding_reg”</td><td>Register</td><td>16</td></tr></tbody></table></figure>



<p class="wp-block-paragraph"><strong>data_addr:</strong> This is the starting address of the desired data within the Modbus data area. The rexhip library uses zero-based addressing.</p>



<p class="wp-block-paragraph"><strong>Note:</strong> Some Modbus devices display registers as one-based, so if values are off by one register, this is probably why.</p>



<p class="wp-block-paragraph" style="padding-top:0;padding-bottom:var(--wp--preset--spacing--40)">data_addr does not refer to values such as 40001, which are often found on datasheets.</p>



<p class="has-text-align-center wp-block-paragraph"><em>Table 2: data_addr Examples</em></p>



<figure style="padding-bottom:var(--wp--preset--spacing--40)" class="wp-block-table"><table class="has-fixed-layout"><tbody><tr><td><strong>Datasheet Notation</strong></td><td><strong>Operation and Data Type</strong></td><td><strong>Function Code (mode)</strong></td><td><strong>data_addr</strong></td></tr><tr><td>00001</td><td>Read Coil</td><td>01</td><td>0</td></tr><tr><td>00025</td><td>Write Multiple Coils</td><td>15</td><td>24</td></tr><tr><td>30020</td><td>Read Input Register</td><td>04</td><td>19</td></tr><tr><td>40005</td><td>Write Single Holding Register</td><td>06</td><td>4</td></tr><tr><td>40256</td><td>Write Multiple Holding Registers</td><td>16</td><td>255</td></tr></tbody></table></figure>



<p class="wp-block-paragraph"><strong>dara_ptr:</strong> This is an Input/Output where the data that will be sent or received is stored. It can be any data type, including arrays and UDTs.</p>



<p class="wp-block-paragraph"><span style="margin: 0px;padding: 0px"><strong>data_len:&nbsp;</strong>This is the length of the data in the query &#8211; the number of either bits or 16-bit registers for coils/holding registers, respectively, that will be read/written, starting at data_addr</span>.</p>



<p class="wp-block-paragraph">This is an optional, generally discouraged parameter to specify; it will be automatically calculated from the length of data_ptr by default.</p>



<p class="wp-block-paragraph">If you want to override the automatic calculation, assign data_len to the desired length, and then set it back to automatic after the mb_query function call using <code>#mb_query.data_len :=&nbsp; #mb_query.c.auto_len</code></p>



<h3 class="wp-block-heading" id="h-modicon-addressing-convention">Modicon Addressing Convention</h3>



<p class="wp-block-paragraph" style="padding-top:0;padding-bottom:var(--wp--preset--spacing--40)">The rexhip library supports the Modicon convention for data addressing with the following static tags in <strong>mb_query</strong> to be used when declaring the mode of the query:</p>



<p class="has-text-align-center wp-block-paragraph"><em>Table 3: Modicon Convention Modes</em></p>



<figure style="padding-bottom:var(--wp--preset--spacing--40)" class="wp-block-table"><table class="has-fixed-layout"><tbody><tr><td><strong>Struct</strong></td><td><strong>Tag (Mode)</strong></td><td><strong>Modbus Function Codes</strong></td></tr><tr><td>Mode</td><td>&#8220;read&#8221;</td><td>01, 02, 03, 04</td></tr><tr><td>Mode</td><td>&#8220;write_single&#8221;</td><td>05, 06</td></tr><tr><td>Mode</td><td>&#8220;write&#8221;</td><td>15, 16</td></tr></tbody></table></figure>



<p class="wp-block-paragraph">When using one of the above modes, data_addr declarations take the form found on datasheets (e.g., 40005).</p>



<h3 class="wp-block-heading" id="h-examples-of-mb-query-calls">Examples of mb_query Calls</h3>



<p class="wp-block-paragraph" style="padding-bottom:var(--wp--preset--spacing--40)">The following is an example of&nbsp;mb_query&nbsp;function calls&nbsp;modified&nbsp;from one of the station blocks included in the&nbsp;rexhip&nbsp;library.&nbsp;In this scenario, three queries are being configured, two of which read input registers and one of which reads holding registers.&nbsp;</p>



<figure class="wp-block-image aligncenter size-full is-resized has-custom-border"><img fetchpriority="high" decoding="async" width="643" height="513" src="https://static.dmcinfo.com/wp-content/uploads/2026/05/siemens-modbus-extended-library-image-1.png" alt="Image showing a Siemens TIA Portal programming environment, specifically focusing on the interface and Structured Control Language (SCL) code for a Modbus TCP or RTU communication block." class="has-border-color has-custom-light-gray-neutral-2-border-color wp-image-44661" style="border-width:2px;border-top-left-radius:20px;border-top-right-radius:20px;border-bottom-left-radius:20px;border-bottom-right-radius:20px;width:500px" srcset="https://static.dmcinfo.com/wp-content/uploads/2026/05/siemens-modbus-extended-library-image-1.png 643w, https://static.dmcinfo.com/wp-content/uploads/2026/05/siemens-modbus-extended-library-image-1-300x239.png 300w" sizes="(max-width: 643px) 100vw, 643px" /><figcaption class="wp-element-caption"><em>Figure 1: mb_query Function Call Example 1</em></figcaption></figure>



<p class="wp-block-paragraph" style="padding-bottom:var(--wp--preset--spacing--30)">The following example shows an mb_query function call used to configure a request that writes multiple values to Modbus holding registers. The values are consolidated into an array, which is then passed to mb_query as a single data_ptr. The first array value will be written to the register at data_addr, the second value will be written to the register at data_addr + 1, and so on.</p>



<figure class="wp-block-image aligncenter size-full is-resized has-custom-border is-style-default"><img decoding="async" width="431" height="374" src="https://static.dmcinfo.com/wp-content/uploads/2026/05/siemens-modbus-extended-library-image-2.png" alt="Image showing a Siemens TIA Portal interface, specifically a Function Block (FB) or Function (FC) being programmed in Structured Control Language (SCL)." class="has-border-color has-custom-light-gray-neutral-2-border-color wp-image-44662" style="border-width:2px;border-top-left-radius:20px;border-top-right-radius:20px;border-bottom-left-radius:20px;border-bottom-right-radius:20px;aspect-ratio:1.1524312077035448;object-fit:cover;width:500px" srcset="https://static.dmcinfo.com/wp-content/uploads/2026/05/siemens-modbus-extended-library-image-2.png 431w, https://static.dmcinfo.com/wp-content/uploads/2026/05/siemens-modbus-extended-library-image-2-300x260.png 300w" sizes="(max-width: 431px) 100vw, 431px" /><figcaption class="wp-element-caption"><em>Figure 2: mb_query Function Call Example 2</em></figcaption></figure>



<h3 class="wp-block-heading" id="h-the-mb-query-bits-function-block">The “mb_query_bits” Function Block</h3>



<p class="wp-block-paragraph" style="padding-bottom:var(--wp--preset--spacing--30)">The mb_query FB is designed to process data in bytes, so any queried booleans must total to whole bytes. If the number of queried bits does not equal complete bytes, either query a Boolean array with a length divisible by 8 (leaving unused bits as needed) or use the mb_query_bits FB instead.</p>



<figure class="wp-block-image aligncenter size-full is-resized has-custom-border"><img decoding="async" width="393" height="86" src="https://static.dmcinfo.com/wp-content/uploads/2026/05/siemens-modbus-extended-library-image-3.png" alt="Image of a code snippet written in Structured Text (ST)." class="has-border-color has-custom-light-gray-neutral-2-border-color wp-image-44663" style="border-width:2px;border-top-left-radius:20px;border-top-right-radius:20px;border-bottom-left-radius:20px;border-bottom-right-radius:20px;aspect-ratio:4.334309839738067;object-fit:cover;width:500px" srcset="https://static.dmcinfo.com/wp-content/uploads/2026/05/siemens-modbus-extended-library-image-3.png 393w, https://static.dmcinfo.com/wp-content/uploads/2026/05/siemens-modbus-extended-library-image-3-300x66.png 300w" sizes="(max-width: 393px) 100vw, 393px" /><figcaption class="wp-element-caption"><em>Figure 3: mb_query_bits Function Call Example</em></figcaption></figure>



<h2 class="wp-block-heading" id="h-station-blocks">Station Blocks</h2>



<h3 class="wp-block-heading" id="h-concept-0">Concept</h3>



<p class="wp-block-paragraph">SBs group queries together, so the master block treats them as belonging to the same Modbus device. Device-level execution context is helpful for both tracking device communication and handling query timeouts.</p>



<p class="wp-block-paragraph">If a device encounters communication errors, queries inside the SB can be skipped together with occasional retries, while other devices keep running.</p>



<p class="wp-block-paragraph">This prevents one problematic device from interfering with the entire bus. Also, it is easy to set up multiple devices of the same type by creating multiple instances of the SB.</p>



<h3 class="wp-block-heading" id="h-implementation">Implementation</h3>



<p class="wp-block-paragraph" style="padding-bottom:var(--wp--preset--spacing--20)">SBs contain an SB header and footer, which are functions included in the rexhip library. The header marks the start of the SB, and all mb_query calls that follow it are tagged as belonging to that device. The footer closes the station context. Both the header and the footer take an mb_query instance and a tag of type mb_station_block_udt as arguments.</p>



<figure class="wp-block-image aligncenter size-full is-resized has-custom-border"><img decoding="async" width="532" height="523" src="https://static.dmcinfo.com/wp-content/uploads/2026/05/siemens-modbus-extended-library-image-4.png" alt="Image showing a Siemens TIA Portal environment with a Structured Control Language (SCL) block designed to control Auma actuators via Modbus RTU." class="has-border-color has-custom-light-gray-neutral-2-border-color wp-image-44664" style="border-width:2px;border-top-left-radius:20px;border-top-right-radius:20px;border-bottom-left-radius:20px;border-bottom-right-radius:20px;width:500px" srcset="https://static.dmcinfo.com/wp-content/uploads/2026/05/siemens-modbus-extended-library-image-4.png 532w, https://static.dmcinfo.com/wp-content/uploads/2026/05/siemens-modbus-extended-library-image-4-300x295.png 300w" sizes="(max-width: 532px) 100vw, 532px" /><figcaption class="wp-element-caption"><em>Figure 4: Station Block Example</em></figcaption></figure>



<p class="wp-block-paragraph">As previously mentioned, there are many pre-configured SBs in the rexhip library, as well as the header and footer functions that allow the creation of custom SBs.</p>



<h3 class="wp-block-heading" id="h-the-station-block-udt">The Station Block UDT</h3>



<p class="wp-block-paragraph">The tag of type mb_station_block_udt in an SB provides useful information and configuration options for a device’s queries and is one of the primary reasons to use SBs.</p>



<figure class="wp-block-image aligncenter size-full has-custom-border"><img decoding="async" width="312" height="475" src="https://static.dmcinfo.com/wp-content/uploads/2026/05/siemens-modbus-extended-library-image-5.png" alt="Image displaying a User Defined Data Type (UDT) in Siemens TIA Portal." class="wp-image-44665" style="border-top-left-radius:20px;border-top-right-radius:20px;border-bottom-left-radius:20px;border-bottom-right-radius:20px" srcset="https://static.dmcinfo.com/wp-content/uploads/2026/05/siemens-modbus-extended-library-image-5.png 312w, https://static.dmcinfo.com/wp-content/uploads/2026/05/siemens-modbus-extended-library-image-5-197x300.png 197w" sizes="(max-width: 312px) 100vw, 312px" /><figcaption class="wp-element-caption"><em>Figure 5: Station Block UDT Contents</em></figcaption></figure>



<h3 class="wp-block-heading" id="h-configuration-conf">Configuration (conf):</h3>



<ul class="wp-block-list">
<li><strong>skip_code:</strong> Both the station block header and footer immediately return, preventing all query scheduling, execution, and result handling for that station.</li>



<li style="padding-bottom:var(--wp--preset--spacing--30)"><strong>disable:</strong> Soft stop for the SB handled by the footer, allowing the station to complete its normal end-of-cycle logic before it stops participating further.</li>
</ul>



<p class="has-text-align-center wp-block-paragraph"><em>Table 4: skip_code vs disable functionality</em></p>



<figure class="wp-block-table"><table class="has-fixed-layout"><tbody><tr><td></td><td><strong>skip_code</strong></td><td><strong>disable</strong></td></tr><tr><td><strong>Checked in header</strong></td><td>Yes</td><td>No</td></tr><tr><td><strong>Checked in footer</strong></td><td>Yes</td><td>Yes</td></tr><tr><td><strong>Stops header logic</strong></td><td>Yes</td><td>No</td></tr><tr><td><strong>Stops footer logic</strong></td><td>Yes</td><td>No</td></tr><tr><td><strong>Allows logging</strong></td><td>No</td><td>Yes</td></tr><tr><td><strong>Allows graceful finish</strong></td><td>No</td><td>Yes</td></tr><tr><td><strong>Typical intent</strong></td><td>Hard kill</td><td>Controlled stop</td></tr></tbody></table></figure>



<ul class="wp-block-list">
<li style="padding-top:var(--wp--preset--spacing--40)"><strong>read_only:</strong> Only allows read queries to be executed.</li>



<li><strong>max_comm_error</strong>: The number of consecutive communications faults that must occur before a communication error is thrown.</li>



<li><strong>exec_x_quries:</strong> The number of queries in the SB to be executed in each loop.</li>
</ul>



<p class="wp-block-paragraph">The “out” struct provides information about the station’s current operational status rather than historical data.</p>



<ul class="wp-block-list">
<li><span style="margin: 0px;padding: 0px"><strong>error:</strong>&nbsp;General error flag which stays true until all queries in the SB complete successfully&nbsp;in one cycle</span>.</li>



<li><strong>error_comm: </strong>True if consecutive communication errors exceed max_comm_error.</li>



<li><strong>finish:</strong> True for one scan when the SB passes execution to the next device.</li>
</ul>



<p class="wp-block-paragraph">The “log” struct provides historical, cumulative data about query execution and error conditions for diagnostics and analysis.</p>



<ul class="wp-block-list">
<li><strong>connected_time:</strong> Timestamp of when a device last regained communication.</li>



<li><strong>disconnected_time:</strong> Timestamp of when a device last lost communication.</li>



<li><strong>done_cnt:</strong> The number of successful queries.</li>



<li><strong>error_comm_cnt:</strong> The number of communication errors.</li>



<li><strong>error_exception_cnt:</strong> The number of non-communication-related errors.</li>



<li><strong>error_status:</strong> The error status code of the most recent failed query.</li>



<li><strong>error_data_addr:</strong> The data address associated with the most recent failed query.</li>
</ul>



<p class="wp-block-paragraph">The “z” struct is used for the internal workings of the rexhip functions and is not intended for logic, diagnostics, or configuration.</p>



<h3 class="wp-block-heading" id="h-station-block-troubleshooting-tools">Station Block Troubleshooting Tools</h3>



<p class="wp-block-paragraph" style="padding-bottom:var(--wp--preset--spacing--30)">The&nbsp;mb_station_block_udt&nbsp;“log”&nbsp;struct&nbsp;allows engineers to quickly&nbsp;identify&nbsp;communication issues and respond appropriately. The following&nbsp;examples&nbsp;demonstrate&nbsp;how it&nbsp;could&nbsp;be used to&nbsp;troubleshoot&nbsp;faulty&nbsp;device communications.&nbsp;</p>



<p class="has-text-align-center wp-block-paragraph"><em>Table 5: Example &#8220;log&#8221; Struct Use Cases</em></p>



<figure style="padding-bottom:var(--wp--preset--spacing--30)" class="wp-block-table"><table class="has-fixed-layout"><tbody><tr><td><strong>Tag</strong></td><td><strong>Use Cases</strong></td></tr><tr><td><strong>connected_time</strong></td><td>Identifying if a device is repeatedly dropping and reconnecting.</td></tr><tr><td><strong>disconnected_time</strong></td><td>Identifying if a device is repeatedly dropping and reconnecting.<br>Correlating communication loss with external events, such as equipment being powered down.</td></tr><tr><td><strong>done_cnt</strong></td><td>Confirming the device is completing successful queries.<br>Estimating how quickly queries are being completed.</td></tr><tr><td><strong>error_comm_cnt</strong></td><td>Confirming the device is attempting to communicate.<br>Identifying errors as communication errors.</td></tr><tr><td><strong>error_exception_cnt</strong></td><td>Confirming the device is attempting to communicate.<br>Identifying errors as non-communication Modbus exceptions.</td></tr><tr><td><strong>error_status</strong></td><td>Identifying the specific type of error affecting a device.</td></tr><tr><td><strong>error_data_addr</strong></td><td>Identifying the exact misconfigured register/coil causing errors.</td></tr></tbody></table></figure>



<h2 class="wp-block-heading" id="h-modbus-rtu-setup" style="padding-top:var(--wp--preset--spacing--30)">Modbus RTU Setup</h2>



<h3 class="wp-block-heading" id="h-the-modbus-master-block">The Modbus Master Block</h3>



<p class="wp-block-paragraph">The rexhip library includes two RTU master function blocks, mb_master_1200_ctrl and mb_master_1500_ctrl, for Siemens 1200 and 1500 PLCs, respectively. This guide will use a 1200-series PLC as an example. The 1500-series master block includes an additional operating_mode input that is mapped to the operating mode of the underlying comm_load instruction.</p>



<p class="wp-block-paragraph" style="padding-bottom:var(--wp--preset--spacing--30)">The master control block takes inputs for the hardware ID and baud rate, and an input/output of type mb_query. In the instance data of the master block, the static struct “conf” contains the parity, retries, timeout gain, and timeout offset parameters.</p>



<figure class="wp-block-image aligncenter size-full is-resized has-custom-border"><img decoding="async" width="513" height="550" src="https://static.dmcinfo.com/wp-content/uploads/2026/05/siemens-modbus-extended-library-image-6.png" alt="Image displaying a function block (FB) configuration for a Modbus master communication setup in Siemens TIA Portal." class="has-border-color has-custom-light-gray-neutral-2-border-color wp-image-44670" style="border-width:2px;border-top-left-radius:20px;border-top-right-radius:20px;border-bottom-left-radius:20px;border-bottom-right-radius:20px;width:500px" srcset="https://static.dmcinfo.com/wp-content/uploads/2026/05/siemens-modbus-extended-library-image-6.png 513w, https://static.dmcinfo.com/wp-content/uploads/2026/05/siemens-modbus-extended-library-image-6-280x300.png 280w" sizes="(max-width: 513px) 100vw, 513px" /><figcaption class="wp-element-caption"><em>Figure 6: Modbus Master Block Call Example</em></figcaption></figure>



<h3 class="wp-block-heading" id="h-timeout">Timeout</h3>



<p class="wp-block-paragraph">The timeout is automatically calculated as follows:</p>



<p class="wp-block-paragraph"><em>Timeout = (total bits transmitted ÷ baud rate ) x timeout gain + timeout offset</em></p>



<p class="wp-block-paragraph">The result is clamped to 5 ms ≤ result ≤ 65 s.</p>



<p class="wp-block-paragraph">This calculation scales the timeout based on the amount of information being transmitted. Setting gain = 0 disables auto-calculation and uses the offset as a fixed timeout.</p>



<h3 class="wp-block-heading" id="h-integrating-queries-with-the-master-block">Integrating Queries with the Master Block</h3>



<p class="wp-block-paragraph">Below is an example of one way to load queries into a Modbus master block using station blocks.</p>



<p class="wp-block-paragraph">This example will use the fbModbus function block shown above, and its instance memory data block “instance_fbModbus.” It will also use two pre-configured station blocks from the rexhip library–AUMA Valve and ABB AquaMaster 3 flowmeter.</p>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-0e47273b wp-block-columns-is-layout-flex">
<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<figure class="wp-block-image aligncenter size-full is-resized has-custom-border"><img decoding="async" width="461" height="409" src="https://static.dmcinfo.com/wp-content/uploads/2026/05/siemens-modbus-extended-library-image-7.png" alt="Image displaying a function block (FB) configuration for a Modbus master communication setup in Siemens TIA Portal." class="has-border-color has-custom-light-gray-neutral-2-border-color wp-image-44672" style="border-width:2px;border-top-left-radius:20px;border-top-right-radius:20px;border-bottom-left-radius:20px;border-bottom-right-radius:20px;aspect-ratio:1.1254528189076074;width:455px;height:auto" srcset="https://static.dmcinfo.com/wp-content/uploads/2026/05/siemens-modbus-extended-library-image-7.png 461w, https://static.dmcinfo.com/wp-content/uploads/2026/05/siemens-modbus-extended-library-image-7-300x266.png 300w" sizes="(max-width: 461px) 100vw, 461px" /><figcaption class="wp-element-caption"><em>Figure 7: AUMA Valve Station Block</em></figcaption></figure>
</div>



<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<figure class="wp-block-image alignleft size-full is-resized has-custom-border"><img decoding="async" width="476" height="374" src="https://static.dmcinfo.com/wp-content/uploads/2026/05/siemens-modbus-extended-library-image-8.png" alt="Image of a code snippet for a Siemens PLC (S7-1200/1500) using a custom library to interface with an ABB AquaMaster 3 Electromagnetic Flowmeter via Modbus RTU or TCP." class="has-border-color has-custom-light-gray-neutral-2-border-color wp-image-44673" style="border-width:2px;border-top-left-radius:20px;border-top-right-radius:20px;border-bottom-left-radius:20px;border-bottom-right-radius:20px;aspect-ratio:1.2685827552031714;width:510px;height:auto" srcset="https://static.dmcinfo.com/wp-content/uploads/2026/05/siemens-modbus-extended-library-image-8.png 476w, https://static.dmcinfo.com/wp-content/uploads/2026/05/siemens-modbus-extended-library-image-8-300x236.png 300w" sizes="(max-width: 476px) 100vw, 476px" /><figcaption class="wp-element-caption"><em>Figure 8: ABB AquaMaster 3 Station Block</em></figcaption></figure>
</div>
</div>



<p class="wp-block-paragraph">OB1 (Main) will call fbModbus, which holds the Modbus master block, and fbDevices, which holds the station blocks.</p>



<p class="wp-block-paragraph" style="padding-bottom:var(--wp--preset--spacing--40)">This example system will have three valves and two flowmeters, so three valve station blocks and two flowmeter station blocks are called in fbDevices. Each one is given a unique Modbus address, and mb_query is set to “instance_fbModbus.mb_query” for all five devices.</p>



<div class="wp-block-columns are-vertically-aligned-center is-layout-flex wp-container-core-columns-is-layout-0e47273b wp-block-columns-is-layout-flex">
<div class="wp-block-column is-vertically-aligned-center is-layout-flow wp-block-column-is-layout-flow" style="flex-basis:33.33%">
<figure class="wp-block-image aligncenter size-full has-custom-border"><img decoding="async" width="278" height="491" src="https://static.dmcinfo.com/wp-content/uploads/2026/05/siemens-modbus-extended-library-image-9.png" alt="Image of two networks of Ladder Logic programming within the TIA Portal software environment" class="has-border-color has-custom-light-gray-neutral-2-border-color wp-image-44674" style="border-width:2px;border-top-left-radius:20px;border-top-right-radius:20px;border-bottom-left-radius:20px;border-bottom-right-radius:20px" srcset="https://static.dmcinfo.com/wp-content/uploads/2026/05/siemens-modbus-extended-library-image-9.png 278w, https://static.dmcinfo.com/wp-content/uploads/2026/05/siemens-modbus-extended-library-image-9-170x300.png 170w" sizes="(max-width: 278px) 100vw, 278px" /><figcaption class="wp-element-caption"><em>Figure 9: FB Calls in OB1</em></figcaption></figure>
</div>



<div class="wp-block-column is-vertically-aligned-center is-layout-flow wp-block-column-is-layout-flow" style="flex-basis:66.66%">
<figure class="wp-block-image aligncenter size-full has-custom-border"><img decoding="async" width="1166" height="725" src="https://static.dmcinfo.com/wp-content/uploads/2026/05/siemens-modbus-extended-library-image-10.png" alt="Screenshot showing the configuration of a Function Block (FB) in Siemens TIA Portal, specifically focusing on an array of device instances being called in a ladder logic program." class="has-border-color has-custom-light-gray-neutral-2-border-color wp-image-44675" style="border-width:2px;border-top-left-radius:20px;border-top-right-radius:20px;border-bottom-left-radius:20px;border-bottom-right-radius:20px" srcset="https://static.dmcinfo.com/wp-content/uploads/2026/05/siemens-modbus-extended-library-image-10.png 1166w, https://static.dmcinfo.com/wp-content/uploads/2026/05/siemens-modbus-extended-library-image-10-300x187.png 300w, https://static.dmcinfo.com/wp-content/uploads/2026/05/siemens-modbus-extended-library-image-10-1024x637.png 1024w, https://static.dmcinfo.com/wp-content/uploads/2026/05/siemens-modbus-extended-library-image-10-768x478.png 768w" sizes="(max-width: 1166px) 100vw, 1166px" /><figcaption class="wp-element-caption"><em>Figure 10: fbDevices</em></figcaption></figure>
</div>
</div>



<h3 class="wp-block-heading" id="h-the-path-of-the-query">The Path of the Query</h3>



<ol class="wp-block-list">
<li>The query starts in an SB where it is configured, and is then passed out of the SB.</li>



<li>It is then passed to fbModbus&#8217;s instance data block via fbDevices<em>.</em></li>



<li>It then gets loaded into the Modbus master block.</li>
</ol>



<p class="wp-block-paragraph" style="padding-bottom:var(--wp--preset--spacing--30)">Each query loaded into the master block is automatically placed in a queue and handled one at a time by the master block.</p>



<div class="wp-block-columns are-vertically-aligned-bottom is-layout-flex wp-container-core-columns-is-layout-48049e16 wp-block-columns-is-layout-flex" style="padding-top:var(--wp--preset--spacing--30)">
<div class="wp-block-column is-vertically-aligned-bottom is-layout-flow wp-block-column-is-layout-flow">
<figure class="wp-block-image aligncenter size-full is-resized has-custom-border"><img decoding="async" width="513" height="678" src="https://static.dmcinfo.com/wp-content/uploads/2026/05/siemens-modbus-extended-library-image-11.png" alt="Selected code snippet shows a Modbus write instruction being executed within a Siemens TIA Portal environment." class="has-border-color has-custom-light-gray-neutral-2-border-color wp-image-44676" style="border-width:2px;border-top-left-radius:20px;border-top-right-radius:20px;border-bottom-left-radius:20px;border-bottom-right-radius:20px;aspect-ratio:0.7585678376555699;width:334px;height:auto" srcset="https://static.dmcinfo.com/wp-content/uploads/2026/05/siemens-modbus-extended-library-image-11.png 513w, https://static.dmcinfo.com/wp-content/uploads/2026/05/siemens-modbus-extended-library-image-11-227x300.png 227w" sizes="(max-width: 513px) 100vw, 513px" /><figcaption class="wp-element-caption"><em>Figure 11: mb_query Definition in Station Block</em></figcaption></figure>
</div>



<div class="wp-block-column is-vertically-aligned-bottom is-layout-flow wp-block-column-is-layout-flow">
<figure class="wp-block-image aligncenter size-full has-custom-border"><img decoding="async" width="757" height="484" src="https://static.dmcinfo.com/wp-content/uploads/2026/05/siemens-modbus-extended-library-image-12.png" alt="Image illustrates the mapping of a Static variable from a Function Block instance to an input parameter of another Function Block in a Siemens TIA Portal environment." class="has-border-color has-custom-light-gray-neutral-2-border-color wp-image-44677" style="border-width:2px;border-top-left-radius:20px;border-top-right-radius:20px;border-bottom-left-radius:20px;border-bottom-right-radius:20px" srcset="https://static.dmcinfo.com/wp-content/uploads/2026/05/siemens-modbus-extended-library-image-12.png 757w, https://static.dmcinfo.com/wp-content/uploads/2026/05/siemens-modbus-extended-library-image-12-300x192.png 300w" sizes="(max-width: 757px) 100vw, 757px" /><figcaption class="wp-element-caption"><em>Figure 12: mb_query Transferred to &#8220;instance_fbModbus&#8221;</em></figcaption></figure>
</div>



<div class="wp-block-column is-vertically-aligned-bottom is-layout-flow wp-block-column-is-layout-flow">
<figure class="wp-block-image aligncenter size-full has-custom-border"><img decoding="async" width="513" height="559" src="https://static.dmcinfo.com/wp-content/uploads/2026/05/siemens-modbus-extended-library-image-13.png" alt="Siemens S7-1200 PLC function block showing the mb_master_1200_ctrl configured for Modbus RTU communication, with a static mb_query variable mapped to the control block and constants defining RS485 port and baud rate." class="has-border-color has-custom-light-gray-neutral-2-border-color wp-image-44678" style="border-width:2px;border-top-left-radius:20px;border-top-right-radius:20px;border-bottom-left-radius:20px;border-bottom-right-radius:20px" srcset="https://static.dmcinfo.com/wp-content/uploads/2026/05/siemens-modbus-extended-library-image-13.png 513w, https://static.dmcinfo.com/wp-content/uploads/2026/05/siemens-modbus-extended-library-image-13-275x300.png 275w" sizes="(max-width: 513px) 100vw, 513px" /><figcaption class="wp-element-caption"><em>Figure 13: mb_query Arrives at Master Block</em></figcaption></figure>
</div>
</div>



<h3 class="wp-block-heading" id="h-modbus-tcp-client-setup">Modbus TCP Client Setup</h3>



<p class="wp-block-paragraph">The rexhip library provides a wrapper for the Modbus TCP client function native to TIA Portal, mb_tcp_ctrl (which may be called mb_client_ctrl depending on the library version). The library does not provide a wrapper for the Modbus TCP server function, so if configuring a server, use the native TIA Portal function MB_SERVER.</p>



<p class="wp-block-paragraph" style="padding-bottom:var(--wp--preset--spacing--30)">The mb_tcp_ctrl block takes inputs for the hardware interface, connection ID (should match the server connection ID), server IP address, TCP port, timeout, and an input/output of mb_query. Below is an example of an mb_tcp_ctrl block call.</p>



<figure class="wp-block-image aligncenter size-full is-resized has-custom-border" style="margin-top:var(--wp--preset--spacing--40);margin-bottom:var(--wp--preset--spacing--40)"><img decoding="async" width="441" height="251" src="https://static.dmcinfo.com/wp-content/uploads/2026/05/siemens-modbus-extended-library-image-14.png" alt="The block shown is a Function Block (FB9) named &quot;mb_tcp_ctrl&quot;, which is designed to manage Modbus TCP client communications within a Siemens TIA Portal environment." class="has-border-color wp-image-44679" style="border-color:#eeeeee;border-top-left-radius:20px;border-top-right-radius:20px;border-bottom-left-radius:20px;border-bottom-right-radius:20px;aspect-ratio:1.7391090024031055;object-fit:cover;width:500px" srcset="https://static.dmcinfo.com/wp-content/uploads/2026/05/siemens-modbus-extended-library-image-14.png 441w, https://static.dmcinfo.com/wp-content/uploads/2026/05/siemens-modbus-extended-library-image-14-300x171.png 300w" sizes="(max-width: 441px) 100vw, 441px" /><figcaption class="wp-element-caption"><em>Figure 14: Modbus TCP Client Block Call Example</em></figcaption></figure>



<p class="wp-block-paragraph">Queries are loaded into the TCP control block in the exact same way as the RTU control blocks, and query statuses can similarly be monitored in the instance memory of SBs.</p>



<h2 class="wp-block-heading" id="h-conclusion">Conclusion</h2>



<p class="wp-block-paragraph" style="padding-bottom:var(--wp--preset--spacing--40)">The rexhip Modbus library provides a structured, consistent way to set up and manage Modbus RTU and TCP communications in TIA Portal. Using standard function blocks and station blocks simplifies configuration, improves readability, and makes troubleshooting easier across a wide range of devices. This approach helps engineers spend less time dealing with protocol details and more time building reliable, maintainable automation systems.</p>



<div class="wp-block-group alignwide has-custom-light-blue-background-color has-background is-layout-flow wp-container-core-group-is-layout-dbd34961 wp-block-group-is-layout-flow" style="border-radius:20px;margin-top:var(--wp--preset--spacing--50);margin-bottom:var(--wp--preset--spacing--50);padding-top:var(--wp--preset--spacing--50);padding-right:0;padding-bottom:var(--wp--preset--spacing--50);padding-left:0">
<div class="wp-block-columns alignwide are-vertically-aligned-center is-layout-flex wp-container-core-columns-is-layout-43efaee5 wp-block-columns-is-layout-flex" style="padding-right:var(--wp--preset--spacing--60);padding-left:var(--wp--preset--spacing--60)">
<div class="wp-block-column is-vertically-aligned-center is-layout-flow wp-block-column-is-layout-flow" style="flex-basis:85%">
<h3 class="wp-block-heading has-text-align-left" id="h-have-an-upcoming-project-dmc-can-help-you-take-the-next-step">Planning a new automation project or controls upgrade?</h3>



<p class="has-text-align-left wp-block-paragraph" id="h-need-help-turning-ideas-into-outcomes-automation-project-to-the-next-level-contact-us-today-to-learn-more-about-our-solutions-and-how-we-can-help-you-achieve-your-goals">DMC delivers <a href="https://static.dmcinfo.com/services/manufacturing-automation-and-intelligence/">Manufacturing Automation</a> and <a href="https://static.dmcinfo.com/services/manufacturing-automation-and-intelligence/plc-programming/">PLC Programming</a> solutions that help reduce downtime and improve accuracy on the factory floor.</p>
</div>



<div class="wp-block-column is-vertically-aligned-center is-layout-flow wp-block-column-is-layout-flow" style="flex-basis:15%">
<div class="wp-block-buttons is-horizontal is-content-justification-center is-layout-flex wp-container-core-buttons-is-layout-2236275c wp-block-buttons-is-layout-flex">
<div class="wp-block-button is-style-fill"><a class="wp-block-button__link has-base-contrast-color has-text-color has-link-color wp-element-button" href="https://static.dmcinfo.com/contact/">Contact Us</a></div>
</div>
</div>
</div>
</div>



<p class="wp-block-paragraph"></p>
<p>The post <a href="https://static.dmcinfo.com/blog/44660/siemens-modbus-extended-library-for-tia-portal/">Getting Started with the Siemens Modbus Extended Library for TIA Portal</a> appeared first on <a href="https://static.dmcinfo.com/">DMC, Inc.</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
