Activate output for some delay

Hi,
I browsed through the programming guidance and found that TSET and ONTIMER can create a delay.
For my task, i need to check an input tag(TAG1) and activate my output tag(TAG2) for a delay of 5 seconds, could i do like the coding below?

Init:
Onchange “TAG1”, "GOTO Trigger"
Ontimer 1, "GOTO @DELAY()"

Trigger:
IF TAG1@ > 100 THEN
TAG2@ = 1
TSET 1,5
END

FUNCTION DELAY()
TAG2@ = 0
TSET 1,0
ENDFN

Thank you!

Hello Jun,

I will perform testing on this script to verify connectivity. At first glance, this script looks to be what you require.

Have you tested it on your device?

-Kevin

Hi Kevin,
Sorry for late reply, i haven’t tested it on my device. I need to make sure whether my program is good to go then only i perform testing on the device.

Could you share the result with me when you perform testing. Thank you !

Hello Jun,

I am testing the code now, and found that the function is not being passed correctly within the INIT Phase. I am running some tests now, to resolve these issues.

Do you want the delay to be looped if the TAG1 value stays above 100? Or do you want the function Delay to be called once then stops, until the tag rises above 100 again?

The current code i have now is as follows:

Onchange “TAG1”, “GOTO Trigger”
Ontimer 1, “GOTO DELAY”

DELAY:
TAG2@ = 0
TSET 1,0
END

Trigger:
PRINT “START”; TAG1@
IF TAG1@ > 100 THEN
TAG2@ = 1
TSET 1,5
ENDIF
END

I removed the function, as there continues errors when attempting to use the GOTO option.

Please let me know if this satisfies your request.

-Kevin

Hi Kevin,
Thank you for your reply, i can refer to the code above when designing delay.
The function does not work well in INIT Phase, so it means INIT Phase cannot have function inside?

Hello Jun,

After referring with some collegues of mine, I found you can declare functions in the INIT phase. The issue is was the “GOTO” statements within declarations:

Onchange “TAG1”, “GOTO Trigger”
Ontimer 1, “GOTO DELAY”

I removed them, and set the Trigger as a function as well. I tested the code on my machine and confirmed that it worked. The revised code is as follows:

Onchange “TAG1”, “@Trigger()”
Ontimer 1, “@DELAY()”

Function Trigger()
IF TAG1@ > 100 THEN
TAG2@ = 1
TSET 1,5
ENDIF
ENDFN

FUNCTION DELAY()
TAG2@ = 0
TSET 1,0
ENDFN

Please let me know if there are issues with the code above.

-Kevin

1 Like

Hi,
Thanks a lot:blush: