I've written a script that executes on the Gateway to synchronize the PLC time with the Gateway every 30 seconds. This is an Ignition Edge application so the Gateway will reside on the terminal that is actually on-site. The customer has provided the PLC program with the understanding that we are not going to change it at all. They currently have a Panelview Plus with a screen where the Year, Month, Day, etc. tags are all numeric entries and then a button triggers the PLC to change the time. I thought it would be a better solution to just set the date and time in the terminal and have it automatically update the PLC at a slow (but regular) interval. What I'm running into is I have an enable in the data structure so it gives the administrator the option to disable the code. What I'm running into is I have a conditional IF statement that actually triggers the synchronize bit if the enable bit is on, or skip that part if the enable is off. I also use the sleep to set the synchronize bit back to false since changing the program is off the table. Here's my code:
DateTimePath = "[edge]PLC Tags/DateTime/"
SyncEnable = system.tag.readBlocking(DateTimePath + "SyncEnable")
SetMonth = system.date.getMonth(system.date.now()) + 1
SetDay = system.date.getDayOfMonth(system.date.now())
SetYear = system.date.getYear(system.date.now())
SetHour = system.date.getHour24(system.date.now())
SetMinute = system.date.getMinute(system.date.now())
SetSecond = system.date.getSecond(system.date.now())
paths = [DateTimePath + "SetMonth",
DateTimePath + "SetDay",
DateTimePath + "SetYear",
DateTimePath + "SetHour",
DateTimePath + "SetMinute",
DateTimePath + "SetSeconds"]
values = [SetMonth,
SetDay,
SetYear,
SetHour,
SetMinute,
SetSecond]
if SyncEnable:
from time import sleep
system.tag.writeBlocking(paths, values)
system.tag.writeBlocking(DateTimePath + "SetSystemDate",True)
sleep(3)
system.tag.writeBlocking(DateTimePath + "SetSystemDate",False)
I'm not sure where I'm going wrong. What's happening right now is all the code is executing even if SyncEnable is false. I'm not exactly an expert in Python, but everything I'm reading shows I did the if statement correctly.