LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to read a strurture from a file?

The ordering of your wiring is important.  You need to wire the type input first, then the string.  I know this is weird, but it works (I tried for LV 7.0 - 8.0).  Just be very sure the data sizes are the same, or you can crash LV and maybe your OS (buffer overruns anyone?).  You can fetch the data as an array of U8s for a slightly more lightweight operation.  Note that the internal LV string format does include the length.  However, you are correct in that LV will not know the length, a priori, of a string read from a file.
0 Kudos
Message 21 of 23
(664 Views)
Hi, DFGray. I don't understand what you mean, can you attach a vi example? If the structure contain array, how to read it? 
0 Kudos
Message 22 of 23
(663 Views)
Here is a simple example of using a typecast on a string.  Both the string and the cluster are 8 bytes in length, allowing the typecast to work correctly.  Run the VI and you will see that each integer is composed of four hex "30"s.  0x30 is the ASCII code for 0.  In practice, the string would come from your file read.

If you have an array in the cluster in the file, you will need to read each element individually and create the cluster in LabVIEW using the bundler.  For a BMP file, you will only run into this with the color map.  The other header info is fixed length, so you should be able to read it and use the typecast trick.  Note that you don't have to use the same structure in your program as the file uses if you don't want to.  Use whatever is easiest for you.
0 Kudos
Message 23 of 23
(644 Views)