How to prevent an increment gate value from resetting

Discussion about Code Builder Builder and Winlog language support.
Post Reply
Janniebunny
Posts: 3
Joined: Fri Jun 15, 2018 6:33 am

How to prevent an increment gate value from resetting

Post 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



Isakovic
Posts: 12
Joined: Tue Jun 14, 2016 10:01 am

Re: How to prevent an increment gate value from resetting

Post 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.

Post Reply