<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Pointer adress from another PRG not possible?</title><link href="https://forge.codesys.com/forge/talk/CODESYS-V2/thread/2524c0643c/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/CODESYS-V2/thread/2524c0643c/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/CODESYS-V2/thread/2524c0643c/</id><updated>2020-08-11T07:27:20.866000Z</updated><subtitle>Recent posts to Pointer adress from another PRG not possible?</subtitle><entry><title>Pointer adress from another PRG not possible?</title><link href="https://forge.codesys.com/forge/talk/CODESYS-V2/thread/2524c0643c/?limit=25#23bd/0225" rel="alternate"/><published>2020-08-11T07:27:20.866000Z</published><updated>2020-08-11T07:27:20.866000Z</updated><author><name>hwillems</name><uri>https://forge.codesys.com/u/hwillems/</uri></author><id>https://forge.codesys.com7260c66e4e6ba35fcd7563c19e8764726ce58cfc</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;I thought about that solution, i just am used to avoid global variables. For every "interface" i mostly write a seperate PRG, and because modbus holding registers are like IN_OUT, i wanted to distribute the "address" of the location throughout the rest of my program with a Struct of pointers to that holding register. &lt;/p&gt;
&lt;p&gt;Because i have alot of different information on that modbus, i like to put data that belongs to each other in a Struct which i normally do before consuming it in other places of my program.&lt;/p&gt;
&lt;p&gt;But with "read &amp;amp; write", i wanted to pass around a pointer. &lt;/p&gt;
&lt;hr/&gt;
&lt;p&gt;What i will try next is make a seperate GLOBAL_VAR, and try to make a struct of pointers to that data and see if that works. &lt;/p&gt;
&lt;p&gt;It's a shame i have to work with Codesys V2.3, as Codesys V3.5 is looking so nice regarding structuring the code with many OOP functionalities, pointers to functions etc. Great for making finite state machines in ST. :) &lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Pointer adress from another PRG not possible?</title><link href="https://forge.codesys.com/forge/talk/CODESYS-V2/thread/2524c0643c/?limit=250#23bd" rel="alternate"/><published>2020-08-10T17:41:52.886000Z</published><updated>2020-08-10T17:41:52.886000Z</updated><author><name>aliazzz</name><uri>https://forge.codesys.com/u/aliazzz/</uri></author><id>https://forge.codesys.coma909ef964363d07cea9dcff20ce7663b9e367d65</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Why don't you declare the TestWord as a VAR_GLOBAL ?&lt;br/&gt;
Then you can easily use it in PRG1 &amp;amp; PRG2. &lt;br/&gt;
Just be careful with running PRG1 or PRG2 in a different task of each other.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Pointer adress from another PRG not possible?</title><link href="https://forge.codesys.com/forge/talk/CODESYS-V2/thread/2524c0643c/?limit=25#30fb" rel="alternate"/><published>2020-08-10T14:53:05.731000Z</published><updated>2020-08-10T14:53:05.731000Z</updated><author><name>hwillems</name><uri>https://forge.codesys.com/u/hwillems/</uri></author><id>https://forge.codesys.com10d0ecc4da5e8215ab5dc1303068acf21358252e</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hello, &lt;br/&gt;
I have several (PRG) POU's in my Codesys V2.3 program. &lt;br/&gt;
For example PRG1, and PRG2. &lt;/p&gt;
&lt;p&gt;Because PRG1 contains an adress which is a Modbus Holding memory, i want a pointer towards that adress. &lt;br/&gt;
I have a HMI that can read and write that holding memory adress.(For example speed reference)&lt;/p&gt;
&lt;p&gt;I also have PRG2, which i also want to read and write to that adress. So what i did is:&lt;/p&gt;
&lt;p&gt;In &lt;strong&gt;PRG1&lt;/strong&gt;:&lt;br/&gt;
VAR&lt;br/&gt;
    testword AT %MW5480 : WORD;&lt;br/&gt;
END_VAR&lt;/p&gt;
&lt;p&gt;In &lt;strong&gt;PRG2&lt;/strong&gt;:&lt;br/&gt;
VAR&lt;br/&gt;
ptr_testvar : POINTER TO WORD;&lt;br/&gt;
END_VAR&lt;/p&gt;
&lt;p&gt;ptr_testvar := ADR(&lt;strong&gt;PRG1&lt;/strong&gt;.testword); &lt;/p&gt;
&lt;hr/&gt;
&lt;p&gt;Somehow this doesn't work, i have used pointers alot (for example iterating over Struct members, when all the members are of the same datatype with sizeof()).&lt;/p&gt;
&lt;p&gt;Is every PRG like a separate instance on Codesys VM? And therefore they can't access each others memory on a pointer level? When you use pointer addressing, and keep the dereferencing inside a single PRG it works fine.&lt;/p&gt;
&lt;p&gt;I also tried to create a pointer address in PRG1, and then dereference it in PRG2. That causes an "Access to illegal address! PLC is stopped." popup. &lt;/p&gt;
&lt;p&gt;I could not find any information about this in the Codesys V2.3 Programming Manual. Also could not find how you can initialize a pointer with ADR() other then to call it in the code itself rather than in the initialization phase. &lt;/p&gt;
&lt;p&gt;Is there any way how to do this?&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>