LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to read a strurture from a file?

In this case, it's right, but I'm not sure it's always right. How the LV can recognise the data type is beyond my comprehension.  In the file I want to read the size of the string changes from one structure to the next, but I know the size, so I want to control the size of string that I want to read.
0 Kudos
Message 11 of 23
(1,389 Views)
Do you write the file using LV vis? In LV help this is mentioned: Arrays and strings in hierarchical data types such as clusters always include size information.
 
So if you write it using LV, there should never be a problem. Otherwise I'm not sure.
Using LV8.0
--------------------------------------------------------------------
Don't be afraid to rate a good answer... 😉
--------------------------------------------------------------------
0 Kudos
Message 12 of 23
(1,389 Views)
The file I read is not created by LV. Smiley Sad
0 Kudos
Message 13 of 23
(1,386 Views)
Do you have a file available to have a look at?
Using LV8.0
--------------------------------------------------------------------
Don't be afraid to rate a good answer... 😉
--------------------------------------------------------------------
0 Kudos
Message 14 of 23
(1,385 Views)
The file I read is just the header of common bmp file which has a structure.
0 Kudos
Message 15 of 23
(1,380 Views)

Ok - so just read out a structure does not work. You have to read the string data and convert it on your own - or at least that's the only way that comes to my mind.

Using LV8.0
--------------------------------------------------------------------
Don't be afraid to rate a good answer... 😉
--------------------------------------------------------------------
0 Kudos
Message 16 of 23
(1,373 Views)
Ok, becktho, Thanks.
0 Kudos
Message 17 of 23
(1,358 Views)
You can also read the values directly from the file, one at a time, letting LabVIEW do the conversion.  Use the byte stream type input of the Read File primitive to set the type.  No need to read as a string, then convert, unless you want to read the entire header in one pass and convert to a cluster using Type Cast (which would probably be faster, but use a bit more memory).  If you use the latter method, you also need to be sure your data types line up perfectly and the cluster does not include any arrays (which are stored as handles in LV).
0 Kudos
Message 18 of 23
(1,352 Views)

Hi DFGray,

      Are you suggesting trinight might do 5 individual reads to obtain the structure?  Is it possible to read the string without explicitly providing/including its length?

When they give imbeciles handicap-parking, I won't have so far to walk!
0 Kudos
Message 19 of 23
(1,331 Views)


DFGray wrote:
unless you want to read the entire header in one pass and convert to a cluster using Type Cast (which would probably be faster, but use a bit more memory).  If you use the latter method...


Hi DF,

      If I understand this correctly, it suggests wiring a string (read from file) into the typecast, and wiring the "target" cluster to the type-terminal, is that correct?  When I try this it breaks as soon as I add the string to the cluster - which makes sense, because LaBVIEW has no way of determining from the raw data how long a string is.


When they give imbeciles handicap-parking, I won't have so far to walk!
0 Kudos
Message 20 of 23
(1,329 Views)