LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

manipulating byte information - byte conversion

So I have a binary file... this binary file always contains a header, which contains important information.... with a length of 834-bytes.

 

I have a few 16-bit numbers I want to manipulate located at (65,66) (67,68) (69,70) (71,72)

 

the other information is in a variety of formats be it floating integers, strings, etc.....

 

My question... Can I convert my entire 834 - byte array into a 417 length array of 16-bit integers, manipulate the data I need, then convert it back and have all the other information remain unchanged?

 

 

Download All
0 Kudos
Message 1 of 6
(2,134 Views)

Sure.  You could do that.  Bytes are bytes.  So if you convert bytes to U16's and don't touch them, they should convert back to bytes just fine.  And the ones you do touch should convert back to different bytes.

Have you tried?  Your VI really doesn't show a conversion, just a reading of data from the file.

0 Kudos
Message 2 of 6
(2,123 Views)

Sure, you should be able to do that with judicious use of "Set File Position".

 

My (pretty strong) recommendation: don't do your first trials operating in-place on your original files.  Copy any such files into a "sandbox" folder for testing.  This will let you try it out and make sure you've got your offsets, your endian-ness, and your integer data types defined correctly.

 

Also: be very careful to think through error handling -- there are only 2 acceptable end results of trying to change your binary file in place:

1. All changes were performed with no errors

2. No changes were performed and the program alerts you to this fact.

 

For such a small file, I might take a more cautious approach like this:

1. rename original file with some kind of temp name

2. read the entire 834 byte content

3. manipulate only the bytes in question

4. write the partly-manipulated bytes out to a new file that reuses the original filename, then close the file.

5. read both before and after files and verify that all non-manipulated bytes agree.  If so, delete the temp file.  Else, delete the new file (with original filename), rename temp file back to original name, and alert operator that the manipulations weren't successful.

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 3 of 6
(2,108 Views)

Call me paranoid, but I would write an encoder/decoder VI pair for the entire message, decode the message, change the stuff you want, then encode the new message to a new file.  (I might even grab the whole IDD and at least read it, but that's being even more paranoid.)  I never met an engineering tool that didn't grow up to be a full-fledged app.  This would give you a big head start.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 4 of 6
(2,068 Views)

@billko wrote:

Call me paranoid, but I would write an encoder/decoder VI pair for the entire message, decode the message, change the stuff you want, then encode the new message to a new file.  (I might even grab the whole IDD and at least read it, but that's being even more paranoid.)  I never met an engineering tool that didn't grow up to be a full-fledged app.  This would give you a big head start.


IDD?  What does that mean?

0 Kudos
Message 5 of 6
(2,026 Views)

Personally, I think I would just create the giant cluster to cover the entire header and just use Read Binary File to read 1 of those clusters.  You can then pinpoint by name (Unbundle By Name) the value(s) you want to update.  I guess this would be along the same lines as what billko was saying.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 6 of 6
(2,000 Views)