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)
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.
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")