LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

OPC-UA: LabVIEW cannot read "Struct DataType"? (error "Bad_TypeMismatch")

Solved!
Go to solution

I have an OPC-UA server on Siemens S7-1200 PLC and I'm trying to read the data with the OPC-UA Client Toolkit from LabVIEW 2019

The software UaExpert shows the data without any error (see image below) 

UaExpertUaExpert

 

But LabVIEW does not show any data and I'm getting the error code:

2155085824

BadTypeMismatch

The value supplied for the attribute is not of the same type as the attribute's value.

 

Here's my VI (LabVIEW 2019):

 

Front panelFront panel

 

Block DiagramBlock Diagram

 

Am I doing something wrong of LabVIEW 2019 (with OPC-UA Toolkit "ni-labview-2019-opcua-toolkit-x86_19.0.0.exe") does not Struct DAta Type?

 

My VI was created according to the example "OPC UA Demo.lvlib:Data Access Client.vi"

NI ExampleNI Example

 

0 Kudos
Message 1 of 10
(4,310 Views)
Solution
Accepted by topic author mthheitor

Hi!

 

No, you are not doing anything wrong.

OPC UA supports basic datatypes like booleans, integers, floats, strings, timestamps and arrays of these, as well as complex data structures. To my knowledge, the typedefs of those complex data types can also be read from the server. However, LabVIEWs OPC UA toolkit only supports the basic data types.

 

Most of the nodes shown unter "Server" in UA expert are such complex data types and are not readable by LabVIEW. This is even true for your node, though it is "just" an enum.

 

But the nodes unter "Server" are not essential. (Though, I understand the idea to start there, since the "Server" node is common to all OPC UA servers.)

 

Did you try to access the "real data" from the PLC program?

 

Message 2 of 10
(4,267 Views)

Thanks for the answer

 

I can read data from PLC like bool, float32, int16, int32 and string (valid for scalar and array).

But I can't read any struct data, even if all the elements in the struct are the same time (see fig. below)

Block Diagram + Front PanelBlock Diagram + Front Panel

 

Obs.: I can read these data by addressing only one element of the struct at time, e.g., "ServerInterfaces.OPC.Tipo_de_ensaio.Escolhe_FADIGA" (ns=4;i=30) instead of "ServerInterfaces.OPC.Tipo_de_ensaio" (ns=4;i=27)

But read one data at time is much slower than read the whole struct.

 

I can't read struct, even if all elements have the same data type (bool)I can't read struct, even if all elements have the same data type (bool)

 

UaExpert works fineUaExpert works fine

 

Add to this the fact that almost all data from the Siemens libraries are in the "Struct" form (see fig. below)

 

Struct and User-Defined Data Types (UDT) are Siemens standard "good programming practices"Struct and User-Defined Data Types (UDT) are Siemens standard "good programming practices"

 

See also https://www.automation.siemens.com/sce-static/learning-training-documents/tia-portal/basics-programm...

 

So, read struct is "must have" in the OPC-UA Toolkit. NI needs to implement this in the new version

 

0 Kudos
Message 3 of 10
(4,231 Views)

Hi!

 

well, this is not really LV related.

 

Inside the OPC server, a struct is not a data container. It is just a node which contains child nodes.

Also UA expert does not read the struct data, it knows which nodes are inside, reads those, and displays the data just as if it can read the struct directly.

 

Regarding speed:

Inside OPC, multiple nodes can be read with a single request to the server. While one still has to pass the list of node IDs to be read, only one request is sent to the server, and only one reply with all data is returned.

 

Further more: You are creating a subscription, that is, you are informed whenever the value changes. If you make a subscription to an entire struct, you would be notified whenever a single value inside changes and get many many many change notifications. This is also not desired.

 

For your communication with the PLC, you should have a subscription on a nodeId which indicates that data is available, then collect that data via normal read, and maybe write back a value to notify that the data is read from the PLC.

 

Message 4 of 10
(4,203 Views)

Hello Sebastian

 

I'm here again, now trying to read "real data" and getting the same error 2155085824 (Bad_typeMismatch)

The data that I'm trying to read is the Siemens DTL (Date and time)

According to Siemens: "An operand of data type DTL has a length of 12 bytes and stores date and time information in a predefined structure."

 

The pdf attached shows details about the DTL

 

Does LabVIEW OPC-UA supports this data type?

DTL.png

 

0 Kudos
Message 5 of 10
(3,995 Views)

That's again a structure. And the same thing applies as mentioned before. This is a Siemens specific DateTime element to match their internal DateTime elements. The official OPC UA DateTime datatype is a signed 64-bit integer representing the number of 100ns intervals since midnight January 1, 1601 GMT. This is a base type that the OPC UA Toolkit should be able to handle and convert into a LabVIEW Timestamp.

 

Your Siemens DataTime struct needs to be handled as individual elements with the OPC UA Toolkit too just as any other struct type. It's not practical to expect the Toolkit to understand the zillions of different complex datatype timestamps that all the different PLCs use.

Rolf Kalbermatter
My Blog
0 Kudos
Message 6 of 10
(3,971 Views)

Sorry to resurrect an old thread, but I'm having a similar issue.

 

I'm not able to read struct members. If a struct is just "a node which contains child nodes", how to I create a NodeID for a child node?  I have tried adding a dot and the struct member name (i.e. "ns=4;s=|var|Folder1.Folder2.StructNode.StructMember1"), but I just get Bad_NodeIdUnknown.  

 

Is there some specific syntax for this?

0 Kudos
Message 7 of 10
(3,556 Views)

Hi,

I'm also having the problem, that I can't read the single values of structures because they have no own ID. Is there a syntax to get the values in a Labview Client.

For example: structure "LocalizedText","ResultDataType","ResultMetaDataType"

Hope anyone here solved the problem and could help

0 Kudos
Message 8 of 10
(1,654 Views)

As said, it's simply not possible. I'm stuck with LV2017, so may be there's something new in current versions.

I've written this simple tool which allows to browse the OPC node tree in LV similar to UAExpert. Click a node in the tree, and it tries to read it as variant and to browse it for child nodes.

 

OpcTree.png

 

It is simply so that there are nodes which are not accessible by LV. And sometimes, a node itself is a struct, but counts as single node. UAExpert is able to decode and display such structs because the OPC server also provides information on how to do so (See top-level node Types), but LV has no way to do so. There's not much more than reading variables as basic data types / arrays of such or as variant. And if even variant fails, there's no way to read it. So, if this tool cannot read it, LV just can't.

 

Quite interesting: A LV OPC server also has some special items in its Server node, which are readable by UAExpert, but not LV itself...

 

I don't know much about the server side, especially about PLCs. Maybe, there is some option to publish the data in an other way?

0 Kudos
Message 9 of 10
(1,631 Views)

I have seen a similar issue in reading OPC data for booleans that are contained within a struct or within a word in the PLC.

 

The OPC servers seems to read the first bit of the word correctly, or the first boolean in the struct.  Any other booleans don't read correctly in the OPC client.  I don't think this has anything to do with LabVIEW, but is within the OPC client itself.  Distributed System Manager shows me the same information as the OPC quick client, so it seems the issue relies within OPC.

 

Oddly enough, if you have multiple numeric values in a struct, that works just fine.

0 Kudos
Message 10 of 10
(325 Views)