CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum by 3S-Smart Software Solutions GmbH | A member of the CODESYS Group
Deutsche Version English version russian version 
It is currently Mon May 20, 2019 5:49 pm

All times are UTC+01:00

Post new topic  Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Wed Jun 13, 2018 7:02 pm 

Joined: Wed Jun 13, 2018 4:11 pm
Posts: 1
hello, new to CODESYS.

I've learned how to pack an array with addresses so i can indirectly address them a use them in loops. the problem i have now is that i dont understand how to unpack the array to an output address.

{putting stuff in an array}
CH0ReadDataArray AT %IW12 : ARRAY[0..127] OF BYTE;
WordArray : ARRAY[0..127] OF WORD

{pack Bytes into Words}
for i:0 to 127 do
end for;

Now how do i fill %QW406 through %QW469 with the contents of WordArray[0..127]??????

PS. i want to do this quickly and efficiently. i don't want to:
%QW406 := WordArray[0];
%QW407 := WordArray[1];

PostPosted: Tue Jun 19, 2018 11:51 am 
Frequent User
Frequent User

Joined: Fri Sep 02, 2011 8:02 pm
Posts: 302
Something like the code below should work. Double check that your pointer math is working correctly and you don’t go one too many points in the loop, etc.


pWrd := ADR(%QW406);

FOR J := 0 TO 127 DO
   pWrd^ := WordArray[J];
   pWrd := pWrd + SIZEOF(WORD);

Code not tested and from memory!

PS execution time is actually longer than if you explicitly list out all of the assignments like you don’t want to.

Scott Cunningham
KEB America, Inc.

Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 2 posts ] 

All times are UTC+01:00

Who is online

Users browsing this forum: No registered users and 6 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited