Oops! Reading the above, I see I pasted the last if statement incorrectly. The PLC script should be as follows, not as above, as that would keep setting your output low whenever the count was zero.
if (count > 0) then
-- count down to 0
count = count - 1;
if count <= 0) then
--set your output low after 30 seconds
hSig = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUTxx);
rc = mc.mcSignalSetState(hSig, 0);
end
end
Place this near the end of the PLC script.
The idea is to start counting when you set your output high, then set the output low after 30 seconds, or beforehand via your own code. Once the count is zero, counting stops and the PLC section is skipped by virtue of the opening if statement. Being global, the count variable is seen within the PLC script and any other code you include, wherever that might be.
Allan