Data Set Scripting

Hi,
I have a Scheduled Gateway script to read data from a .csv file and push it out to a data set tag.
I have
file_path = "C:\Users\SJ\Downloads\PLCTags.csv"
# Read in the file as a string.
string = system.file.readFileAsString(file_path)
# Convert the string to a dataset and store in a variable.
dataset = system.dataset.fromCSV(string)

So far so good.... however, I can't seem to then write out to a dataset tag.
I've tried the conversion commands
system.dataset.toPyDataSet and system.dataset.toDataSet without success.
I'm probably missing something simple ??!

Cheers

Hi, Stephen. Please have a read of Wiki - how to post code on this forum and then fix your original post. We can't tell if you've indented properly.

1 Like

I've check, it's indented properly.

Can you post your entire code block please?

And any errors?

Is the tag's readOnly property set to True? If so, set it to False.

Also, make sure you are using the following syntax to write the dataset to the tag:

system.tag.writeBlocking(['path/to/tag'], [dataset])

I don't see anything like this in your code snippet.

4 Likes

Hi.
This is what I had originally
system.tag.write("tagpath", "dataset")

Which didn't work

Then I went to your suggestion

system.tag.writeBlocking([tagpath], [dataset])

Which works !!

Cheers

1 Like

Your dataset variable is in quotes making it a string. That's probably why the tag write wasn't working, but nevertheless, the write blocking method is the most up to date way to handle tag writes, so it's good that you changed the syntax.

1 Like

Hi,
That's good to know.

Thanks again.