From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Variant in Variant of a shared variable

Solved!
Go to solution

Hello,

I am trying to read some Tags in a Siemens S7-1200 PLC over NI OPC server. I can read them in NI-DSM (Distributed System Manager). However, I can not read or write them in Labview. I generated a shared variable event loop which will run when a  variable changes. I get always Variant in Variant as Value which is not correct as I want to convert it to a data type. (See attached image)

How can I correct it?

 

 

 

0 Kudos
Message 1 of 6
(3,058 Views)

Use 'variant to data' to convert it to the appropriate data type (it looks like a numeric?).


LabVIEW Champion, CLA, CLED, CTD
(blog)
0 Kudos
Message 2 of 6
(3,049 Views)

Did you see the image? Variant to data but which data? Data is also variant. I have to make variant->variant->UInt8 which seems not good and not correct. Tags are UInt8. Normally in probe windows I see <variant:254> for byte variables. But what does it mean <Variant:<Variant:233>> ?

0 Kudos
Message 3 of 6
(3,043 Views)
Solution
Accepted by topic author kahlenberg

It doesn't matter, this works:

VariantInVariantToData.png

 


LabVIEW Champion, CLA, CLED, CTD
(blog)
0 Kudos
Message 4 of 6
(3,026 Views)

O thanks, it works. But I wonder why are there 2 variants inside each other.

0 Kudos
Message 5 of 6
(3,019 Views)

It is quite common for a function/property/method to return a value as a variant if the data type is unknown at runtime (e.g. getting a control value for a generic control).

 

Is your shared variable a variant? If so - the event data converts that to a variant (even though it is already a variant) because you might have registered for events for different shared variables that might be of different data types so it returns as a variant so you can convert it to the correct type (based on the 'data type' event data item).


LabVIEW Champion, CLA, CLED, CTD
(blog)
0 Kudos
Message 6 of 6
(3,000 Views)