How to prevent an increment gate value from resetting

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

How to prevent an increment gate value from resetting

Postby Janniebunny » Sat Jul 06, 2019 6:13 am

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

Postby Isakovic » Wed Sep 25, 2019 5:07 am

Write value into a txt file at the end of while loop and then make logic to read it back when PLC resets.


Return to “Code - Code Builder”

Who is online

Users browsing this forum: No registered users and 2 guests