LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

read binary file made with VB

Hi there,

 

Here is something I never did, so a little help is welcome 🙂

 

I have a binary file made with VB and I want to read it with LabVIEW 8.5.

I know the structure of the records in the file, it's something like: 

    str1      As String * 5
    str2      As String * 6
    str3     As String * 2
    date      As Date
    str4     As String * 20
    str5   As String * 20
    int1       As Integer  

    flt1    As Single 
    flt2     As Single
    flt3      As Single

and so on.

 

Further on there's even a 2D array: 3 rows, 400 cols of singles.

The total length of one record is 5120 bytes.

 

I can pick up whatever record from the file using the "Set file positions" & "Read from binary file" vi's but how do I convert those 5120 bytes in the correct structure?

 

I was thinking of a cluster but how do I define a fix string length in LV?

Also, is a cluster the right way to go?

 

So, like I said any help is welcome 🙂

Thanks

0 Kudos
Message 1 of 8
(3,496 Views)

Alain S wrote:

I was thinking of a cluster but how do I define a fix string length in LV?

Also, is a cluster the right way to go?

 

So, like I said any help is welcome 🙂

Thanks


Defining a fixed sized string officially not possible, and even the non official way will get you bugs, so let's do the official route.

 

First open up the file with a hex editor, I normally use the Total Commander's built in F3, and then hit '3' to get a hex view. In that view I check wheter the lenght of the string is prepended to the string (Pascal and LabVIEW style) or ended with a Null (C style).

If none of them is happening, I would use a cluster of 5 U8's to get the string, convert this cluster to an array, and convert that to a string.

I have no idea what a 'Date' representation is in VB.

 

A cluster is very suitable for this task, however I do not get the info about the 2D array, if you could add a data file that would be very helpfull.

 

 

Ton

Message Edited by TonP on 28-08-2009 08:44 PM
Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
0 Kudos
Message 2 of 8
(3,491 Views)

Ton is right about the cluster. You will have to treat the embedded fixed size strings as clusters of that many integers. And the funny part here is that VB strings are probably even when written to disk, Widechar (16Bit Unicode) strings. I have also no idea what a Visual Basic Date is. It could be an integer with secnds since some arbitrary date, or a floating point with days or seconds since such a point or a structure (cluster) with the individual date and time components.

 

For the 2D array you simply want to read in 1200 single floating point values (4800 bytes) and convert them into a 1D array of singles and then reshape that array to your specs. The problem I see is that I do in no way get to a size of 5120 bytes for all this unless your structure in the beginning is a bit longer.

 

Rolf Kalbermatter

Rolf Kalbermatter
My Blog
0 Kudos
Message 3 of 8
(3,467 Views)

Thanks for the reactions guys!

To use Ton's suggestion regarding the "Byte array to string", I now read one record as an array of U8's.

Then I loop through the complete array and convert a specific amont of bytes to strings and integer with no problem.

Still have some troubles with the Date and the Singles 😞

The result of that first single I have now is wrong due to endians? or ??????   I have to review the datatypes in both LV & VB !

 

You are right Rolf, the 2D array are just 4800 singels to read and reshape Smiley Happy

But first I have to read singles in the correct way Smiley Surprised

 

For the 5120 bytes, I wrote only some of the datafields from one record. There are 29 items in total that uses 5120 bytes.

 

Attached the latest status of my decoder vi.

I don't use the cluster for now since these are just trials to convert the byte's into correct datatypes

 

So if someone knows how to convert the bytes to Single & Date that would spare me a lot of research 🙂

0 Kudos
Message 4 of 8
(3,456 Views)

Well if you work in LabVIEW 8.6 or better you could directly use the Read from Binary File function and set its byte order input to little endian. You can even read in compete clusters although will have to treat the fixed size strings as clusters of that many characters (most likely 16bit integers since they are widechars). This will make sure to treat integers and floating point values according to the little endian encoding.

 

Rolf Kalbermatter

 

 

Rolf Kalbermatter
My Blog
0 Kudos
Message 5 of 8
(3,440 Views)

All problems solved Smiley Very Happy

Biggest problem was the Date datatype from VB6.0, but after reading some papers about VB6.0 datatypes I managed to convert the 8 U8 bytes to a LV TimeStamp 🙂

If someone ever need such conversion, feel free to ask for my solution. 

 

Case closed!

 

0 Kudos
Message 6 of 8
(3,432 Views)
Why not just post your solution in this thread while it is fresh in your mind?  That way if someone is searching for the same problem and they discover your thread, you will have solved it for them.Smiley Wink
Message 7 of 8
(3,428 Views)

Ravens Fan wrote:
Why not just post your solution in this thread while it is fresh in your mind? 

Because the vi's are well documented Smiley Indifferent, so that even within 10 years I still know how it works Smiley Tongue

But since you asked so nicely, here are the solutions for both single (was quite easy) and date (was a little harder to beat).

 

Keep in mind this is for date stored in VB6.0 format not VB.net!!

Dates are stored in another way in VB.net.

Download All
Message 8 of 8
(3,411 Views)