Hi all,
Trying to work out the best way to handle some scripting…
I have a UDT for an AB Logix PLC, which handles diagnostic information and also has date and time information from the PLC in it. This tag structure also has the ability to store a new date and time, and then send it back to the PLC to set the PLC time. This UDT structure is all working well.
Next, I have a script which is currently stored in the project script library. I pass it a tag path to one of those UDT instances, and it gets the current PC time and synchronises the target PLC clock with that PC time. I can call this script using a button on a client, which works just fine.
But here’s where my current approach doesn’t work. Within the UDT, I’ve got a bool tag called “AutoSyncEnable”, and two int tags “AutoSyncHour” and “AutoSyncMinute”. The idea is that if Auto Sync is enabled, it will automatically sync the PLC time at [AutoSyncHour]:[AutoSyncMinute] every day. To trigger this, I have a tag change event on the CurrentMinute tag - so every time the PLC clock’s minute changes, I will check if Auto Sync is enabled, and if so, whether it’s the right time to do the Auto Sync. If it is, I call the same script as before. However, I’ve learned that I can’t call a project library script from a UDT tag value change event.
I could just duplicate the script right there in the UDT definition, as it’s only writing to other tags within that UDT anyway - but as soon as I find myself copying and pasting a script, I start to think that maybe I should be doing this differently. Any suggestions?