"write table" Trigger Issue

ANU
2018-09-19
2018-09-20
  • ANU - 2018-09-19

    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.

    Thank You

     
  • aliazzz

    aliazzz - 2018-09-19

    Please explain your purpose/problem a bit more, some more information on what you are trying to achieve would be welcome

     
  • ANU - 2018-09-20

    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,

     
  • singleton - 2018-09-20

    Hi,
    one possibility would be to use a FOR loop and Arrays. Something like this:

    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
    
    FOR counter := 0 TO ArrayLength DO
       IF mParameter[counter] <> pParameter[counter] THEN
          writetable := TRUE;
          EXIT;
       END_IF
    END_FOR
    
     
  • Anonymous - 2018-09-20

    Originally created by: Viacheslav Mezentsev

    Struct + pointer + mem utils + crc.

    IMG: 2018

     
  • aliazzz

    aliazzz - 2018-09-20

    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.

     

Log in to post a comment.