How to prevent an increment gate value from resetting

Discussion about Code Builder Builder and Winlog language support.
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()

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


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

Return to “Code - Code Builder”

Who is online

Users browsing this forum: No registered users and 1 guest