Page 1 of 1

How to prevent an increment gate value from resetting

Posted: Sat Jul 06, 2019 6:13 am
by Janniebunny
Hi There,

I have a REAL gate value which increments on an action to my PLC. If the PLC goes to KO, how could I write code to somehow store the last value and add the new value from the gate once the PLC is OK again? In other words if the PLC resets, the value returns to ZERO, but Winlog still retains the last value. Here is a section of code, it makes the variable "v2" ZERO in stead of retaining the last read gate value. I really look forward to some assistance.

Gate "id2" is the raw gate value, "v2" is the secondary value to enable me to retain the incremented value if "id2" resets to ZERO.

Code: Select all

Global bool devKO;
Global real v2;

Function void main()
#Startup
SetDigGateValue("clear_dash",1,0);

             While (WindowIsOpen())
             
             devKO = IsDeviceCommunicationKo(1,0);
             if(devKO==true) then getKOgateVal();
             else if (devKO==false) then SetNumGateValue("v2",2,v2+GetNumGateValue("id2",2));
             end
             end

        Sleep(20000);
    end
end

Function void getKOgateVal()
v2= GetNumGateValue("id2",2);
end



Re: How to prevent an increment gate value from resetting

Posted: Wed Sep 25, 2019 5:07 am
by Isakovic
Write value into a txt file at the end of while loop and then make logic to read it back when PLC resets.