LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to read a strurture from a file?

Hi, I want to read a structure form a file(for example: a bmp file), I write a vi, but I don't know how to deside the size of the string, the structure is
 
string 5
DBL   1
U8      1
SGL   1
U32    1
Download All
0 Kudos
Message 1 of 23
(3,672 Views)

Hi trinight,

I'm not familier with the file-functions depicted in your diagram! - are they LV8?

If you know the number of chars in the string, then you know the number of bytes in the "structure", and you should be able to read that number of bytes - then convert those bytes to the LVtypes shown.  Is that what you want to do?

When they give imbeciles handicap-parking, I won't have so far to walk!
0 Kudos
Message 2 of 23
(3,660 Views)
yes, Dynamik. I am using  LV8 and I know the size of the string, I want to read the structure using the cluster which is the data type. In the cluster I don't know how to deside the size of the string.
0 Kudos
Message 3 of 23
(3,652 Views)
You could read the data as string and then use the scan from string function to get your values.
Using LV8.0
--------------------------------------------------------------------
Don't be afraid to rate a good answer... 😉
--------------------------------------------------------------------
Message 4 of 23
(3,646 Views)

Is that possible reading the data in the type as I defined in the cluster for one time?

0 Kudos
Message 5 of 23
(3,643 Views)
Attached you find a picture of how this would look like - the only point to take care for is the format of the numbers. Also have a look in the LV help (search for "Format Specifier Examples").
 
 
Using LV8.0
--------------------------------------------------------------------
Don't be afraid to rate a good answer... 😉
--------------------------------------------------------------------
0 Kudos
Message 6 of 23
(3,642 Views)
THanks, becktho, your vi works well, but I really want to learn using the "read from binary file" function to read the structureSmiley Happy 
0 Kudos
Message 7 of 23
(3,636 Views)

Have a look at the attached vi.

I don't know if you could read any binary file (because you mentioned bmp) that was not written with exactly this structure.

Using LV8.0
--------------------------------------------------------------------
Don't be afraid to rate a good answer... 😉
--------------------------------------------------------------------
Message 8 of 23
(3,633 Views)
In your vi, your creat a file and read the file. The first several bytes are string type, but they  also can by other data type , my question is how to contral the size of string I want to read. For example, the string of the first cluster in your file are "Data0001", if I want to read only "Data" then "0001" can be I32 data type, that is how to set the number of the string I want to read.
0 Kudos
Message 9 of 23
(3,629 Views)
I'm not sure how exactly it is coded by NI, but there must be some kind of "entry-markers". As you can see, I just placed an empty string constant in the cluster, but it get's all datasets correctly.
You could also place a String in between the numbers, and everything is read correctly.
If you have a look at the file written, you also see that the Strings are ASCII and the numbers really are binary. So obviously in the file you want to read the combination you described should not occur.
 
Is the file you want to read written by someone else?
 
Do you have an example file and do you know data that should be available?
Using LV8.0
--------------------------------------------------------------------
Don't be afraid to rate a good answer... 😉
--------------------------------------------------------------------
0 Kudos
Message 10 of 23
(3,626 Views)