CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum
Deutsche Version English version russian version 
It is currently Tue Sep 25, 2018 5:53 am

All times are UTC+01:00




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

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.

example:
{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
WordArray[i]:=(BYTE_TO_WORD(CH0ReadDataArray[i])*256)+BYTE_TO_WORD(CH0ReadDataArray[i]);
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];
.
.
.
etc.


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

Joined: Fri Sep 02, 2011 8:02 pm
Posts: 288
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.

Code:
PWrd : POINTER TO WORD;

pWrd := ADR(%QW406);

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


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.
www.kebblog.com
www.kebamerica.com


Top
   
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 1 guest


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