LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to write and read multiple data types in and from a binary file

Solved!
Go to solution

Hello,

I'm trying to write three types of cluster to a binary file and it is working fine.

I'm unable read the type of data from binary file again and no error I'm getting.

Please help in resolving this issue.

 

Thanks you.

Download All
0 Kudos
Message 1 of 7
(3,704 Views)

Hi Ramachandraiah,

 

I'm trying to write three types of cluster to a binary file and it is working fine.

You are writing a whole stack of typedef'd clusters of (arrays of) clusters to that file - all those typedefinitions are missing from your attachment!

 

I'm unable read the type of data from binary file again and no error I'm getting.

You get no error because you are clearing them.

When you want to get those errors: don't clear them!

 

Did you debug your read VI? Where does it throw an error?

I didn't go through that whole stack of huge cluster typedefinitions: are they the very same for the writer and reader VI?

 

Btw.

- I would avoid saving data in such huge clustered data structures to files…

- OpenG has functions to save and read clusters to/from ini files…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 7
(3,676 Views)

You write three different clusters to the file, cluster A, N x cluster B, cluster C, in that order..

Reading, you read cluster A from the beginning, N instances of Cluster B until you get an error, but then, before you read cluster C, you reset the file position to the start of the file, thus you are trying to read the C data where the data of A is located. This will not work (and if it would work by accident, you'll get garbage). Does it work better if you don't set the file position?

 

And yes, we cannot test because of all the missing typedef.

0 Kudos
Message 3 of 7
(3,664 Views)

I tried without resetting the file position even though I couldn't read the data what I've written to it.

I tried with simple data data1-one dbl number, data2-boolean, data3-string.

I couldn't read the data properly.

 

 

0 Kudos
Message 4 of 7
(3,620 Views)

If you know how many of type B clusters you are writing, then write that value (I32) before writing the B clusters.  Then on the read side, you can just read an array of type B clusters without a loop.

 

And as already stated, do not just clear your errors.  You need those for debugging.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 5 of 7
(3,605 Views)
Solution
Accepted by topic author Ramachandraiah

@crossrulz wrote:

If you know how many of type B clusters you are writing, then write that value (I32) before writing the B clusters.


Even if you don't know a priori how many B clusters you'll be writing (e.g. if this is a while loop with a random termination condition), You could take and remember the file position of the I32 number, just write a preliminary zero, then keep count when writing the elements. Overwrite that file position with the correct count once the loop has finished.

 

Still all this seems fragile.

0 Kudos
Message 6 of 7
(3,593 Views)

Thank you very much brother

0 Kudos
Message 7 of 7
(3,562 Views)