Restart a tag based on user pressing a button

I have a project that is tracking time where users are active, I have wrote this to a tag instead of using in project as multiple people could be using project / reference in other areas and projects as well for informative purposes. I want to give the ability to restart the tag on a button. The Tag itself is an expression tag with the following script:

if(isNull({[.]Seconds Active.value}), 0, if({[~]Break Tags/760ABreak.value} = 1,({[.]Seconds Active.value} + 1 ),{[.]Seconds Active.value}))

It shows zero if no activity and the if they start their shift / go on break / have downtime etc. it keeps up with only their actual production time, user controlled. What I can’t seem to do however is once their shift is over is write the value back to zero, except for restarting the tag, which is fine with me. I’m just not sure how to script that to a button as it doesn’t appear in the “system.tag…” scripting. Is anyone familiar with how to accomplish this?

You can’t just do a system.tag.write to the tag to give it a value of 0? If it won’t let you write to the value, you could nest another if statement inside of this one, linked to a memory tag that you trigger with the button. Have it write 0 to it on change. You can use hasChanged() on the memory tag and script the button to cycle the memory tag off and on based on which state its in when it is pressed.

If you want to disable and then re-enable the tag you can us system.tag.editTag() if your in 7.9.

If your in 8.0 I would assume you can use system.tag.configure() to do the same thing but I haven’t tried it. I know you can create new tags with it and overwrite a current tags configuration. You may need to use it with system.tag.getConfiguration(). I don’t have an 8.0 system available to me right now to test it out though.

1 Like

I thought I would just use the system.tag.write as well but I get the following error message:

Error writing to tag ‘[default]ASSYTags/760A/Seconds Active.value’: Bad_ReadOnly(“Tag value source does not support writing.”)

Even though the tag itself is set in read/write.

Expression tags are read-only regardless of the permissions.

1 Like

So am I just doing this the wrong way? Or is my thought process wrong on the best way to achieve this?

@bpreston’s suggestion to have some other writable memory tag result in the expression tag evaluating to 0 would work.

edit: though you’d have to set it high, let the expression evaluate, then reset it…

1 Like

The set it high and reset was why I was thinking use the hasChanged function in the expression. I assumed it would go high with a change due to the button and then return to 0 on the next scan. Allowing for the reset to happen but making it so you didn’t have to worry about resetting the memory tag, you’d just have to check if it was a 1 or 0 before writing to it when the button is pressed.

1 Like

I gotcha man, I’m just new to this type of working in Ignition so I’m stumbling through it pretty slowly and having to drop and punt on planned build in my head quite a bit.

Hi Kevin, Can you please help us in ignition how to restart a tag based on user pressing a button or any scripting though we refresh tag . Now we are facing issue in indirect tag binding text box field not updated or not properly clear after tag binding . Please suggest any code .