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: 

Check if writing/reading to file (XML) executed properly ?

Hello everyone,

 

What am i trying to do: i have a Test.lvclass representing the state of my test and im saving the print of the class object to file during the test execution. I use Flatten to XML and Write to XML (string) functions. For loading i have Unflatten from XML and Read from XML (string).

 

Everything works fine, but sometimes (very irregularly!) when the test object should be restored from the file, the file appears empty and loading from it generates an error of course.

 

My guess is there must be an error accessing the file during the Write or Read functions

 

So my question is how to efficiently check the correctness of these functions? Do the Write to/Read from XML functions ckeck that? Can I rely on their standard error output or do i have to do something like Write - Read - check if contains supposed data?

Another guess would be something related to the file not being closed properly after write/read.. ? 

 

I would appretiate any ideas and tips on that..

Thank you!

0 Kudos
Message 1 of 3
(2,709 Views)
-Generally it is preferred to use the standard error out functionality to check if any error happened during write function.
-Usually above should be enough to conclude the write operation success.
- Also check XML String and XML input of write function whether it is empty or not.
- Are you using read/ write functions parallel? if not this shouldn't cause issue.
- If there are any XML specific errors you can check : To manipulate an existing file, use the Load File method to load the XML document into memory. LabVIEW can access the XML document unless the XML parser encounters errors within the document that prevent the XML parser from parsing the document. The Parse Errors output displays these XML-related errors : https://zone.ni.com/reference/en-XX/help/371361H-01/lvconcepts/parsing_xml_files_in_lv/
-If you you can recreate the error by any sample VI it can help better to debug.
Thanks
uday
Message 2 of 3
(2,692 Views)
Are you actually flattening a class to XML, or a cluster? If it's a cluster and the cluster changes between executions, the load will completely fail with an error (use a different format e.g. json or the OpenG/MGI INI file functions). Flattening a class to XML should work as the class keeps a mutation history for loading in old data into a newer version of the class.

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