LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to create a polymorphic binary file?

Solved!
Go to solution
I need to have a LV application create what I think is a polymorphic binary file. In other words, the data is obtained from a variety of data types.  For example, the file needs to contain the following data: First byte = Alpha Character (i.e. Q, which is ASCII decimal number 81 )Next byte = 8-bit Unsigned number (i.e. U8 representation)Next four bytes = SGL Floating Point Number (It's my understanding that an SGL number contains four bytes.)Next four bytes = SGL Floating Point NumberLast byte = 8-bit Unsigned number The resulting file will be read by another (non-LV) application.  Is there a way to do this?  I’m using WIN-XP and LV v.8.5.1. Dave
0 Kudos
Message 1 of 7
(3,822 Views)
Solution
Accepted by topic author dj143

Hi dj,

 

typecast all those values to either string or array of U8, then write the file.

A binary file is just a collection of bytes, so you can write just bytes...

 

Edit:

You don't need to typecast, you can wire all those values directly to WriteBinaryFile functions. This function is polymorphic...

 

Dis-/Advantages:

- using typecast and build string you can limit the number of file accesses, working in memory is usually faster than disk access

- using polymorphism of WriteBinaryFile you can limit memory needs of your program with the disadvantage of having a lot more file accesses

 

Choose what best fits your needs...

Message Edited by GerdW on 02-01-2010 07:49 PM
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 7
(3,817 Views)


You don't need to typecast, you can wire all those values directly to WriteBinaryFile functions. This function is polymorphic...

 


Yea, if you just write the raw data to binary, as long as you read it out as the same adapter you will be able to interface with this file from any programming language.

0 Kudos
Message 3 of 7
(3,788 Views)

At first I attempted to save the file from a cluster of the various data objects.  However, it did'nt work and I then sent the question to the forum.  Gerd's comment that a binary file is a collection of bytes got me to thinking to append the binary write functions.  Attached is a screen shot of the code, which is now working for my application.  The purpose of the four write functions that has the constant is used as "dummy" bytes in an effor to be compatible with the other system.  Although I have not tryied the typecast method, perhaps there is a more elegant way to this other that what is shown in the attached.

 

Thank you for your responses.

 

Dave

0 Kudos
Message 4 of 7
(3,769 Views)
I hate when I forget to make the attachement...
0 Kudos
Message 5 of 7
(3,766 Views)

Dave

 

Check out this code. You can write any cluster directly into the write to binary file VI. Then use cluster constant of the same type (or the same cluster)to read the binary data out as the same data type.

 

Read and Write Cluster to Bin file.png

 

-Hunter

0 Kudos
Message 6 of 7
(3,739 Views)

Hi Hueter,

 

Sorry it took so long to respond.  I was sidetracked on other projects.  I am not able to use the cluster method, which is similar to the first attempt.  I had to go back to using the code shown on Feb 2nd.  By the way the code shown on the 2nd does not have the Byte Order constant connected to all the file write functions as they should have been.

 

Thanks,


Dave

0 Kudos
Message 7 of 7
(3,605 Views)