Jump to content
  • 0

FileWriteBinary results in 0x0000 content


OE3CPA

Question

Hi to the forum,

I like my Digital Discovery and made a project to take HP Singnatures (historic method for HP instruments) and reading ROM images.

All is working well, except for the last step.

I have filled up an array called "romOutData" by:

var romOutData = []:  // for init ...

romOutData.push (rgValue [i]);    // to read values into OutData

And at the end I use:

FileWriteBinary("/tmp/x.bin", romOutData);   // write file

I successfully creates a file, it has the expected length of 8192 bytes (there are 8192 entries in romOutDate.length), but hexdump shows all 8192 values with zeros (0x00) ....

Reading out with a for loop is OK:

for (var i = 0; i < romOutData.length; i ++) {
    print ("romOutData [", i, "] = ", romOutData [i]);
}
print("len = ", romOutData.length);

... delivers ...

:
:

romOutData [ 8188 ] = h80
romOutData [ 8189 ] = hBA
romOutData [ 8190 ] = h04
romOutData [ 8191 ] = h51
len = 8192

So the fields have the correct values, but the file has only zeros. Is this a data type issue ?
What is the correct way to handle binary files and byte arrays in the script language of Discovery products ?

-----------------------
I use 3.22.23 (beta) on Linux 64bit Ubuntu 24.04 with Digital Discovery
----------------------

Greetings
Chris

Edited by OE3CPA
Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Hi @OE3CPA

The values are strings. Use parseInt("0x"+rgValue[i].substring(1)) to convert to number.
FileWriteBinary expects/writes array of bytes/characters. If you need, you can use File object methods for other types of data.

image.png

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...