<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to STRUCT AT %MW1000</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/eac4fbe382/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/eac4fbe382/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/eac4fbe382/</id><updated>2024-08-13T11:33:04.877000Z</updated><subtitle>Recent posts to STRUCT AT %MW1000</subtitle><entry><title>STRUCT AT %MW1000</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/eac4fbe382/?limit=100#25b6" rel="alternate"/><published>2024-08-13T11:33:04.877000Z</published><updated>2024-08-13T11:33:04.877000Z</updated><author><name>Gustavo Antonio Banchetti Brucatori</name><uri>https://forge.codesys.com/u/mubeta/</uri></author><id>https://forge.codesys.comde37f1730a8ee4f93d7f580eaf122fe4ee65e04e</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;This is normal and correct since in CoDeSys static addressing of variables uses the IEC method. A double word (long) has the size of 8 bytes, so %ML0 coincides with %MB0 ... %MB7; %ML1000 with %MB8000 ... %MB8007. (Similar reason for word and other formats).&lt;br/&gt;
Also the reason the compiler won't let you map the structure to a %MW depends on the fact that the individual base elements are manipulated to 32 bits regardless of the smaller size.&lt;/p&gt;
&lt;p&gt;That said, it makes me strange that you cannot write a parser without making use of static memory allocation.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>STRUCT AT %MW1000</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/eac4fbe382/?limit=25#6e3d" rel="alternate"/><published>2024-08-13T07:05:01.057000Z</published><updated>2024-08-13T07:05:01.057000Z</updated><author><name>paulorb</name><uri>https://forge.codesys.com/u/paulorb/</uri></author><id>https://forge.codesys.coma753aba573b7f034a4779ae8013989d1f4e710fa</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hi I am trying to use STRUCT to parse commands from Modbus/TCP, Modbus client will fill the bytes related to a specific command (type, parameters), then PLC (Codesys) will access the command parameters. A STRUCT will simplify a lot the process of parsing the data, so I don't need to parse byte per byte, address will be mapped to a struct and I can use it for parsing the data.&lt;/p&gt;
&lt;p&gt;From what I understood, the compiler does not allow me to specify the location of the struct for a %MW register.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;VAR_COMMAND AT %MW1002: REFERENCE TO structGenericModbusCommand;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;This will throw:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;Bad declaration, use '%ML' for 'structGenericModbusCommand' variable&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;But If I change it to %ML, when you go online you see that it is actually allocating the struct in another memory address.&lt;/p&gt;
&lt;p&gt;When we go online, on GVL we can see:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;VAR_COMMAND.     structGenericModbusCommand     %ML1002
     commandType        COMMANDTYPE             %MB8016
     &lt;span class="k"&gt;...&lt;/span&gt;                                        %MB8020
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;I am not specifying a pointer or a reference it is a struct type, why is it mapping to a %MW location (random one). How can I control where it is mapping to?&lt;/p&gt;
&lt;p&gt;I need a consistent way to map STRUCT to specific modbus address. Is it possible?&lt;/p&gt;
&lt;p&gt;Thanks,&lt;br/&gt;
Paulo&lt;/p&gt;
&lt;p&gt;Note I am using a Codesys OEM:  Schneider Machine Expert Logic Builder (M241)&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>