Hi
How can I access UDT parameter in tag change event script?
I have used system.tag.read(â[.]âŚ\Parameters.ABCâ), where ABC is the parameter name, successfully.
Obviously the relative path changes based on your folder structure in the UDT.
Interested to know if there is a better way, such as {ABC} in the references
Hi Deon
I doesnât in tag change event script in udt.
I donât know if itâs possible. But we usually have a number of memory tags inside a folder of our UDT, that are just bound to those parameters.
Then those memory tags can be retrieved just like regular tags in the script.
Depends on the version. v8.0 makes parameters easier to access than v7.9.
v7.9 Iâve found it easier to do as Sanderd17 suggested.
v8.0 do as deon.korb suggests.
@Paullys50 and @deon.korb
I have a similar question for the struct member reading of UDT in script with Ignition V8.0
The [default]VetctorTag/Vector is a OPC UDT tag, which can be read by system.tag.read function as shown in below snapshot that triggered by a button click operation.
This OPC tag has three members X, Y and Z. In fact, I want to just parse and print its member X.
It seems that system.tag.read(â[default]VetctorTag/Vector.Xâ) doesnât work. Could you help to give suggestion of it?
Thanks in advance
system.tag.read(â[default]VetctorTag/Vector/Xâ) should work.
I usually use the browsers, such as a Perspective binding, to figure out the syntax first.
Thanks for your info, the way works for the memory tags, but doesnât work for OPC UDT tags.
The â[default]VetctorTag/Vectorâ is a OPC UDT tag that I dragged from a third part OPC UA server. Its whole data of X, Y, Z can be get by the with system.tag.read(â[default]VetctorTag/Vector/Xâ) ,
but using system.tag.read(â[default]VetctorTag/Vector/Xâ) doesnât work for reading its struct member X.
What about this post?
@zxcslo
Thanks for your info, I knew we could use JsonGet to retrieve Json format UDT of OPC tag.
Just want to know if it is possible to use system.read() to achieve this goal in script, because the jsonGet() function is only used in expression and it canât be used in script.
If it provide the jsonGet() function in script, then it solve my issues.
What about this:
or this:
value = system.tag.read("New Tag3").value
value = system.util.jsonDecode(value)
print value
print value['X']
print value['Y']
print value['Z']
This post explain itâŚ
EDIT: I just realized that @Kevin.Herron already explained this to you 11 days ago�
@zxcslo
Thanks for your comments.
Iâve try with your suggestion, it only works without the calling the eval() function as shown in the green box of below snapshot.
If we use eval() function or system.util.jsonDecode() function, both of them canât parse the âDocumentâ datatype, which is in fact printed as
<type âcom.inductiveautomation.ignition.common.script.adapters.PyDocumentObjectAdaperâ> as shown in below snapshot.
It seems that the Document type canât be parsed by jsonDecode() function.
BTW, in fact, Iâve asked the question for document type UDT parsing as you mentioned, the jsonDecode() function also doesnât work for that case, I use another workaround by using tags directly in script to solve my problem in that thread.
Well... then I'm 'lost'...
In my case, when I drag from OPC browser the UDT (struct) tag from my S7-1500 OPC UA server, that tag is Unicode string type (JSON). You obviously get Document type.
I'm using v7.9.12. You're using v8.
In v8 system.tag.read is deprecated (but it'll still work, for backward compatibility). The new function is system.tag.readAsync.
Maybe system.tag.read was changed in v8...??? Maybe @Kevin.Herron can explain?
EDIT: I read the other post it again and it seems that, because tag system is completely changed in v8:
system.tag.read
is fine but its most direct replacement in 8.0 is system.tag.readBlocking
.
@dawei.liu if youâre getting a document type just call str()
on it first.
Yes, my bad...
Anyway, good call on str()...
@Kevin.Herron and @zxcslo
Really appreciate your help, the str() works well and solve my issues
I understood the question incorrectly, but it is very interesting to see how to read a struct up and then access itâs members.
How would you write back to one member of the struct then?
Just as Kevinâs suggestion in jsonSet workaround in script
I just tested that itâs possible to write back the struct value through script (Ignition version 8.0.4 Nightly)
With below script, the UDT member âparam1â of âOPC_tagâ can be updated and writen back to OPCUA server.
value1 = system.tag.read(âOPC_tagâ).value
value1 = system.util.jsonDecode(str(value1))
value1[âparam1â] = âupdated_param1_valueâ
value2 = system.util.jsonEncode(value1)
system.tag.write(âOPC_tagâ, value2)
Doesnât that write the whole structure back? Less than optimal.
It does, and itâs required because his tag represents the whole structure. Reading the whole structure is the only way to get decent performance out of built-in OPC UA servers like the one on the S7-1500.
It would be ideal if the client could magically derive the NodeId for any given structure member and write to just that Node in the server, but itâs not even a given that a server exposes the members as individual Nodes.