# Making a CSV files with data of Fibre rolls

**URL:** <https://forum.inductiveautomation.com/t/making-a-csv-files-with-data-of-fibre-rolls/63560>\
**Category:** Ignition\
**Created:** [August 29, 2022, 12:19pm UTC](https://forum.inductiveautomation.com/t/making-a-csv-files-with-data-of-fibre-rolls/63560 "2022-08-29T12:19:03Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matthias\_Longueville](https://avatars.discourse-cdn.com/v4/letter/m/7ba0ec/32.png) [@Matthias\_Longueville](https://forum.inductiveautomation.com/u/Matthias_Longueville)\
**Post date:** [August 29, 2022, 12:19pm UTC](https://forum.inductiveautomation.com/t/making-a-csv-files-with-data-of-fibre-rolls/63560/1 "2022-08-29T12:19:03Z")

</div>

Dear all,  
I am quiet new in the Ignition world.  
I work for a textile company. We produce rolls of geotextile.  
Now I want to make a CSV file where I can see some data off each roll.  
My script is as followed:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/7/f75ae3cf7950017fd16691fec7503f275684a727.png)

I already get a CSV file, but its not each roll. It makes different lines for the same roll:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/8/486fd6d992215037c4e9c5e6ae9a944e10e96d47.png)

Does somebody know what I do wrong?

Thanks for the help.

