<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Maintaining Variable State between calls</title><link href="https://forge.codesys.com/forge/talk/CODESYS-V2/thread/6a879f0ffc/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/CODESYS-V2/thread/6a879f0ffc/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/CODESYS-V2/thread/6a879f0ffc/</id><updated>2020-02-27T22:35:24.089000Z</updated><subtitle>Recent posts to Maintaining Variable State between calls</subtitle><entry><title>Maintaining Variable State between calls</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/6a879f0ffc/?limit=25#a4b5" rel="alternate"/><published>2020-02-27T22:35:24.089000Z</published><updated>2020-02-27T22:35:24.089000Z</updated><author><name>shooter</name><uri>https://forge.codesys.com/u/shooter/</uri></author><id>https://forge.codesys.com3d49d703f9c1edd1d6772e9564b83b372a55352f</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;what version of codesys is used and for what PLC.&lt;br/&gt;
yes the state of a function block can be stored in a structure, but why is that done?&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Maintaining Variable State between calls</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/6a879f0ffc/?limit=25#2e5a" rel="alternate"/><published>2020-02-27T22:35:22.520000Z</published><updated>2020-02-27T22:35:22.520000Z</updated><author><name>hammarbytp</name><uri>https://forge.codesys.com/u/hammarbytp/</uri></author><id>https://forge.codesys.come8638fd7d8d92447e3aaebaba774fac3e1a316b5</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Sorry if this is a basic question, but we are new to CODESYS&lt;/p&gt;
&lt;p&gt;We are currently porting function blocks written in C from a alternative IEC 61131 environment into CODESYS&lt;/p&gt;
&lt;p&gt;One of the things we used to do in the old environment was create a special pin on the function block to store the internal state of the function block instance. So on the 1st call of the function block it would malloc a area of memory and store the pointer on the internal variable pin. So for example if we only wanted to run the function block code once, when a enable pin had gone low to high, we would store the state of enable pin in the internal variable and compare it with the present state of the enable pin to see if it had changed.&lt;/p&gt;
&lt;p&gt;However it feels a bit of a kludge and as we move to CODESYS I feel there must be a better alternative. &lt;/p&gt;
&lt;p&gt;So my question is how, in a C function block, do we maintain the internal state of a function block instance?&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>