LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Basic Binary File Does not Read Unless Placed into Exact Format it originated?

Solved!
Go to solution

Ok, check this out.  This just does not make any sense to me.  First, you'll need to run it and create the two files.  You're going to get an error at the close.  Now...here's what doesn't make any sense to me.  If you enable the disabled diagram and read that same file, you can look at how the file is being read and the data interpreted.  How is that any different and not causing an error?  I took the U8 and changed it back to its original Boolean Array[8] format and received no error.  Which means the data was read as a U8 at some point.  But...for whatever reason, cannot be read and displayed as a U8.  What's up with that?  What am I not understanding?

0 Kudos
Message 1 of 6
(2,940 Views)

I'm really confused about what cases should be enabled and what not.

 

The only possible error I see in here is when you write the file you then try to read it before closing the file.  But the file pointer is still at the end of the file, so you should get an End Of File error.  If you set your file pointer to be at the start of the file after you wrote, then you would read your byte just fine.


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 2 of 6
(2,932 Views)

Huh....no read and write.  Either read or write.  Gotcha.

0 Kudos
Message 3 of 6
(2,926 Views)
Solution
Accepted by DailyDose

@DailyDose wrote:

Huh....no read and write.  Either read or write.  Gotcha.


Not quite.  It is a matter of where the file pointer is.

 

The file pointer is what location in the file will be read from or written to, depending on what you do next.  When you write to a file, the file pointer is set to be directly after what you just wrote.  So when you write a new file, the file pointer is at the end of the file.  So when you try to do a read when the file pointer is at the end of the file, an attempt of a read at the end of the file happens.  But there is nothing left for it to read.  Therefore you get an End Of File error.

 

So if you just added a Set File Position to set the file pointer to the start of the file, you can read your byte with no error.


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 4 of 6
(2,917 Views)

I understand now.  Thank you good sir!

0 Kudos
Message 5 of 6
(2,907 Views)

Actually, where the file pointer is set to depends a lot on the open mode for the File Open function. Open, Open and Create will indeed set it to the end of file. Create or Replace will however truncate the file to 0 length and place the file pointer at the beginning (well after truncation the beginning and end of file is the same).

Rolf Kalbermatter
My Blog
0 Kudos
Message 6 of 6
(2,893 Views)