I have this script:
def getCSVItem1():
#if newValue.getValue() == True:
import csv
from java.util import Date
runstartTime = system.tag.readBlocking("[default]SystemA/Item1/IgnitionValues/RunTimes/RunStartTime")
runstartTime = runstartTime[0].value
# Define the start and end times for the query
previousRunStartTime = system.tag.read("SystemA/Item1/IgnitionValues/RunTimes/PreviousRunStartTime").value
RunEndTime = system.tag.read("SystemA/Item1/IgnitionValues/RunTimes/RunEndTime").value
# Define the tag paths
tagPaths = [
"SystemA/Item1/Actual_Weight",
"SystemA/Item1/Machine_Status",
"SystemA/Item1/Maximum_Weight",
"SystemA/Item1/Minimum_Weight",
"SystemA/Item1/Open_Lid_Kickoff",
"SystemA/Item1/Preset_Number",
"SystemA/Item1/Standard_Deviation_LH",
"SystemA/Item1/Standard_Deviation_LL",
"SystemA/Item1/Tare",
"SystemA/Item1/Target_Weight",
"SystemA/Item1/Total_Scanned",
"SystemA/Item1/UnderWeight_Count",
]
# Extract the short names from the tag paths
headers = ['Timestamp'] + [path.split('/')[-1] for path in tagPaths]
# Query the tag history
history = system.tag.queryTagHistory(paths=tagPaths, startDate=previousRunStartTime, endDate=RunEndTime)
# Get the current date and time and format it to be safe for file names
currentDateTime = system.date.format(system.date.now(), "yyyy-MM-dd_HH-mm-ss")
# Define the output CSV file path with the formatted date and time
outputFilePath = "C:\\Users\\Account1\\Documents\\Item1-" + currentDateTime + ".csv"
# Write the history data to a CSV file
with open(outputFilePath, 'wb') as csvfile:
writer = csv.writer(csvfile)
# Write header row
writer.writerow(headers)
# Iterate over the dataset rows
for row in range(history.getRowCount()):
# Write timestamp and values for each tag
timestamp = history.getValueAt(row, 0) # Assuming timestamp is in the first column
values = [history.getValueAt(row, col) for col in range(1, history.getColumnCount())]
writer.writerow([timestamp] + values)
If I run it using script console it works fine.
However when I run it using Gateway Script Console on a tag change it just returns a csv file with the header but after that its blank. Anyone have any ideas?