Selecting row from Power Table to send to PLC tag

Hello,
I have read a CSV file and stored it in a Power table. I now want to take one entire column (field name "Value") and send it to an OPC-UA array (100 elements - here is the tag: [edge]GlobalVars/SetupParametersString)
I wanted to put my code in here (and it is below) but it doesn't work and I'm not sure why. I think I need to convert the data to string, but I can't get the ToString command to work either.

I think this is easy, but I am stumped. Can anyone help please?

Thank you!

tbl = event.source.parent.getComponent('Power Table')
tempDS = system.dataset.toPyDataSet(tbl.data)
hdr = ['Value']
newDS =
for row in tempDS:
newDS.append([row[0]])
system.tag.write('[edge]GlobalVars/SetupParametersString',system.dataset.toDataSet(hdr,newDS))

I think that I'm selecting the column correctly, but I am just not writing the data to the OPC Tag correctly. I get the timeout error if the PLC is off:

Error writing to tag '[edge]GlobalVars/SetupParametersString': Bad("Bad_Timeout: The operation timed out.")

And I get this error if the PLC is on:

Error writing to tag '[edge]GlobalVars/SetupParametersString': Bad("Bad_TypeMismatch: The value supplied for the attribute is not of the same type as the attribute's value.")

Can you share some details about the OPC tag configuration?

What server is it from? What is the Ignition tag datatype? What is the datatype in the server? A screenshot of the tag config would be useful.

Sorry Kevin...my bad.
I'm not sure what you mean when you ask what server is it from. The PLC is an Omron NX502. It is an array of String[15]. I was playing around with the total number of elements...this screenshot is of a 2001 element array:

Try writing the list of strings you create to the tag, instead of creating a dataset from it.

I'm sorry, but I'm not sure what you are asking me to try.

This code works to move a memory array of 5 integers into the array of 5 STRING[15] in the PLC without any problems:

tagValue = system.tag.readBlocking('[edge]test')[0].value
value = list(tagValue)
system.tag.writeBlocking('[edge]TestSTRING15', [value])

The variable TEST is a memory array of 5 values, and the TestSTRING15 is a PLC based array of 5 elements of STRING[15]. So I think that I am not extracting the column of values properly from the dataset. I did try to create a LIST of the data, but that caused the same Bad_TypeMismatch error.

Something like this:

list = []
for row in tempDS:
    list.append(row[0])

system.tag.writeBlocking(['[edge]GlobalVars/SetupParametersString'],[list])

I'm sorry Kevin...No errors when executed, but it didn't change the variables in the PLC.

Add a print so we can see the result:

# set up tempDS as before...

list = []
for row in tempDS:
    list.append(row[0])

print list
print system.tag.writeBlocking(['[edge]GlobalVars/SetupParametersString'],[list])

I know fundamentally you can write to an OPC Tag that is a StringArray by writing a list of string values. I verified this works on a test server:

values = ["a", "b", "c"]

print system.tag.writeBlocking(['[default]StringArray'], [values])

Not sure yet what's wrong in your situation.

Morning Kevin!
Sorry, I had to go to bed last night :slight_smile:
The problem is getting the data from the dataset to the array. I've already verified, via the code above, that I can take data from an Ignition Memory array tag and write it to the OPCUA array tag. So the problem is that I am not successfully getting the column Value from the dataset to the OPC array. I'm going to create a memory tag array and try to get the data from the dataset into that. Once I can get the data into the memory array, the problem should be resolved because I have successfully written to the OPC tags from the memory array. I just need to finish a few things before I test it this morning :slight_smile:

Did you notice I removed some extra brackets in my code that builds the list?

This is a slight variation that is fully functional with a test table/data:

data = event.source.parent.getComponent('Table').data

ds = system.dataset.toPyDataSet(data)

values = [row[0] for row in ds]

print values

print system.tag.writeBlocking(["[default]StringArray"], [values])

Kevin,

I did not notice. I've done 2 things. The first is that I created a memory array of DOUBLE. I was successfully moving the data into this array (albeit I was moving the FIRST column, not the SECOND column titled Value). For some reason, I was not having success getting this array to write to the PLC, which I had no trouble with before.

Then I saw the post from you above. I took the code and entered it and it is faulting at the PRINT system.tag.writeblocking line...so it doesn't seem to work for some reason. The data isn't moved from the dataset into the memory array.
Traceback (most recent call last):
File "event:actionPerformed", line 62, in
java.lang.NullPointerException: java.lang.NullPointerException: Cannot invoke "String.equalsIgnoreCase(String)" because the return value of "com.inductiveautomation.ignition.common.tags.model.TagProvider.getName()" is null

caused by NullPointerException: Cannot invoke "String.equalsIgnoreCase(String)" because the return value of "com.inductiveautomation.ignition.common.tags.model.TagProvider.getName()" is null

Here is the code:

data = event.source.parent.getComponent('Power Table').data

ds = system.dataset.toPyDataSet(data)

values = [row[0] for row in ds]

print values

print system.tag.writeBlocking(["[default]SetupParametersMemoryArray"], [values])

I did change to a power table, since that is what I am using. The memory array did not receive the data from the code above. Below is what I had used that DID get the dataset into a memory array. My memory array write to the PLC isn't working now and I am trying to figure that out now...

list =
for row in tempDS:
list.append(row[0])
system.tag.writeBlocking(['[edge]SetupParametersMemoryArray'],[list])
system.tag.writeBlocking(['[edge]GlobalVars/SetUpParametersString'],['[edge]SetupParametersMemoryArray'])

I have to do 2 things with the above code (you sent yesterday I believe)...I need to select ONLY the Values column, and I need to get the tag.write to the PLC to work (it was working yesterday...I broke something).

Thank you!

If you copied my latest code you need to change the name of the tag provider it references.

Mine is called “default”, yours “edge”.

Oops! Yes, sorry. I changed everything else and forgot the path :slight_smile:

It populates the memory array correctly (again, still using the wrong column of data):

print system.tag.writeBlocking(["[edge]SetupParametersMemoryArray"], [values])

I changed it to the actual OPC Tag though and it didn't work:

print system.tag.writeBlocking(["[edge]GlobalVars/SetupParameters"], [values])

The code you supplied displayed this...so the data did populate the array. It did have a timeout error though. One thing that I do not understand is why the memory tag, that has 2001 elements, actually shows up to 2063 in Ignition, with the tags ABOVE 2001 showing null rather than a value

u'1982', u'1983', u'1984', u'1985', u'1986', u'1987', u'1988', u'1989', u'1990', u'1991', u'1992', u'1993', u'1994', u'1995', u'1996', u'1997', u'1998', u'1999', u'2000', u'2001', u'2002']
[Bad("Bad_Timeout: The operation timed out.")]

this continues until [2063]