JavaScript Scripting Issue – Writing Integer to Internal Tag Prevents Bit Toggle

0
Hi everyone, I'm working on JavaScript scripting in WinCC Unified and encountered an issue when handling tag operations. I need to: Read the status of two tags (one internal and one external). Toggle the external bit tag. Write an integer value to the internal tag. I can successfully toggle the bit tag, but when I add the step to write an integer value to the internal tag, the bit toggle stops working. Here’s my script:   export function gfxStateContentboard5_1_OnTapped(item, x, y, modifiers, trigger) { let ToggleTag = Tags("Machine_VFD_Cmd_ManModeSelected"); let MachineSts = tags("MachineState");   let ToggleTagVal = ToggleTag.Read(); //............................... if (ToggleTagVal) {    ToggleTag.Write(false); MachineSts.write(4); } else {    ToggleTag.Write(true);  MachineSts.write(1); } }
asked
2 answers
0

Please also check if Expression functionality can be used > this often avoids scripting and ensures best performance

answered
0

Hi Brigitte,

Thanks for your support. Could you please clarify how I can ensure that the Expression functionality can be used? I can toggle a tag bit, but when I try to write to a register and toggle the bit, the script does not work.

 

let ToggleTag = Tags("Machine_VFD_Cmd_ManModeSelected");

let MachineSts = tags("MachineState");

 

let ToggleTagVal = ToggleTag.Read();

 

if (ToggleTagVal) {   

ToggleTag.Write(false);

MachineSts.write(4);

} else {   

ToggleTag.Write(true); 

MachineSts.write(1);

}

Best regards,

answered