Just a simple question. I am trying to access and modify an element in a bidimensional array/list, but it is not working as I expected and I am missing something. I cannot find anything similar in the manual or forum.
This example is just for testing with onClick action in a normal button:
X = [["A","B"],["C","D"]]
system.tag.write("[default]NewTag",X)
self.getSibling("Label_0").props.text = X[0]
#ok, I see ["A","B"]
self.getSibling("Label_0").props.text = X[0][0]
#ok, I see A
Y = system.tag.readBlocking("[default]NewTag")[0].value
self.getSibling("Label_0").props.text = Y[0]
#I see ['A','B']
self.getSibling("Label_0").props.text = Y[0][0]
#I get literally: [
Could anyone explain the difference?
And then, how would I modify any element in the bidimensional list? Would it be different if work with the X array or Y array? Example (when pressing another button):
Ignition’s tags don’t support anything beyond 1d arrays. When you write the 2d array into it and then read it back I think you’re getting a string representation of some object in memory instead of a value you can work with.
If you don’t need to access the data from multiple scopes (Vision Client vs Gateway) you can maybe just store it in a global variable or the globals map.
Also worth considering storing some amount of the content in a json structure. You could use a “document” tag and have access to the content through the tag editing GUI. That document holding everything could easily be pushed anywhere/everywhere as an encoded json string.
@Kevin.Herron I need to access the data from perspective. I am developing a SCADA project only using perspective. Not sure if I accessing from a perspective client would create any problem.
@rcrownover I am a little newby to Ignition. Could you give a simple example of your idea?
[UPDATE]
I just tried this example and I am still stuck:
On a first button:
X = [["A","B"],["C","D"]]
jsonString = system.util.jsonEncode(X)
system.tag.write("[default]NewTag",jsonString)
#NewTag type is document, and I can see that the array is written (attached image)
On a second button:
jsonString = system.tag.readBlocking("[default]NewTag")[0].value
#all of this looks ok:
self.getSibling("Label").props.text = jsonString
# [["A","B"],["C","D"]]
self.getSibling("Label").props.text = jsonString[0]
#["A","B"]
self.getSibling("Label").props.text = jsonString[0][0]
#A
#but I cannot modify like this:
jsonString[0][0] = "Z" # or even jsonString[0][0] = another array
I tried using system.util.jsonDecode but not working or not sure how to use it.