<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Addressing memory area </title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/b223d63214/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/b223d63214/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/b223d63214/</id><updated>2022-08-31T12:27:49.621000Z</updated><subtitle>Recent posts to Addressing memory area </subtitle><entry><title>Addressing memory area </title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/b223d63214/?limit=25#24cb/3f5d" rel="alternate"/><published>2022-08-31T12:27:49.621000Z</published><updated>2022-08-31T12:27:49.621000Z</updated><author><name>fajean</name><uri>https://forge.codesys.com/u/fajean/</uri></author><id>https://forge.codesys.com4cac186b7c7f15b6e3fe0610efa623e4366377d8</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Personally, I would forego the union and individual entry structures and only use the array. It is more concise, and allows adjusting array size with a "configurable constant" (no other code change). This still allows "AT" addresses for communication.  I only use structured code, maybe this blinds me to cases where arrays are not as easy to code for.&lt;/p&gt;
&lt;p&gt;However, if you prefer, or for some reason are forced, to have variables accessible in a way that does not use arrays, the above should work.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Addressing memory area </title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/b223d63214/?limit=25#24cb" rel="alternate"/><published>2022-08-31T12:19:08.076000Z</published><updated>2022-08-31T12:19:08.076000Z</updated><author><name>aivarasutkus</name><uri>https://forge.codesys.com/u/aivarasutkus/</uri></author><id>https://forge.codesys.com2b152939bd2a82f21bf2328aed0c2e7fb193f5ef</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Sorry, crashed browser.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Addressing memory area </title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/b223d63214/?limit=25#911c/c118" rel="alternate"/><published>2022-08-31T12:18:03.325000Z</published><updated>2022-08-31T12:18:03.325000Z</updated><author><name>aivarasutkus</name><uri>https://forge.codesys.com/u/aivarasutkus/</uri></author><id>https://forge.codesys.com91e92de259a3a7c55c20e6e1db175da05237b4bc</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Bingo. Thanks&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Addressing memory area </title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/b223d63214/?limit=25#911c/ee6e" rel="alternate"/><published>2022-08-31T12:17:59.351000Z</published><updated>2022-08-31T12:17:59.351000Z</updated><author><name>aivarasutkus</name><uri>https://forge.codesys.com/u/aivarasutkus/</uri></author><id>https://forge.codesys.com59e478198ea2dd12e3d76ddc6e1cb66a6a9d778a</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Bingo. Thanks!&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Addressing memory area </title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/b223d63214/?limit=25#911c/d28a" rel="alternate"/><published>2022-08-31T12:17:54.903000Z</published><updated>2022-08-31T12:17:54.903000Z</updated><author><name>aivarasutkus</name><uri>https://forge.codesys.com/u/aivarasutkus/</uri></author><id>https://forge.codesys.comfcbb603e18eca77ed6324017297389f71d420812</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Bingo. Thanks!&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Addressing memory area </title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/b223d63214/?limit=25#911c/a6d4" rel="alternate"/><published>2022-08-31T12:17:49.299000Z</published><updated>2022-08-31T12:17:49.299000Z</updated><author><name>aivarasutkus</name><uri>https://forge.codesys.com/u/aivarasutkus/</uri></author><id>https://forge.codesys.com667556e8c8e7f3afd9fb736ee31d8d7e75ee5708</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Bingo. Thanks!&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Addressing memory area </title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/b223d63214/?limit=25#911c" rel="alternate"/><published>2022-08-31T10:32:00.417000Z</published><updated>2022-08-31T10:32:00.417000Z</updated><author><name>fajean</name><uri>https://forge.codesys.com/u/fajean/</uri></author><id>https://forge.codesys.comb04e5a223e49f03384e3f838ae7f4b8f282e46e0</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Here is what I think you are trying to achieve :&lt;br/&gt;
&lt;em&gt; Allow access to variables without the use of arrays for parts of your code that cannot deal with arrays&lt;br/&gt;
&lt;/em&gt; Allow access to variables as an array for other parts of your code that are simpler (and easier to modify) done this way.&lt;br/&gt;
* Allow mapping to "AT" addresses for communications purposes&lt;/p&gt;
&lt;p&gt;Here is one way this may be done.&lt;/p&gt;
&lt;p&gt;First, I will assume you have a structure for each of your analog values that looks like this :&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="err"&gt;TYPE Analog_300_A13EGA10CF001 :&lt;/span&gt;
&lt;span class="err"&gt;STRUCT&lt;/span&gt;
&lt;span class="err"&gt;  MV: REAL;&lt;/span&gt;
&lt;span class="err"&gt;  Sim_value: REAL;&lt;/span&gt;
&lt;span class="err"&gt;  // ...&lt;/span&gt;
&lt;span class="err"&gt;END_STRUCT&lt;/span&gt;
&lt;span class="err"&gt;END_TYPE&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Then, define a structure that has all the entries you need. Please note this is much like defining an array by explicitly instantiating each entry.&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="err"&gt;TYPE Analog_300_entries :&lt;/span&gt;
&lt;span class="err"&gt;STRUCT&lt;/span&gt;
&lt;span class="err"&gt;  entry_0: Analog_300_A13EGA10CF001;&lt;/span&gt;
&lt;span class="err"&gt;  entry_1: Analog_300_A13EGA10CF001;&lt;/span&gt;
&lt;span class="err"&gt;  entry_2: Analog_300_A13EGA10CF001;&lt;/span&gt;
&lt;span class="err"&gt;  entry_3: Analog_300_A13EGA10CF001;&lt;/span&gt;
&lt;span class="err"&gt;END_STRUCT&lt;/span&gt;
&lt;span class="err"&gt;END_TYPE&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Now, define a union, which will give two "views" of the same memory area, so that we can see it both as an array and as a structure of individual entries.&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="err"&gt;TYPE Analog_300_union :&lt;/span&gt;
&lt;span class="err"&gt;UNION&lt;/span&gt;
&lt;span class="err"&gt;  entries: Analog_300_entries;&lt;/span&gt;
&lt;span class="err"&gt;  arrayed: ARRAY[0..3] OF Analog_300_A13EGA10CF001;&lt;/span&gt;
&lt;span class="err"&gt;END_UNION&lt;/span&gt;
&lt;span class="err"&gt;END_TYPE&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;You instantiate that union in a global variables list :&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="err"&gt;VAR_GLOBAL&lt;/span&gt;
&lt;span class="err"&gt;  Analog_300 AT %MW0: Analog_300_union;&lt;/span&gt;
&lt;span class="err"&gt;END_VAR&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;In your program, you now have both the "individual variable view", the "arrayed view", and the "AT" addressing. Here is example code to show that both "views" really work on the same data.&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="nt"&gt;MAIN&lt;/span&gt; &lt;span class="nt"&gt;PROGRAM&lt;/span&gt; &lt;span class="nt"&gt;HEADER&lt;/span&gt;
&lt;span class="nt"&gt;PROGRAM&lt;/span&gt; &lt;span class="nt"&gt;MAIN_b223d63214&lt;/span&gt;
&lt;span class="nt"&gt;VAR&lt;/span&gt;
  &lt;span class="nt"&gt;s1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;s2&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;LINT&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
  &lt;span class="nt"&gt;p1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;p2&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;POINTER&lt;/span&gt; &lt;span class="nt"&gt;TO&lt;/span&gt; &lt;span class="nt"&gt;Analog_300_A13EGA10CF001&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
  &lt;span class="nt"&gt;r1&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;REAL&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="nt"&gt;END_VAR&lt;/span&gt;

&lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="nt"&gt;MAIN&lt;/span&gt; &lt;span class="nt"&gt;PROGRAM&lt;/span&gt; &lt;span class="nt"&gt;CODE&lt;/span&gt; &lt;span class="nt"&gt;BLOCK&lt;/span&gt;
&lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="nt"&gt;We&lt;/span&gt; &lt;span class="nt"&gt;can&lt;/span&gt; &lt;span class="nt"&gt;access&lt;/span&gt; &lt;span class="nt"&gt;the&lt;/span&gt; &lt;span class="nt"&gt;same&lt;/span&gt; &lt;span class="nt"&gt;memory&lt;/span&gt; &lt;span class="nt"&gt;area&lt;/span&gt; &lt;span class="nt"&gt;in&lt;/span&gt; &lt;span class="nt"&gt;two&lt;/span&gt; &lt;span class="nt"&gt;ways&lt;/span&gt;
&lt;span class="nt"&gt;globals&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Analog_300&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;arrayed&lt;/span&gt;&lt;span class="cp"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="cp"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Sim_value&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nt"&gt;2&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="nt"&gt;r1&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nt"&gt;globals&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Analog_300&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;entries&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;entry_1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Sim_value&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="nt"&gt;Let&lt;/span&gt; &lt;span class="nt"&gt;us&lt;/span&gt; &lt;span class="nt"&gt;show&lt;/span&gt; &lt;span class="nt"&gt;that&lt;/span&gt; &lt;span class="nt"&gt;the&lt;/span&gt; &lt;span class="nt"&gt;memory&lt;/span&gt; &lt;span class="nt"&gt;layout&lt;/span&gt; &lt;span class="nt"&gt;truly&lt;/span&gt; &lt;span class="nt"&gt;matches&lt;/span&gt;
&lt;span class="nt"&gt;s1&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nt"&gt;SIZEOF&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;globals&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Analog_300&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;entries&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="nt"&gt;s2&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nt"&gt;SIZEOF&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;globals&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Analog_300&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;arrayed&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="nt"&gt;p1&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nt"&gt;ADR&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;globals&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Analog_300&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;entries&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;entry_3&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="nt"&gt;p2&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nt"&gt;ADR&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;globals&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Analog_300&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;arrayed&lt;/span&gt;&lt;span class="cp"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="cp"&gt;]&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Is that close to what you want to do?&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Addressing memory area </title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/b223d63214/?limit=25#fd7b/cc73" rel="alternate"/><published>2022-08-31T10:07:10.826000Z</published><updated>2022-08-31T10:07:10.826000Z</updated><author><name>aivarasutkus</name><uri>https://forge.codesys.com/u/aivarasutkus/</uri></author><id>https://forge.codesys.com67ad3e15ae242c1cb5be7ead185570f27126a0cc</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Like i said, its just a test.&lt;br/&gt;
My structure looks like in picture. You can address it by using %MW or there is another way to address it. My test code was done with symbolic address. If i make break points and go line by line and i write value to Copy tag&lt;br/&gt;
Copy:= ptInt^;// &amp;lt;- here while program is halted &lt;br/&gt;
then this operation writes value from copy tag to tag in test area&lt;br/&gt;
ptInt^.Sim_value :=Copy.Sim_value; //&lt;/p&gt;
&lt;p&gt;This idea comes from simatic where you can reach so called Data blocks with Area Registers (IL). Then you could read and transfer values in you data block&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Addressing memory area </title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/b223d63214/?limit=25#fd7b" rel="alternate"/><published>2022-08-31T09:37:23.774000Z</published><updated>2022-08-31T09:37:23.774000Z</updated><author><name>fajean</name><uri>https://forge.codesys.com/u/fajean/</uri></author><id>https://forge.codesys.comdba45ad89c8686223cff7baac3fb8a3b503e33f3</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;I am a bit confused. The code you provide does not seem to reference your global variables list, there are no "AT" addresses. I do not understand what your intent is with the code at the bottom, or what you mean exactly by "working, too fast rewrites values".&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Addressing memory area </title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/b223d63214/?limit=25#8978/398c" rel="alternate"/><published>2022-08-31T06:55:49.416000Z</published><updated>2022-08-31T06:55:49.416000Z</updated><author><name>aivarasutkus</name><uri>https://forge.codesys.com/u/aivarasutkus/</uri></author><id>https://forge.codesys.comac352c83e9a413c26d0a8d3bd258d3ec091f325a</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Not exactly.&lt;br/&gt;
So i have my custom structure in global variables list. It goes like: &lt;br/&gt;
Analog_300_A13EGA10CF001&lt;br/&gt;
Analog_301_A13EGA20CF001 ect.&lt;br/&gt;
Since Scada system is goes over modbus, variables has to have address.&lt;br/&gt;
So my tag goes like Ana_list.Analog_300_A13EGA10CF001. I cant really use array, because it will impossible to code process.&lt;br/&gt;
And since i have more objects including valves, motors, that makes quite a lot of tags. So i was wondering if i could just copy of my item to HMI to configuration window and then read/write values over it.&lt;br/&gt;
First attempt &lt;/p&gt;
&lt;p&gt;PROGRAM PLC_PRG&lt;br/&gt;
VAR&lt;br/&gt;
    NR : INT; // number tage&lt;br/&gt;
    A,B,C,D : Ana; // test objects&lt;br/&gt;
    Indr: Ana;&lt;br/&gt;
    Copy: Ana;&lt;br/&gt;
    ptInt, ptInt2: POINTER TO Ana;&lt;br/&gt;
    e : BOOL;&lt;br/&gt;
    Before,after1 : real;&lt;br/&gt;
END_VAR&lt;br/&gt;
// program&lt;br/&gt;
CASE NR OF  // selecting object from tag list&lt;br/&gt;
    1: ptInt := ADR(A);&lt;br/&gt;
    2: ptInt := ADR(B);&lt;br/&gt;
    3: ptInt := ADR(C);&lt;br/&gt;
    4: ptInt := ADR(D);&lt;br/&gt;
    ELSE&lt;br/&gt;
        ptInt :=ADR(Indr); // If none selected give spare copy&lt;br/&gt;
END_CASE&lt;br/&gt;
Copy:= ptInt^; // Write values from tag in GVL item to copy  -part working&lt;br/&gt;
Before := Copy.Sim_value; // testing tag&lt;br/&gt;
ptInt^.Sim_value :=Copy.Sim_value; // Writing values from copy to tag inG VL- not working, too fast rewrites values&lt;br/&gt;
After1 :=Copy.Sim_value;// testing tag&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>