LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

save and read control value using xml

Solved!
Go to solution
I need to read and update controls with the values they have the previous time the vi was run. Attached is a vi that I come up with. I can save control values; when I implement the section that should read and update control values, I keep getting this error "The XML tag describing the type of data does not match the wired type". Does any one know why? Attachment: test vi and xml control file.
0 Kudos
Message 1 of 11
(2,382 Views)

You are getting the error because you are trying to Unflatten from XML and wiring a variant, but the XML string does not describe a variant. The XML string for a variant is completely different than for a, say, numeric.

 

This is the XML string for a variant:

 

<LvVariant>
<Name>Variant</Name>
</LvVariant>

 

This is the XML string for a DBL:

 

<DBL>
<Name>Numeric</Name>
<Val>1.00000000000000</Val>
</DBL>

 

Thus, if you feed in the second string, you cannot provide a datatype of variant to the Unflatten From String function. This is like trying to turn an orange into an apple.

 

Saving control values to file is a subject that has come up many times. I would suggest doing a forum search as you will find solutions to this. OpenG has a set of VIs to this as well.

 

Other code comments:

  • Avoid using string functions to create paths. Use the file functions such as Build Path and Strip Path.
  • You do not need an Open/Create/Replace function. This is already handled inside the Read From XML File and Write to XML File VIs.
  • Do not create duplicate code. You are creating the same path in two different places. Use a wire to branch. 
  • You have an unitialized shift register in the for-loop. This means that each time you run the VI the shift register will remember what it had the last time, and continue to concatenate to that array.
  • The shift register is completely unnecessary. Use auto-indexing of the for-loop to automatically generate the array of XML strings.
  • Learn to use the wire cleanup tool.
Message Edited by smercurio_fc on 01-29-2010 11:02 PM
0 Kudos
Message 2 of 11
(2,372 Views)
Scratch what I said about the variant conversion. I hadn't seen that you were saving the stuff as variants, but after the fact. Right now I'm looking at your VI again, but it keeps crashing LabVIEW. Something very strange is going on...
0 Kudos
Message 3 of 11
(2,367 Views)
Solution
Accepted by topic author aderogba

As far as I can tell it appears you found a bug. The Unflatten From XML does not properly handle a cluster of a string and a variant of something. The Get All method returns an array of clusters, with each cluster being a string and a variant.

 

If you do this:

 

 

 

then no error is generated.

 

 

But, if you do this:

 

 

 

you get an error.

 

Looks like a bug to me.

Message Edited by smercurio_fc on 01-29-2010 11:49 PM
Message 4 of 11
(2,363 Views)

Thanks for your help. I had the suspcition it works in some instances and breaks down in others. I will be interested in what NI response will be. What I have done in the interim is use Unflatten to/from String combination instead of xml. That seems to be working. The only wrinkle is that  I am using the deprecated Ctrl Val.Get All method because it has type desc, regular Ctrl Val.Get All does not.

 

0 Kudos
Message 5 of 11
(2,354 Views)
0 Kudos
Message 6 of 11
(2,346 Views)

aderogba wrote:

Thanks for your help. I had the suspcition it works in some instances and breaks down in others. I will be interested in what NI response will be. What I have done in the interim is use Unflatten to/from String combination instead of xml. That seems to be working. The only wrinkle is that  I am using the deprecated Ctrl Val.Get All method because it has type desc, regular Ctrl Val.Get All does not.


That method will work. There are other methods. As I indicated, this question comes up a lot, so if you do a search you will find suggestions. And, as I also noted, OpenG has VIs for this sort of thing.

0 Kudos
Message 7 of 11
(2,331 Views)
0 Kudos
Message 8 of 11
(2,329 Views)

This behavior was reported in CAR #198717.

 

Regards, 

 

Marti C
Applications Engineer
National Instruments
NI Medical
0 Kudos
Message 9 of 11
(2,292 Views)
Are you aware of any fix to this problem?
0 Kudos
Message 10 of 11
(2,235 Views)