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

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

saunwin

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

It should be b.Length - 1.
No Error's Erel, The sub just completes after 603 loops (it doesn't reach the end of the array, so wouldn't throw the error)
 
Upvote 0

saunwin

Active Member
Licensed User
Longtime User
Hi Erel,

I Think I've done this correctly.
 

Attachments

  • test.zip
    12.3 KB · Views: 473
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…