ONchange not working with DI tag

Here is a piece of my script, this tag is a digital input and type Boolean. It is not entering that Fill_Downtime function. I’ve tried it with different tags, even changed the original tag to a memory tag and manually changed it and was able to enter the function properly.

No errors are thrown it just does not seem to recognize a change even though I am watching the tag change in the values screen. What could be happening?

OnChange “AMP_1300CountFill03_Run”,"@Fill_Downtime()"
Function Fill_Downtime()
@LOG(‘Filler Downtime Function’)
Print ‘Filler Downtime’
If (AMP_1300CountFill03_Run@= 0) Then //Line stopped
down_start_time% = GETSYS PRG, “TIMESEC”
//filler_dnts@=TIME$
RETURN
ELSE
down_end_time% = GETSYS PRG, “TIMESEC”
downtime% = down_end_time% - down_start_time%
filler_downtime@ = filler_downtime@+downtime%
ENDIF
ENDFN

I’m not sure what happened but this has started to work properly, I will keep watching it but I guess this post can be closed for now.

Hi @garyR,

Thanks for the update. The script looks fine, so i’m not sure why it wasn’t working. Let me know if you have any other problems.

This problem is appearing again, don’t really know where to start debugging. I’ve tried creating new tags and deleting the old ones, rewriting the function and other parts of the script. Do you have any suggestions on where to look? I’m capturing the tag via MQTT so I know its changing just not entering the function still. I’ve found this error occurring on another device so I’m thinking its related to the script but I don’t know where to look.

Hi @garyR,

I’m sorry to hear that. Can you create a backup of the Ewon using eBuddy and check “Include Support Files” please so I can check the script, settings, and logs?

Thanks,

Kyle

I have had issues in the past with some ONCHANGE calls. The way I fixed them was to create a function that was called on a timer. Inside of that function then I setup the ONCHANGE calls. Then I set a timer to wait 30 seconds then call the ONCHANGE setup function and then set the timer to 0 so it does not run again. This way the Flexy could startup, get running, connect to the plc and then do the ONCHANGE watching.

1 Like

@tedsch2 looks to be working, thanks.

Code I added to is below in case anyone else has this issue -

TSET 3, 30
ONTIMER 3, “@changes()”

Function changes()
ONCHANGE “AMPCountFill03_Run”,"@Status_Change()"
TSET 3,0
Endfn

1 Like

You are welcome.

Just a little nudge HMS. 4 timer limit in the basic code.