<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Array of pointers to output</title><link href="https://forge.codesys.com/forge/talk/CODESYS-V2/thread/b97d307f8e/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/CODESYS-V2/thread/b97d307f8e/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/CODESYS-V2/thread/b97d307f8e/</id><updated>2020-02-27T19:42:30.347000Z</updated><subtitle>Recent posts to Array of pointers to output</subtitle><entry><title>Array of pointers to output</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/b97d307f8e/?limit=25#4b24" rel="alternate"/><published>2020-02-27T19:42:30.347000Z</published><updated>2020-02-27T19:42:30.347000Z</updated><author><name>shooter</name><uri>https://forge.codesys.com/u/shooter/</uri></author><id>https://forge.codesys.com6eebde8fc00995a3711d3e0ce8f8ae8e2e6d8d46</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;a direct connect with an array is impossible, you can NOT make&lt;br/&gt;
VAR&lt;br/&gt;
arrayoutput&lt;span&gt;[0]&lt;/span&gt; at QX0.0 :BOOL;&lt;br/&gt;
etc&lt;br/&gt;
END_VAR&lt;/p&gt;
&lt;p&gt;but you can write a complete word from array to the outputs&lt;/p&gt;
&lt;p&gt;VAR&lt;br/&gt;
maxarrays is ie 5&lt;br/&gt;
arrayout &lt;span&gt;[maxarrays]&lt;/span&gt; array of word;&lt;br/&gt;
arrayoutput &lt;span&gt;[maxarrays,16]&lt;/span&gt; of BOOL;&lt;br/&gt;
output0 AT QW0:WORD;&lt;br/&gt;
output1 ATQW1:WORD;&lt;br/&gt;
etc&lt;br/&gt;
END_VAR&lt;/p&gt;
&lt;p&gt;in program you make&lt;br/&gt;
a loop with&lt;br/&gt;
for B = 1 to maxarrays&lt;br/&gt;
arrayout&lt;span&gt;[B]&lt;/span&gt;:=0; // empty the counter&lt;br/&gt;
for A = 0 to 16&lt;br/&gt;
arrayout&lt;span&gt;[B]&lt;/span&gt;:= arrayout&lt;span&gt;[B]&lt;/span&gt;+ (arrayoutput&lt;span&gt;[B,A]&lt;/span&gt;*EXPT(2,A))  // if output in array is TRUE (1) then add 2 power A&lt;br/&gt;
// &lt;br/&gt;
next A&lt;br/&gt;
next B&lt;br/&gt;
now they are in words&lt;br/&gt;
then&lt;br/&gt;
output0 := arrayout&lt;span&gt;[0]&lt;/span&gt;;&lt;br/&gt;
etc&lt;br/&gt;
this is all straight forward without any pointers, so very flexible and can be used on any type of PLC.&lt;/p&gt;
&lt;p&gt;in util.lib there is&lt;br/&gt;
EXTRACT(in,n)&lt;br/&gt;
 The n-th bit of DWORD in is returned in BOOl&lt;/p&gt;
&lt;p&gt;PACK&lt;br/&gt;
 Up to 8 bits are packed into a byte&lt;/p&gt;
&lt;p&gt;PUTBIT&lt;br/&gt;
 A bit of a DWORD is set to a certain value&lt;/p&gt;
&lt;p&gt;UNPACK&lt;br/&gt;
 A Byte is returned as single bits&lt;/p&gt;
&lt;p&gt;for the rest of this have a look at  w &lt;a class="" href="http://www.oscat.de" rel="nofollow"&gt;www.oscat.de&lt;/a&gt; w  (also english version available.&lt;br/&gt;
get the lib, the pdf and the txt version.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Array of pointers to output</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/b97d307f8e/?limit=25#4962" rel="alternate"/><published>2020-02-27T19:42:29.090000Z</published><updated>2020-02-27T19:42:29.090000Z</updated><author><name>sernevi</name><uri>https://forge.codesys.com/u/sernevi/</uri></author><id>https://forge.codesys.com483c7f70ce26ec02dac667c929928852132c95af</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hi&lt;/p&gt;
&lt;hr/&gt;
&lt;p&gt;outputarray&lt;span&gt;[0]&lt;/span&gt;:=output0;&lt;br/&gt;
this will write the state of the output in the array&lt;br/&gt;
and&lt;br/&gt;
outputarray&lt;span&gt;[0]&lt;/span&gt;:=1;&lt;br/&gt;
this will put a 1 in the array.&lt;/p&gt;
&lt;p&gt;nowhere you say output0:= ????&lt;/p&gt;
&lt;hr/&gt;
&lt;p&gt;=&amp;gt; outputarray&lt;span&gt;[0]&lt;/span&gt; = 1 (array memory of position 0 = 1)&lt;/p&gt;
&lt;p&gt;Ah ok. So with the inverse;&lt;br/&gt;
output0:=outputarray&lt;span&gt;[0]&lt;/span&gt;;&lt;br/&gt;
and&lt;br/&gt;
outputarray&lt;span&gt;[0]&lt;/span&gt;:=1;&lt;br/&gt;
=&amp;gt; output0 (@qx0.0) = 1 (true/high)&lt;br/&gt;
And here write the  state of the array to the output..&lt;/p&gt;
&lt;p&gt;is connecting the array with the adress of the output0. That was what i was after, connecting the output adress to the array. &lt;br/&gt;
I thought it would work either way.&lt;/p&gt;
&lt;p&gt;This atleast solved that problem and i think i understand the difference how Codesys handles local-/temporary memory and in/output adresses. I just need to keep track of how i want it to function.&lt;/p&gt;
&lt;p&gt;Thanks again, br&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Array of pointers to output</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/b97d307f8e/?limit=25#c89d" rel="alternate"/><published>2020-02-27T19:42:25.575000Z</published><updated>2020-02-27T19:42:25.575000Z</updated><author><name>shooter</name><uri>https://forge.codesys.com/u/shooter/</uri></author><id>https://forge.codesys.comcb6b597fdc71ca9d3eed84f21c26ad871f63ddeb</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;and sorry chris in your first post the sequence was wrong ( i did not see this as it was all in one line.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Array of pointers to output</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/b97d307f8e/?limit=25#26d0" rel="alternate"/><published>2020-02-27T19:42:24.308000Z</published><updated>2020-02-27T19:42:24.308000Z</updated><author><name>shooter</name><uri>https://forge.codesys.com/u/shooter/</uri></author><id>https://forge.codesys.com45c3476a70c24d5d60973170e6a89cc5013b06b8</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;outputarray&lt;span&gt;[0]&lt;/span&gt;:=output0;&lt;br/&gt;
this will write the state of the output in the array&lt;br/&gt;
and&lt;br/&gt;
outputarray&lt;span&gt;[0]&lt;/span&gt;:=1;&lt;br/&gt;
this will put a 1 in the array.&lt;/p&gt;
&lt;p&gt;nowhere you say output0:=  ????&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Array of pointers to output</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/b97d307f8e/?limit=25#0ef4" rel="alternate"/><published>2020-02-27T19:42:20.777000Z</published><updated>2020-02-27T19:42:20.777000Z</updated><author><name>sernevi</name><uri>https://forge.codesys.com/u/sernevi/</uri></author><id>https://forge.codesys.com925a01f4e498eca2ded199b1d6cd073d2d6be01f</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Sorry for my late reply.&lt;br/&gt;
The reason i started thinking of using pointers was that i could not get my program to work as i wanted.&lt;/p&gt;
&lt;p&gt;However, when i tested what you wrote &lt;br/&gt;
 output0:= outputarray&lt;span&gt;[0]&lt;/span&gt;;&lt;br/&gt;
output1:=outputarray&lt;span&gt;[1]&lt;/span&gt;;&lt;/p&gt;
&lt;p&gt;tested by&lt;br/&gt;
outputarray&lt;span&gt;[0]&lt;/span&gt;:=1;&lt;br/&gt;
(gave output0 = true)&lt;/p&gt;
&lt;p&gt;that worked. but what i wrote originally was&lt;br/&gt;
outputarray&lt;span&gt;[0]&lt;/span&gt;:=output0;&lt;br/&gt;
and&lt;br/&gt;
outputarray&lt;span&gt;[0]&lt;/span&gt;:=1;&lt;br/&gt;
(did not give output0 = true)&lt;br/&gt;
And i could not understand why it didnt work.. To be frank, I still dont understand why the inverted declaration (as in yours') works but not mine.&lt;br/&gt;
I feel i have missed something basic with this. If you got the time i would be very grateful if you could explain it.&lt;/p&gt;
&lt;p&gt;Thanks a lot.&lt;/p&gt;
&lt;p&gt;br&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Array of pointers to output</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/b97d307f8e/?limit=25#60b8" rel="alternate"/><published>2020-02-27T19:42:19.526000Z</published><updated>2020-02-27T19:42:19.526000Z</updated><author><name>shooter</name><uri>https://forge.codesys.com/u/shooter/</uri></author><id>https://forge.codesys.com0a5be086b80a7c15952819b6dfffd114a1bdc73f</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;why use pointers?&lt;/p&gt;
&lt;p&gt;just say output0:= outputarray&lt;span&gt;[0]&lt;/span&gt;;&lt;br/&gt;
output1:=outputarray&lt;span&gt;[1]&lt;/span&gt;;&lt;br/&gt;
etc.&lt;br/&gt;
pointers can be used but make the program only possible on one type of controller.&lt;br/&gt;
in the GLOBAL VAR list just say output0 at %QX0.0:BOOL;&lt;br/&gt;
etc&lt;br/&gt;
you can also do this in the PLC config but this is easier. and will print in your program.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Array of pointers to output</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/b97d307f8e/?limit=25#9263" rel="alternate"/><published>2020-02-27T19:42:15.974000Z</published><updated>2020-02-27T19:42:15.974000Z</updated><author><name>sernevi</name><uri>https://forge.codesys.com/u/sernevi/</uri></author><id>https://forge.codesys.com0318c55b15cfba4685db41a46d78e390e11e40c8</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I'm fairly new to this and i have been struggeling with something for a few days now.&lt;br/&gt;
I searched the forum for similar cases, but could not find anything. The closest i found was this thread ( l &lt;a class="" href="http://forum.codesys.com/viewtopic.php?t=1725" rel="nofollow"&gt;viewtopic.php?t=1725&lt;/a&gt; l ). Tried something similar with Pointer to Bool instead of Int, but that didn't work&lt;/p&gt;
&lt;p&gt;I want to create an array of pointers to my boolean outputs. It shouldnt be so complicated but for some reason i'm not able to get it working.&lt;/p&gt;
&lt;p&gt;The application is basically a learning program. I want to trigger inputs and save them in the order they are triggered. This should then be mapped to the corresponding outputs.&lt;br/&gt;
I.e. pseudo code arrayin&lt;span&gt;[1]&lt;/span&gt;= input1 at%ix0.0, arrayin&lt;span&gt;[2]&lt;/span&gt; = input2 at%ix0.1&lt;br/&gt;
That is then mapped to output arrayout&lt;span&gt;[1]&lt;/span&gt; = output1 at%qx0.0 arrayout&lt;span&gt;[2]&lt;/span&gt; = output2 at%qx0.1&lt;br/&gt;
Very simple and straight forward in my head.&lt;/p&gt;
&lt;p&gt;However, every way i have tested it it either becomes a programming error (cannot convert pointer to bool sort of) or that the pointer "doesnt work". &lt;/p&gt;
&lt;p&gt;Tested creating a standard array of bool and added output1 and output2 to it, when i then try to activate one of them (just arrayout&lt;span&gt;[1]&lt;/span&gt;:=TRUE;) it gives the True value to arrayout&lt;span&gt;[1]&lt;/span&gt; but not the adress for output1. Thats why i thought i must need an array of pointers (which point to my outputs/inputs).&lt;/p&gt;
&lt;p&gt;I hope atleast someone understands what i mean..&lt;/p&gt;
&lt;p&gt;Thanks in advance, br Chris&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>