Can't figure out why my script doesn't work

I've written the following script in the script console, and it works:
filePath = "C:\FlowReport.csv"
tagsToRead = ["[edge]PLC Tags/FlowTotalsLog/Main", "[edge]PLC Tags/FlowTotalsLog/Aux1", "[edge]PLC Tags/FlowTotalsLog/Aux2", "[edge]PLC Tags/FlowTotalsLog/Aux3", "[edge]PLC Tags/FlowTotalsLog/FRidx"]
tagData = system.tag.readBlocking(tagsToRead)
mainVal = tagData[0].value
aux1Val = tagData[1].value
aux2Val = tagData[2].value
aux3Val = tagData[3].value
index = tagData[4].value
data = str(index) + "," + str(mainVal) + "," + str(aux1Val) + "," + str(aux2Val) + "," + str(aux3Val) + '\r\n'
system.file.writeFile(filePath, data , True)

I copied and pasted the code in my project library here and defined it as a function called "append"

I then added a script to a tag to trigger this script whenever the value changes and is true.

When I execute the script in the script console, it works. I creates the file and populates the data. But when I trigger the tag on, nothing happens. I don't get any error messages in the log. Just, nothing happens. I have no idea what to do next.

There's a few things that could be going wrong here.

  1. the project you defined the "append" function in needs to be configured as the "Gateway Scripting Project" in order to be accessible from a tag event script. See Project Library | Ignition User Manual

  2. you're now running the script on the Gateway rather than in your Designer, which could be a different computer and certainly has different permissions implications since Ignition is running as a service. Are you looking for the file on the C: drive of whatever computer the Gateway is running on?

  3. filePath = "C:\FlowReport.csv"
    I'm a little confused this worked at all without two backslashes, i.e.
    filePath = "C:\\FlowReport.csv"

I'm not sure if this makes a difference or not, but this is an Ignition Edge app, not full blown Ignition. I'm not seeing an option for the Gateway Scripting Project. Probably because Edge can only have one project anyway.

I also tried making this a Gateway Tag Change script and I still have issues. It's not creating the file, and when I look under Gateway Scripts under Tag Change, it says it executed successfully.

I figured out why.

The Gateway resides on a VM, not my local machine. Of course it's not going to put the file on my local machine. It's going to put it on the Gateway. Which it did.

That's what I was suggesting in point 2 of my response :slight_smile:

3 Likes