B4J Question Reading a file to list

saunwin

Active Member
Licensed User
Longtime User
Good morning,

I have a HEX file that I've chosen with file chooser and read into a list.

B4X:
Dim List1 As List
    List1.Initialize
        List1 = File.ReadList(File.GetFileParent(filename), File.GetName(filename))
            For i = 0 To List1.Size - 1
            Log(List1.Get(i))
            Next

Next step is to transmit this list/hex file to a microcontroller (over an opened com port). How would I do this ?
Hints, tips, advice, gratefully received - Many thanks in advance
 

saunwin

Active Member
Licensed User
Longtime User
Hi Steve, Yes I have comms between the PC and the micro, it's getting the list into a byte array suitable from transmission (I think) I'm struggling with.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Then you should probably use the jRandomAccessFile Library and it's Read as bytes Method.
 
Upvote 0

saunwin

Active Member
Licensed User
Longtime User
Hi Erel,
Thanks for the advice. I seem to be missing some bytes.
The code is below and the log will log b.length correctly as 36133
the loop will only log 603 values ?

Any idea what's happening here.
Many thanks in advance.

B4X:
Dim b() As Byte = Bit.InputStreamToBytes(File.OpenInput(File.GetFileParent(filename), File.GetName(filename)))
   Log (b.Length)
        For x =0 To b.Length
            Log (x &" - " & b(x))
    Next
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Don't you see an error with this code?

It should be b.Length - 1.

Then it ill be one byte less

But 36133 (b.length) - 603 (log output in lines) = 35530 missing bytes.

Or did i miss something? ;-)
 
Upvote 0
Top