IDC Latch with QCODE
I'm writing more of my program with Qcode, and ran across something this morning that might help someone else:
I was trying to get an IDC to latch on with a momentary, rising edge signal, and then stay on when the signal goes off. Easy, using object list and a "latching or/and"
But, when I write what I thought was an equivalent statement in Qcode, the ICD functions as a momentary, and doesn't latch:
Obviously, this is a bad programming practice, because in just about any other structured text programming language, the IDC would become stuck on the first time the input went true, and would never turn off. However, that's NOT what it does. Try it for yourself; when the input goes false, the IDC also goes false, acting like this:
I don't think that those previous two code statements are equivalent, but I guess that's just an IQAN idiosyncrasy. So here's a work-around I came up with using a memorizing channel. It works as advertised as a latching IDC: when the input goes true, the MR channel latches on, and then when a different input goes true, the MR latches off:
Note the use of the ALWAYS TRUE IDC. As it's name suggests, it has a TRUE operator in it's activating channel so that it's always on. This allows the MR to latch to true.
So there you have it, a latching "IDC" in Qcode.
Customer support service by UserEcho
Try using a static local variable in your Qcode to retain the latched state. You can use if/then to manipulate the state. Result will always be your static variable.
Aha! Thank you. I actually didn't know about static local variables until now.
Apparently you can just define static variables at the beginning of the code by simply stating them.
A Latching function is self holding. So this is how i solved it.
My tests shows it act as the Object list version.
It could be a bit of bad practice to have two resulting lines, but in this simple code I let it pass. It's always the last executed Result that sets the output.