def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):
if initialChange or previousValue.value is None:
return
# when value turn off
if not currentValue.value and previousValue.value:
#Tracking time and durations
start_time = None
duration = None
# Get current time
current_time = system.date.now()
# Grab Opc Tags
alarm_value = system.tag.readBlocking([default]DT Fault /Alarm).value
station = system.tag.readBlocking([default]DT Fault /Station 4)
# get the description from alarm value to search the array
Description = system.tag.readBlocking([default]DT Fault /StationAlarmArray/StationAlarmArray_[alarm_value]_/Description)
# Alarm_value greater than 0 Start timers
if alarm_value >= 1:
if start_time is None:
start_time = current_time
else
if start_time is not None
end_time = current_time
duration = system.date.secondsBetween(start_time, end_time)
system.db.runPrepUpdate("""
Insert INTO [dbo].[Dt_LH_Faults]
([Date]
,[station]
,[alarm_value]
,[Description]
,[start_time]
,[end_time]
,[Duration])
Values (GETDATE(),?,?,?,?,?,?)
""",[Date,Station,Fault Idx, Fault Description,Start Time,End Time, Fault Duration], "CAL")
Can anyone help with the error and take a look to see if this is done right new to scripting thanks in advance