LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

[Variable Web Services] Complex and variant variable datatypes with Variable Web Services

I'm trying to get Variable Web Services (VWS) working for one of my projects. After some trial and error I was able to get a LabVIEW proof of concept application working that can read and write shared variables using VWS and the HTTP Client. However, I reached a stumbling block when I was trying to read the value from either a variant- or complex(cluster)-typed variable. When trying to read the value I get "datatype not supported errors".

 

The help on this topic is very sparse and does not mention explicitly that VWS works on simple types only. In fact, it has this to say on the DataType property of the Variable and VariableValue resources:

 

DataType [string] — The data type of the Variable. The variable Web service supports primitive types and arrays of primitive types. For complex data types, use the serialized XML string or JSON string as the value of the Value property.

 

So assuming it's a requirement for this project to use VWS to access variables, my questions are, is it possible to use variant and/or cluster types and VWS? What does "use the serialized XML string or JSON string as the value of the Value property" mean in terms of the GET URL that reads a variable?

 

Thanks!

0 Kudos
Message 1 of 4
(3,265 Views)

It looks like you will need to use XML or JSON to handle complex and variant data types. JKI recently released an introduction to JSON that may be helpful in using that data type. 

 

Introduction to JKI JSON:

http://blog.jki.net/jki/introduction-to-jki-json/

Maggie M.
Application Engineer
National Instruments.
http://www.ni.com/support
0 Kudos
Message 2 of 4
(3,222 Views)

Ahhhhh. That's what that line means. It must have been staring at it for too long, cause it didn't occur to me that it was suggesting that to handle complex data types I would need to make the shared variable type a string and serialize the data to JSON to get around the native data type limitation. 

 

I would suggest that the documentation be updated to explicitly state what the limitations of this feature are, and to clarify how to use complex types. 


Thanks!

0 Kudos
Message 3 of 4
(3,215 Views)

To get this working I actually needed to do a lot of string manipulation. Since the PUT request is also in JSON, I needed to use basically two passes of escaped ". So to pass the JSON flattened cluster, which has three elements of boolean, number, and string, I ended up with something like this:

 

{
"Value" : "\"{\\\"testbool\\\":false,\\\"testnum\\\":23,\\\"teststring\\\":\\\"this is a d\\\"}\""
}

Conversly, to get the value back out, I needed to unescape the JSON to unflatten the value, all this string manipulation ends up causing copies and the memory of my RT target grows. 

 

So my question is, is there a recommended way to escape the " that won't cause the application to continually increase memory?

 

0 Kudos
Message 4 of 4
(3,210 Views)