Showing results for 
Search instead for 
Did you mean: 

How to create a polymorphic binary file?

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
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...



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



- 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,
CLAD expired, using LV2011SP1 + LV2017 (+LV2019 sometimes) on Win7+cRIO
Kudos are welcome Smiley Wink

Message 2 of 7

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

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.



0 Kudos
Message 4 of 7
I hate when I forget to make the attachement...
0 Kudos
Message 5 of 7



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



0 Kudos
Message 6 of 7

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.




0 Kudos
Message 7 of 7