<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Modbus TCP illegal function exception]]></title><description><![CDATA[<p dir="auto">I'm using the mobuds TCP packet template in the transmit pane to test reading some holding registers. So default I'm using the "Modbus TCP read" option and fill in all the necassary options. After trying to use the "Modbus TCP read/write multiple"  and switched back to  "Modbus TCP read" I cant read any register anymore without getting the IllegalFunction Exception. I have tried resetting all the settings back to default, even reinstalled IOninja but with no success.</p>
<p dir="auto">I can reproduce this issue on another PC. When I'm comparing my settings on a fresh install of IOninja, the issue seems to be the length field of ADU what is updating wrong. When I disable "auto-update length" and fill in the value from the PC that is working correctly, it's working, but when I enable "auto-update length" again its throwing the illegalfunction exceptions again.</p>
<p dir="auto">Is this is bug or am I missing something?</p>
<p dir="auto">Succesvol reading with auto-update disabled<br />
<img src="/forum/assets/uploads/files/1700038770508-schermafbeelding-2023-11-15-095918.png" alt="Schermafbeelding 2023-11-15 095918.png" class=" img-responsive img-markdown" width="954" height="461" /></p>
<p dir="auto">Failed to read with auto-update enabled<br />
<img src="/forum/assets/uploads/files/1700038781882-schermafbeelding-2023-11-15-095902.png" alt="Schermafbeelding 2023-11-15 095902.png" class=" img-responsive img-markdown" width="1052" height="459" /></p>
]]></description><link>http://64.23.185.212/forum/topic/260/modbus-tcp-illegal-function-exception</link><generator>RSS for Node</generator><lastBuildDate>Sat, 05 Sep 2026 20:49:45 GMT</lastBuildDate><atom:link href="http://64.23.185.212/forum/topic/260.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 15 Nov 2023 08:57:27 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Modbus TCP illegal function exception on Thu, 16 Nov 2023 10:23:35 GMT]]></title><description><![CDATA[<p dir="auto">Thanks for the detailed explanation and information Vladimir! This fixes my issue and nice to hear that it will be solved in the next release.  Thank you very much! <img src="http://64.23.185.212/forum/assets/plugins/nodebb-plugin-emoji/emoji/android/1f642.png?v=miq4h6da9ug" class="not-responsive emoji emoji-android emoji--slightly_smiling_face" title=":)" alt="🙂" /></p>
]]></description><link>http://64.23.185.212/forum/post/563</link><guid isPermaLink="true">http://64.23.185.212/forum/post/563</guid><dc:creator><![CDATA[Ronald Tonnis de Graaf]]></dc:creator><pubDate>Thu, 16 Nov 2023 10:23:35 GMT</pubDate></item><item><title><![CDATA[Reply to Modbus TCP illegal function exception on Thu, 16 Nov 2023 02:17:26 GMT]]></title><description><![CDATA[<p dir="auto">Not exactly a bug but rather a missing misuse protection.</p>
<p dir="auto">So, what's happening? The automatic calculation of  Modbus TCP frames is done like this:</p>
<pre><code>void updateModbusTcpLength(void* p) {
	size_t size = dynamic sizeof(p);
	if (size &lt; sizeof(io.ModbusTcpAduHdr))
		return;

	((io.ModbusTcpAduHdr*)p).m_length = size - offsetof(io.ModbusTcpAduHdr.m_deviceAddress);
}
</code></pre>
<p dir="auto">Basically, <code>m_length</code> is set to the length of the payload (from <code>m_deviceAddress</code> and to the very end of the packet).</p>
<p dir="auto">In your case, the packet length is 17, offset of <code>m_deviceAddress</code> is 6, so <code>m_length</code> is set to 11. However, the size of <code>Modbus TCP read</code> should always be 12 (not 17). If you erase the trailing 5 bytes from your packet, it will work as expected.</p>
<p dir="auto">That should solve the issue; for more relevant details, read on.</p>
<p dir="auto">By design, packet templates never allow creating a packet <em>shorter</em> than the template itself. However, it's allowed to add any suffix after the templated headers (that would be required for <code>Modbus TCP write</code>, for instance).</p>
<p dir="auto">In <code>ioninja-5.1.0</code> we added the <code>fixedSize</code> attribute exactly to prevent unintentional misuse in case of packets that should never grow <em>longer</em> than the template itself.</p>
<p dir="auto"><code>Modbus TCP read</code> is exactly this kind of packet, but in the current version of IO Ninja, it's missing the <code>fixedSize</code> attribute. We will add it in the next release of IO Ninja, but in the meantime, you can fix it by yourself. To do so, please open  <code>ioninja/scripts/packets/ModbusTcp.jnc</code> in any text editor, locate the definition of <code>ModbuTcpReadPacket</code> (in the very beginning), and modify it as such:</p>
<pre><code>[ 
	displayName = "Modbus TCP read",
	fixedSize
]
struct ModbusTcpReadPacket {
// ...
</code></pre>
<p dir="auto">In order to apply it, please reload this template into the Packet Template editor (<code>Edit packet template</code> -&gt; <code>Load stock script</code> -&gt; <code>Modbus TCP</code>).</p>
<p dir="auto">Let me know if this works for you.</p>
]]></description><link>http://64.23.185.212/forum/post/562</link><guid isPermaLink="true">http://64.23.185.212/forum/post/562</guid><dc:creator><![CDATA[Vladimir]]></dc:creator><pubDate>Thu, 16 Nov 2023 02:17:26 GMT</pubDate></item></channel></rss>