Kind regards

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [August 29, 2022, 1:58pm UTC](https://forum.inductiveautomation.com/t/making-a-csv-files-with-data-of-fibre-rolls/63560/2 "2022-08-29T13:58:06Z")

</div>

There are a few things that I see.

1. This is in a Gateway Timer Event, which may or may not be the correct event type. Since the very first thing you do is look at the Reset tag, I would probably recommend that this script be placed in a Tag Change Script.
2. You have the delay set a 5ms and you are using `system.tag.write()` to write the value.  
a. 5ms is quite fast, what is the expected cycle time? Generally I would expect a timer event to run at about half the expected cycle time.  
b.`system.tag.write()` is not only deprecated, but is also an asynchronous function. This is the real gotcha here, as almost certainly the timer is re-occurring before the write actually occurs.

I would suggest that you move this to a Tag Change event on the Reset tag. Then change your script to look something like the following:

```python
if not initialChange and newValue.getValue():
   import csv
   #set a list of tag paths of all tag values needed in script and read them all at once
   tagPaths = ["[Bontexgeo Kft]Rol lengte laatste rol (m)","[Bontexgeo Kft]Gewicht laatste Rol (kg)"]
   #system.tag.readBlocking() returns a list of qualified values so this builds a list with just the values
   tagValues = [qValue.value for qValue in system.tag.readBlocking(tagPaths)]

   headerValues = ["Datum","Tijd","LENGTE","GEWICHT"]
   #Get the current date, format it and add to the front of the tagValues list
   now = system.date.now()
   tagValues = [system.date.format(now,"dd/MM/yyyy"),system.date.format(now,"HH:mm:ss")] + tagValues
   #crete the CSV file
   fileName = r"D:\TIS_TEST_{}.csv".format(now,"yyMMdd")
   csv.createCSV(fileName, headerValues, tagValues)
   #reset the "reset" tag. system.tag.writeBlocking blocks the thread until the write has finished.
   system.tag.writeBlocking([str(event.getTagPath())],[0])

```

This script does exactly the same thing as your script, I have made some changes to streamline it, but the result of the script should be the same.

1. Always read as many tags as you can at once. `system.tag.readBlocking()` takes a list of tag paths and reads all tags in a single call. This is much faster than making individual calls as each call will block the thread (prevent further execution) until the read is complete. This is also true of the deprecated `system.tag.read()` funciton.
2. When building a new list, there is no reason to append the items, just initialize the list inline as I have done.
3. To initialize the tagValues list I use a list comprehension, in expanded form that code would look like:

```auto
tagValues = []
for qValue in system.tag.readBlocking(tagPaths):
    tagValues.append(qValue.value)

```

1. Rather than using the csv package as you are, you may want to consider using the `system.dataset.exportCSV()` function instead. I have no reason for this other than it is a function that is native to Ignition. Of course if you’re going to use a dataset function, you could also use the `system.dataset.exportExcel()` if you need this in an excel format, rather than just a csv.

---

<div class="post-metadata">

**Author:** ![Matthias\_Longueville](https://avatars.discourse-cdn.com/v4/letter/m/7ba0ec/32.png) [@Matthias\_Longueville](https://forum.inductiveautomation.com/u/Matthias_Longueville)\
**Post date:** [August 30, 2022, 5:51am UTC](https://forum.inductiveautomation.com/t/making-a-csv-files-with-data-of-fibre-rolls/63560/3 "2022-08-30T05:51:55Z")

</div>

Hi Irose,

Thanks for the answer.  
Sorry but I am really new in this world. I have not really a background in this.  
If I understand good I need to copy your script here:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/4/f4cfce22b3124d9e0fc5c2772ecef93d6533be8a.png)

What do I need to put in the Tags tab:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/d/fd0d83169deebd0a6650f588252c72d33fdddd7d.png)

Again, thanks for your time. I appreciate it.

Kind regards

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [August 30, 2022, 7:10am UTC](https://forum.inductiveautomation.com/t/making-a-csv-files-with-data-of-fibre-rolls/63560/4 "2022-08-30T07:10:02Z")

</div>

You’ll also need to add the tag you want to monitor (`[Bontexgeo Kft]Reset`) to the list of tag paths (your last screenshot).

And there’s a small mistake in the script: line 11, it should be `tagValues`, not `tagValus`.

---

<div class="post-metadata">

**Author:** ![Matthias\_Longueville](https://avatars.discourse-cdn.com/v4/letter/m/7ba0ec/32.png) [@Matthias\_Longueville](https://forum.inductiveautomation.com/u/Matthias_Longueville)\
**Post date:** [August 30, 2022, 7:15am UTC](https://forum.inductiveautomation.com/t/making-a-csv-files-with-data-of-fibre-rolls/63560/5 "2022-08-30T07:15:06Z")

</div>

Hi Pascal,

Thanks for the reply.  
Ok I added this in the tag tab.  
When I try to run the script in the script console I have next fault:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/4/04d1b42fe1c5cbc67c4ced3b6344a7514f94ca55.png)

Kind regards

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [August 30, 2022, 7:22am UTC](https://forum.inductiveautomation.com/t/making-a-csv-files-with-data-of-fibre-rolls/63560/6 "2022-08-30T07:22:46Z")

</div>

This script won’t work in the script console. It was made for a gateway tag change script, and that’s where it’s supposed to go. The script console doesn’t know what `InitialChange` and `newValue` are.

That being said, the error returned here is a syntax error, which means it won’t work anywhere. In this case, it seems you missed the last parenthesis when copy/pasting.

edit: This should work in the console:

```python
import csv

trigger = system.tag.readBlocking(["[Bontexgeo Kft]Reset"])[0].value

if trigger:
   #set a list of tag paths of all tag values needed in script and read them all at once
   tagPaths = ["[Bontexgeo Kft]Rol lengte laatste rol (m)","[Bontexgeo Kft]Gewicht laatste Rol (kg)"]
   #system.tag.readBlocking() returns a list of qualified values so this builds a list with just the values
   tagValues = [qValue.value for qValue in system.tag.readBlocking(tagPaths)]

   headerValues = ["Datum","Tijd","LENGTE","GEWICHT"]
   #Get the current date, format it and add to the front of the tagValues list
   now = system.date.now()
   tagValues = [system.date.format(now,"dd/MM/yyyy"),system.date.format(now,"HH:mm:ss")] + tagValues
   #crete the CSV file
   fileName = r"D:\TIS_TEST_{}.csv".format(now,"yyMMdd")
   csv.createCSV(fileName, headerValues, tagValues)
   #reset the "reset" tag. system.tag.writeBlocking blocks the thread until the write has finished.
   system.tag.writeBlocking(["[Bontexgeo Kft]Reset"],[0])

```

---

<div class="post-metadata">

**Author:** ![Matthias\_Longueville](https://avatars.discourse-cdn.com/v4/letter/m/7ba0ec/32.png) [@Matthias\_Longueville](https://forum.inductiveautomation.com/u/Matthias_Longueville)\
**Post date:** [August 30, 2022, 7:54am UTC](https://forum.inductiveautomation.com/t/making-a-csv-files-with-data-of-fibre-rolls/63560/7 "2022-08-30T07:54:11Z")

</div>

Hi Pascal,

Ok thanks for the answer.  
The line is no down, so I will wait until it is back on running.  
I will inform you if I get my data from each roll in a CSV file.

Thanks!

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [August 30, 2022, 11:41am UTC](https://forum.inductiveautomation.com/t/making-a-csv-files-with-data-of-fibre-rolls/63560/8 "2022-08-30T11:41:52Z")

</div>

> [@pascal.fragnoud](#):
>
> And there’s a small mistake in the script: line 11, it should be `tagValues`, not `tagValus`.

Typo has been corrected. Thanks for the catch.

---

<div class="post-metadata">

**Author:** ![Matthias\_Longueville](https://avatars.discourse-cdn.com/v4/letter/m/7ba0ec/32.png) [@Matthias\_Longueville](https://forum.inductiveautomation.com/u/Matthias_Longueville)\
**Post date:** [August 31, 2022, 5:40am UTC](https://forum.inductiveautomation.com/t/making-a-csv-files-with-data-of-fibre-rolls/63560/9 "2022-08-31T05:40:05Z")

</div>

Hi,

So the machine is running and I see on the local server that the tag change is executed:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/9/6985fb0ff8eff0a4dd6da338add45b27a97319b7.png)

But, if I look on the server, where the csv file needs to be saved, I see nothing:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/7/57d61e4f5999b34168c41be6c3a7b0dd81b31e53.png)

The file name is TIS\_TEST\_(date).

Any idea how this comes?

Thanks!

---

<div class="post-metadata">

**Author:** ![Matthias\_Longueville](https://avatars.discourse-cdn.com/v4/letter/m/7ba0ec/32.png) [@Matthias\_Longueville](https://forum.inductiveautomation.com/u/Matthias_Longueville)\
**Post date:** [August 31, 2022, 10:55am UTC](https://forum.inductiveautomation.com/t/making-a-csv-files-with-data-of-fibre-rolls/63560/10 "2022-08-31T10:55:19Z")

</div>

If I look, I have this error in the log activity:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/a/4ad6c838a40fc81d9af2a9b3565d334127c74880.png)

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [August 31, 2022, 11:19am UTC](https://forum.inductiveautomation.com/t/making-a-csv-files-with-data-of-fibre-rolls/63560/11 "2022-08-31T11:19:25Z")

</div>

The error means that the `csv` module you are importing has no function `createCSV()`.

I didn’t take the time to verify if how you were using the csv module was actually valid or not.

Honestly, you’re probably better off using the Ignition provided `system.dataset.exportCSV()` function. That would look like this:

```python
if not initialChange and newValue.getValue():
   import csv
   #set a list of tag paths of all tag values needed in script and read them all at once
   tagPaths = ["[Bontexgeo Kft]Rol lengte laatste rol (m)","[Bontexgeo Kft]Gewicht laatste Rol (kg)"]
   #system.tag.readBlocking() returns a list of qualified values so this builds a list with just the values
   tagValues = [qValue.value for qValue in system.tag.readBlocking(tagPaths)]

   headerValues = ["Datum","Tijd","LENGTE","GEWICHT"]
   #Get the current date, format it and add to the front of the tagValues list
   now = system.date.now()
   tagValues = [system.date.format(now,"dd/MM/yyyy"),system.date.format(now,"HH:mm:ss")] + tagValues
   #crete the CSV file
   fileName = r"D:\TIS_TEST_{}.csv".format(now,"yyMMdd")
   system.dataset.exportCSV(fileName,True,system.dataset.toDataSet(headerValues,[tagValues]))
   #reset the "reset" tag. system.tag.writeBlocking blocks the thread until the write has finished.
   system.tag.writeBlocking([str(event.getTagPath())],[0])

```

---

<div class="post-metadata">

**Author:** ![Matthias\_Longueville](https://avatars.discourse-cdn.com/v4/letter/m/7ba0ec/32.png) [@Matthias\_Longueville](https://forum.inductiveautomation.com/u/Matthias_Longueville)\
**Post date:** [August 31, 2022, 11:28am UTC](https://forum.inductiveautomation.com/t/making-a-csv-files-with-data-of-fibre-rolls/63560/12 "2022-08-31T11:28:31Z")

</div>

Hi Irose,

Thanks for the answer.  
If I change it I get next screen:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/5/15de2a668b5e3171ba8098b9ef1e0d7f5a86c7df.png)

Kind regards

---

<div class="post-metadata">

**Author:** ![Matthias\_Longueville](https://avatars.discourse-cdn.com/v4/letter/m/7ba0ec/32.png) [@Matthias\_Longueville](https://forum.inductiveautomation.com/u/Matthias_Longueville)\
**Post date:** [August 31, 2022, 12:04pm UTC](https://forum.inductiveautomation.com/t/making-a-csv-files-with-data-of-fibre-rolls/63560/13 "2022-08-31T12:04:33Z")

</div>

> [@lrose](#):
>
> `system.dataset.exportCSV(fileName,True,system.dataset.toDataSet(headerValues,[tagValues]))`

I found it (TAB and SPACE problem)

---

<div class="post-metadata">

**Author:** ![Matthias\_Longueville](https://avatars.discourse-cdn.com/v4/letter/m/7ba0ec/32.png) [@Matthias\_Longueville](https://forum.inductiveautomation.com/u/Matthias_Longueville)\
**Post date:** [August 31, 2022, 12:16pm UTC](https://forum.inductiveautomation.com/t/making-a-csv-files-with-data-of-fibre-rolls/63560/14 "2022-08-31T12:16:33Z")

</div>

Hi @lrose,

I changed the script like you told me:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/4/44a5f9bd42e98df3a31d316e98002dab2cb58961.png)

But, I still have the same error:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/3/c353bf66952b321c8bd8993a5382a69e7cc00abd.png)  
Any idea how it comes?

Thanks!

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [August 31, 2022, 12:21pm UTC](https://forum.inductiveautomation.com/t/making-a-csv-files-with-data-of-fibre-rolls/63560/15 "2022-08-31T12:21:20Z")

</div>

Are you sure you saved it? Anything that is italicized in the project browser is not saved. I only say this because looking at that script you have there I don’t see `createCSV` anywhere which makes it seem like your old version is being used.

---

<div class="post-metadata">

**Author:** ![Matthias\_Longueville](https://avatars.discourse-cdn.com/v4/letter/m/7ba0ec/32.png) [@Matthias\_Longueville](https://forum.inductiveautomation.com/u/Matthias_Longueville)\
**Post date:** [August 31, 2022, 12:32pm UTC](https://forum.inductiveautomation.com/t/making-a-csv-files-with-data-of-fibre-rolls/63560/16 "2022-08-31T12:32:50Z")

</div>

Hi,  
Yes you were right.  
The error is gone, but now I have next error:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/b/0b9b848d92539fd8f000d8614022d9eda4353ab9.png)  
I changed the “create CSV” with “system.dataset.exportCSV()”, and now he does not recognize this one.

Kind regards

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [August 31, 2022, 12:36pm UTC](https://forum.inductiveautomation.com/t/making-a-csv-files-with-data-of-fibre-rolls/63560/17 "2022-08-31T12:36:15Z")

</div>

Looking at the documentation it’s because `system.dataset.exportCSV` is for a Vision client scope only as part of its functionality is to ask the user where to save. This doesn’t make sense in a Gateway scope.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/7/17badb23e00775729d190f83d4848e750e3c2ff0.png)

You are going to want to use [system.dataset.toCSV - Ignition User Manual 8.1 - Ignition Documentation](https://docs.inductiveautomation.com/display/DOC81/system.dataset.toCSV) instead

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [August 31, 2022, 12:52pm UTC](https://forum.inductiveautomation.com/t/making-a-csv-files-with-data-of-fibre-rolls/63560/18 "2022-08-31T12:52:51Z")

</div>

ugh, that one’s on me. Should have checked the scope.

```auto
if not initialChange and newValue.getValue():
   #set a list of tag paths of all tag values needed in script and read them all at once
   tagPaths = ["[Bontexgeo Kft]Rol lengte laatste rol (m)","[Bontexgeo Kft]Gewicht laatste Rol (kg)"]
   #system.tag.readBlocking() returns a list of qualified values so this builds a list with just the values
   tagValues = [qValue.value for qValue in system.tag.readBlocking(tagPaths)]

   headerValues = ["Datum","Tijd","LENGTE","GEWICHT"]
   #Get the current date, format it and add to the front of the tagValues list
   now = system.date.now()
   tagValues = [system.date.format(now,"dd/MM/yyyy"),system.date.format(now,"HH:mm:ss")] + tagValues
   #crete the CSV file
   fileName = r"D:\TIS_TEST_{}.csv".format(now,"yyMMdd")
   csv = system.dataset.toCSV(system.dataset.toDataSet(headerValues,[tagValues]),True,True,False)
   system.file.writeFile(filePath,csv)
   #reset the "reset" tag. system.tag.writeBlocking blocks the thread until the write has finished.
   system.tag.writeBlocking([str(event.getTagPath())],[0])

```

This script should do the trick. Make sure you verify for correct indentation after copying.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [August 31, 2022, 12:55pm UTC](https://forum.inductiveautomation.com/t/making-a-csv-files-with-data-of-fibre-rolls/63560/19 "2022-08-31T12:55:40Z")

</div>

Not that it’s doing any harm, but there is no reason to `import csv` anymore since you don’t use it, plus the namespace gets overwritten by `csv = system.dataset.toCSV(system.dataset.toDataSet(headerValues,[tagValues]),True,True,False) ` so another reason to drop that line.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [August 31, 2022, 12:57pm UTC](https://forum.inductiveautomation.com/t/making-a-csv-files-with-data-of-fibre-rolls/63560/20 "2022-08-31T12:57:21Z")

</div>

Thanks, copy paste. Didn’t take the time to remove the import. Gone now.

[Next page](https://forum.inductiveautomation.com/t/making-a-csv-files-with-data-of-fibre-rolls/63560.md?page=2)
