LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

More Specific 'Class Name' Property for Controls?

I'm trying to write a VI which can look at a large XML file and compare the various values inside the file with specific controls inside a cluster. Essentially I want to extract the values from the XML file which are of interest to me (the values for the cluster) and populate the cluster.
 
LabVIEW's XML Read functions require a 1 to 1 match (just like the flatten and unflatten string) for the control value against the data in the file. This defeats a lot of the purpose of XML in my opinion. XML allows you to throw a ton of stuff in a file and then extract what you need or view the data however you like.
 
One difficulty I'm running into is that there isn't a control 'Property' (Like Class Name or Class ID for instance) that tells me exactly what type of data the control is. For example, all 'Digital' controls return 'digital' as their class name. I want to know if it is I32, Double, U8, etc. so that I can convert the XML text correctly from a string to the correct digital format.
 
I want to keep 1 large 'config' xml file with lots of data for various applications, and then search through the file for specific values at run time so that I can populate the control. I used to use the 'Type Descriptor' in LabVIEW 7 which had all of the critical information (Variable Name, Value, Exact Type, etc.) for converting from the string value to the correct control value. Now that is gone in LabVIEW 8...so I'm trying to use the properties that are available to me for each control, but I'm finding that there just isn't enough specific information about the exact type of control.
 
Any Ideas?
0 Kudos
Message 1 of 10
(4,301 Views)
You're referring to two different issues here. The first has to do with XML files and LabVIEW's XML functions. Personally, I've always considered LabVIEW's XML functions to be very lacking, as they don't really treat an XML file as a DOM so you can't get specific items like you said. They are specifically designed to read and write data generated by LabVIEW to XML. They are not generic XML functions. For that you need to go outside of LabVIEW to something like LabXML or to some of the code mentioned in this thread.

As for your other query, are you referring to the "Unflatten From String" function? You can still get this functionality if you right-click on the function and select "Convert 7.x Data".

Message Edited by smercurio_fc on 04-05-2006 01:36 PM

0 Kudos
Message 2 of 10
(4,290 Views)
Oops, that should say "Flatten to String"...
0 Kudos
Message 3 of 10
(4,285 Views)

I agree with you on the XML functions.

It is only 2 different issues here because I'm trying to compensate for what the XML functions lack.

I know I can use the 7.x option,...but nobody likes to code for functionality which is now deemed obsolete. I want my new, super cool vi to be compatible with LabVIEW 8.0 and all versions further without relying on the 7.x option.

A support person said they've dropped the 'Type Descriptor' in LabVIEW 8 because it is too complex to be useful by the users. We still need the specifics of a control though.

Thanks for the reply.

Craig

0 Kudos
Message 4 of 10
(4,282 Views)
I guess there's one part of this that I'm not understanding. You said that you want to convert the XML text from a string to the "correct digital format" so you can set the values of the controls. How is the data stored in the XML file in the first place? Is it from a "Flatten to XML" function? Can you provide a sample of this XML file and your original 7.x code?
0 Kudos
Message 5 of 10
(4,278 Views)

For now, it is probably easier if we assume that I am able to parse the XML file and extract the string values.

Imagine my XML file is like this, and I'm interested in extracting only 'Speed' and 'Distance' in order to populate a cluster control which contains these two values:

<Config>
 <Version>
  8.0
 </Version>
 <Speed>
  99
 </Speed>
 <Distance>
  150
 </Distance>
 <Accel>
  22
 </Accel>
</Config>

So...I have these two string values '99' and '150'...and I have references to the two numeric controls inside the cluster. I want to convert these two string values to the correct numeric format (DBL, I32, etc.) before using populating the numeric control via the [Ctl -> Value] Property using a Property Node...which takes a Variant.

I've attached an example of what I'm talking about..and an image.

 

 

Download All
0 Kudos
Message 6 of 10
(4,266 Views)
OK, let me ask a dumb question: Based on your example, what's preventing you from simply using the "Fract/Exp String to Number" for all conversions and allowing the data type coercion to happen automatically when you wire the output of this function to a "Bundle by Name" function to which you've wired your cluster? Sort of like this:




Message Edited by smercurio_fc on 04-06-2006 08:52 AM

0 Kudos
Message 7 of 10
(4,254 Views)

I'll probably have to do that. I just remember from the old days that fractionals don't always convert exactly to integers....I don't know if the same is still true. I do remember encountering a problem using the 'Quotient/Remainder' SubVI with Doubles.

Will a double hold the maximum value for a U32 or perhaps worst case a U64 now that they are available.

Thanks for the input. I know there are work arounds...I could also look at the text string and determine roughly the size by the number of digits and if a decimal is present or not...then use the 'closest' numeric type. Or, I can use a naming convention similar to standard C (intMyNumber, etc.) and look for the 'prepend' string in the name to determine how to convert the data.

I just like doing it exactly right...with no conversion. Oh well.

Thanks.

0 Kudos
Message 8 of 10
(4,241 Views)
Fractionals will get rounded to the nearest integer with a coercion mechanism. If the text you read out of the xml file was the string "5.88" and your control was an I32 your method would use the "Decimal String to Number" since you're basing that on the control type, and not the data itself. This would give you a value of "5" for the control. If you use the "Fract/Exp String to Number" and then have a coercion occur when you wired the value to an integer-type control (the method I showed you) the control's value would be "6". Which is correct? Technically, neither one since the data is 5.88, not 5, or 6. If, however, the text you read ouf the xml file was the string "5" then either method would give you the same answer.

As for the data ranges, you can find this information in the LabVIEW User Manual. A DBL is 64 bits of data storage and it's more than large enough to hold a U32 or U64.
0 Kudos
Message 9 of 10
(4,233 Views)
Craig,

It looks to me as though the Flatten to XML function in LV provides what you need. For a simple cluster with a numeric (double), a boolean, and a string, the output is:


Cluster
3

Numeric
0.00000


Boolean
0


String




The Write to XML File.vi with the XML string above as input prepends the LV version and some other information.

If you want to have things other than your VI's controls in the file, you will need to do some parsing with the string functions.

Lynn

The HTML processor of the forum messed with the display. Here is the test VI.

Message Edited by johnsold on 04-06-2006 01:08 PM

0 Kudos
Message 10 of 10
(4,225 Views)