LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Read variant from file

Hi to everybody!
I'm trying to write variant to file(in binary mode),but I can't read it in anyway.The problem is that when I read the file it returns that the end of file has been encountered.I think the problem is in the count input parameter of "Read from binary file" vi.Could yuo help me please?I attach the VI I created.
Or can you suggest another way to read a variant from file?
Message 1 of 7
(3,334 Views)

Since you are trying to read and write Clusters to and from disk I would highly recommend using the Flatten to XLM functions.  Makes it easy to read and write clusters to and from disk.

Matt

Matthew Fitzsimons

Certified LabVIEW Architect
LabVIEW 6.1 ... 2013, LVOOP, GOOP, TestStand, DAQ, and Vison
0 Kudos
Message 2 of 7
(3,330 Views)
Thank you for your help,but I do need to use variant  necessarily to mantain undefined data!Could you suggest a method to use it?
0 Kudos
Message 3 of 7
(3,314 Views)

This should be what you are looking for.  What I did was flatten to string before writing the file to disk.  Wen reading I used unflatten from string.  Should work for any case.

 

Matt

Matthew Fitzsimons

Certified LabVIEW Architect
LabVIEW 6.1 ... 2013, LVOOP, GOOP, TestStand, DAQ, and Vison
0 Kudos
Message 4 of 7
(3,304 Views)
Yes,I had yet thought to do as you suggest,but it didn't work.It was because in my final program (the one I attached is only an example) I don't want there is "Type",from which to obtain the "type string" parameter,in the part of the VI which read the file.Here because I wanted to use the variant type.
My goal is to become indipendent from data type in all VIs through which the data have to pass,but it hasn't to be interpreted.
In my final project I am going to have a VI (Read) which read data from file and a VI (Algorithm) which use data after its interpretation and only in this last VI I can use "Type" from which to obtain "type string".
Moreover I'd prefer not to use string type because in Algorithm I will need to convert string to data and I know this operation makes slow the VI (I am going to run it on a real time system too) while the conversion from variant to data is supposed to be faster or not according to you?!
Sorry if I haven't been clear,but if you want to help me and if you havent' understood something,I'll be glad to  explain it better.Thank  you very much  from  your help anyway!!
0 Kudos
Message 5 of 7
(3,298 Views)

 

I don't know if you solved your problem or not, but I came up with a solution. The key is to use "Flatten to string" and "Unflatten from string". Don't use the XML functions. They seem to get all borked up when you try to read them back into a variant.

 

What I have attached is a project with two VIs. The WriteCompressedData takes in a variant, flattens it, and compresses the flattened string with the zlib DLL.  The ReadCompressedData reads the file, inflates it, and then unflattens it back into a variant. Then you can cast the variant into whatever type you need. I also have a little GenerateWaveform VI that serves as an example by generating a waveform, writing it to disk and then reading the file back and displaying the waveform that was saved in the file.

 

 These files were saved in LV 8.2.1.

 

 

--

Brian Rose
0 Kudos
Message 6 of 7
(2,946 Views)

Brian, you replied to a post made in 2006.  I sure hope the originator found a solution by now.

 

- tbob

Inventor of the WORM Global
0 Kudos
Message 7 of 7
(2,937 Views)