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 Sun Oct 21, 2018 7:44 am

All times are UTC+01:00




Post new topic  Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Wed Sep 19, 2018 1:02 pm 
Offline

Joined: Tue Sep 11, 2018 7:59 am
Posts: 5
Hello ,

I Have Discovered Issue(not really but its not good too) In Old Code That,

IF Any one of the Variable is Changed
THEN writetable :=True

it means Every single time it will go and write value in table, I want to improve that in some better way.
If Any one Could suggest Anything it will be great. :D

Thank You


Top
   
PostPosted: Wed Sep 19, 2018 8:33 pm 
Offline
User avatar

Joined: Fri Jan 19, 2018 3:38 pm
Posts: 54
Please explain your purpose/problem a bit more, some more information on what you are trying to achieve would be welcome :wink:

_________________
https://github.com/Aliazzzz


Top
   
PostPosted: Thu Sep 20, 2018 5:44 am 
Offline

Joined: Tue Sep 11, 2018 7:59 am
Posts: 5
hello Aliazzz,

I explain The problem here :

if at least one parameter changes, send parameters table to Database

IF( (
mParameter1 <> pParameter1 OR
mParameter2 <> pParameter2 OR
mParameter3 <> pParameter3 OR
mParameter4 <> pParameter4 OR
mParameter5 <> pParameter5 ))
THEN
writetable := TRUE;

END_IF

- I Want To improve this logic because For 5 parameter its okk but Now i have more than 20 so its not wise to call write table everytime.

Thank You,


Top
   
PostPosted: Thu Sep 20, 2018 3:03 pm 
Offline

Joined: Thu Aug 04, 2011 11:16 am
Posts: 84
Hi,
one possibility would be to use a FOR loop and Arrays. Something like this:

Code:
VAR
   mParameter : ARRAY [0..ArrayLength] OF INT := [1,2,3,4,5];
   pParameter : ARRAY [0..ArrayLength] OF INT := [1,2,3,7,5];
   counter : INT;
   writetable : BOOL;
END_VAR
VAR CONSTANT
   ArrayLength   : INT := 4;
END_VAR


Code:
FOR counter := 0 TO ArrayLength DO
   IF mParameter[counter] <> pParameter[counter] THEN
      writetable := TRUE;
      EXIT;
   END_IF
END_FOR


Top
   
PostPosted: Thu Sep 20, 2018 3:47 pm 
Offline
User avatar

Joined: Fri Feb 10, 2017 6:12 am
Posts: 56
Struct + pointer + mem utils + crc.


You do not have the required permissions to view the files attached to this post.


Top
   
PostPosted: Thu Sep 20, 2018 5:14 pm 
Offline
User avatar

Joined: Fri Jan 19, 2018 3:38 pm
Posts: 54
I'd go with a crc approach as this is way more flexible with regards of your array/tablesize.
If the current crc (of your table) differs from the newly calculated crc then you trigger the writing of the table.
The example @Viacheslav Mezentsev demonstrates this mechanic.

_________________
https://github.com/Aliazzzz


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

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 2 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