I am reading a tag in my PLC which is a count down timer, in seconds.
I need to show this countdown time on a display, but I need the format to change to HH:MM:SS. How can I do this? I thought about using a expression binding and use “runScript” to run a gateway script, but I have to constantly pass the seconds to the script. the runScript expression seems like you have to pass it string text? Or can I pass a tag?
Now that v7.7 is out, I thought about adding a script on the tag directly, which would create the HH:MM:SS string each time the value changed, I would dump that into another string tag.
Alright so I came up with a solution by adding a script to the tag directly. Works, but need to put it through it’s paces. Here is the code:
m, s = divmod(currentValue.value, 60)
h, m = divmod(m, 60)
hhmmss = "%d:%02d:%02d" % (h, m, s)
system.tag.write("[.]remainHHMMSS", hhmmss)
Little concerning as I added this to my UDT definition and all my SQLtags proceeded to time out for an extended period of time (fairly complex UDT with a large number of SQLtags). Definitely would be cautious doing this in a production environment.
Is there a better way to to this in ignition 7.9/8? I need a simple countdown timer formatted as h:mm:ss between two timestamps (time remaining until shift change in my case).
I was hoping to be able to accomplish this with an expression.
Note that it's worth a disclaimer that this will "break" if you overflow 24 hours. You can solve that with an additional if statement and more complex logic, but I'll leave that for the reader.
No particular reason, other than expression functions are (were) fairly rigorous in their expected types. There’s a pending change for 8.0 that will make things like that work as expected, as much as possible.
If your talking doing the same thing but through a script it is identical but using script functions. You would need to do a system.tag.read(tag path).value to get your seconds and store it in a variable but then you would insert your variable into the script. Then it depends where the script is to how to put it in the label.
time = system.date.format(system.date.addSeconds(system.date.midnight(system.date.now()),insert your seconds val here),"HH:mm:ss")