1. *** New version of B4J is available ***
    B4J v7.8
    Dismiss Notice

Android Question Reading a data file 0-255

Discussion in 'Android Questions' started by ElliotHC, May 29, 2019.

  1. ElliotHC

    ElliotHC Active Member Licensed User

    Sorry, I didn't use the ToUnsigned. Been up all night :confused:
     
  2. sorex

    sorex Expert Licensed User

    uncomment this one which does the same as that extra sub

    Code:
    'Log( Bit.And(bytes(x),255))
     
    ElliotHC likes this.
  3. ElliotHC

    ElliotHC Active Member Licensed User

    Which will be quicker if it's a large file? Or will both take a similar time * 64k
     
  4. sorex

    sorex Expert Licensed User

    it's faster since you don't have the overhead of calling and ending the subs which does extra stack operations but for 64K we probably talk about mili or nanoseconds.
     
  5. ElliotHC

    ElliotHC Active Member Licensed User

    Those kinds of seconds I like!

    Why is it that if I feed it back in to a byte array I lose it again?


    Code:
    For x = 0 To job.GetInputStream.BytesAvailable - 1
                Bytes_to_Send(x) = 
    Bit.And(bytes(x),255)
                
    Log(Bytes_to_Send(x))
            
    Next
    When I look at this it goes back as before.

    The reason this is an issue is that I need to use this Sub to send it out of the BT

    Code:
    Public Sub SendMessage(msg() As Byte)
        messagesToSend.Add(msg)
        
    If messagesToSend.Size > 1 Then
            manager.WriteData(ServiceId2, WriteChar2, msg)
        
    End If
    End Sub
    So I am trying to use this:

    Code:
    For x = 0 To job.GetInputStream.BytesAvailable - 1
                Bytes_to_Send(x) = 
    Bit.And(bytes(x),255)
                
    Log(Bytes_to_Send(x))
            
    Next
            
      
            
    CallSub2(Starter, "SendMessage", Bytes_to_Send)
    But I'm only sending Characters again :(
     
  6. ElliotHC

    ElliotHC Active Member Licensed User

  7. sorex

    sorex Expert Licensed User

    each time you read out a byte from a byte array it's signed again so you need to apply that bit.and again.

    if you store it into an int array you will read out the value as you stored it.

    what is the highlighted yellow line in the log and what is it supposed to be?
     
    Last edited: May 29, 2019
  8. ElliotHC

    ElliotHC Active Member Licensed User

    That's my data coming in to the Micro via the Bluetooth serial module.. So B4A App(BT Transparent Serial Connection) <OTA> BT Module > PICMICRO

    So in this sub:

    Code:
    Public Sub SendMessage(msg() As Byte)
        messagesToSend.Add(msg)
        
    If messagesToSend.Size > 1 Then
            manager.WriteData(ServiceId2, WriteChar2, msg)
        
    End If
    End Sub
    How do I get that byte array 'msg' to be unsigned bytes when it goes out?
     
  9. sorex

    sorex Expert Licensed User

    I guess you'll need to do it on the other side when/where you read it out again.

    I guess the writedata sends it correct unless the source (bytes array) has incorrect data.
     
  10. ElliotHC

    ElliotHC Active Member Licensed User

    I go from here:

    Code:
    job.GetInputStream.ReadBytes(bytes,0,job.GetInputStream.BytesAvailable)
     

            
    CallSub2(Starter, "SendMessage", bytes)
    To here:

    Code:
    Public Sub SendMessage(msg() As Byte)
        messagesToSend.Add(msg)
        
    If messagesToSend.Size > 1 Then
            manager.WriteData(ServiceId2, WriteChar2, msg)
        
    End If
    End Sub
    I don't see how I can get it to send out in individual bytes.

    Surely If I just to a for next loop and load the Bytes array in to the msg array I'm going to face the same issue where it's sending it out as a string?
     
  11. sorex

    sorex Expert Licensed User

    but the log that you posted where is that coming from?

    is that pulled from that micro controller's console?
     
  12. ElliotHC

    ElliotHC Active Member Licensed User

    Yes, the programmer is connected to the PIC and I'm sending it out of the PIC. It's sending the decimal value of the bytes coming in. That is 100% sound as it doesn't to any singing or anything like that.
     
  13. ElliotHC

    ElliotHC Active Member Licensed User

    I've been coding with the Firmware Basic compiler since 2005 so I know my way around that, VB since about 2008. I've only been using B4A and B4J for a short while so I know little about how it works.

    I can tell you that I'm only sending ASCII characters using this method.. It's not been a problem up to now as the App data has been text.. Now I need to send byte values 0-255 as I'm sending the MIcro HEX file which is encrypted.

    The other option is to send the values as comma separated text values.. But seriously? That will make the file 4 times larger.
     
  14. sorex

    sorex Expert Licensed User

    it seem to be correct. You're confused with hex & int values.

    Code:
    Dim t As String="84 72 73 83 32 73 83 32 84 72 69 32 70 73 82 77 87 65 82 69"
    Dim data() As String
    data=
    Regex.Split(" ",t)
    t=
    ""
    For x=0 To data.Length-1
     t=t & 
    Chr(data(x))
    Next
    Log(t)
    the log shows: THIS IS THE FIRMWARE

    which is also seen in a screenshot of your in an earlier post.
     
  15. ElliotHC

    ElliotHC Active Member Licensed User

    I'm sending "THIS IS FIRMWARE<009>12<240>45" but you can't see the 9 or 240 in the log

    upload_2019-5-29_13-35-4.png
    upload_2019-5-29_13-35-24.png
    What is actually coming in:

    upload_2019-5-29_13-35-53.png
     

    Attached Files:

  16. ElliotHC

    ElliotHC Active Member Licensed User

    It's almost as if it's stopped sending the data or stopped filling msg when it hits a byte that isn't stringable.
     
  17. sorex

    sorex Expert Licensed User

    are you sure that part of the data is in the file that is on that webserver and that you don't pull in a cached version of that file
     
  18. ElliotHC

    ElliotHC Active Member Licensed User

    I think that when I send bytes over to here

    upload_2019-5-29_13-46-11.png

    Using this

    upload_2019-5-29_13-46-34.png

    I am signing the bytes? This means that it's not sending the 9, in fact it stops filling the array or stops sending.
     
  19. sorex

    sorex Expert Licensed User

    compare log( job.GetInputStream.BytesAvailable ) with the filesize on the server
     
  20. sorex

    sorex Expert Licensed User

    you're doing not but just logging the data. the data is still signed in the array which is normal.

    the problem is somewhere else
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice