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

  2. ElliotHC

    ElliotHC Active Member Licensed User

    You're probably right.
     
  3. sorex

    sorex Expert Licensed User

    also check that the bytes() array is big enough and try

    Code:
    job.GetInputStream.ReadBytes(bytes,0,bytes.Length)
     
  4. sorex

    sorex Expert Licensed User

    by the way... I see that your msg has 7 00's prefixed. maybe you just need to add 7 extra bytes to the msg (lenght)?

    or figure out where those 00's are coming from and remove them.
     
  5. ElliotHC

    ElliotHC Active Member Licensed User

    I think I have found an issue.

    When I try and send this which should be 74 bytes.

    Code:
    Dim Bytes_40 As String
            Bytes_40 = 
    "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"
            
    CallSub2(Starter, "SendMessage", Bytes_40.GetBytes("utf8"))
            
    CallSub2(Starter, "SendMessage", Bytes_40.GetBytes("utf8"))
    I get this which is only 40...

    upload_2019-5-29_15-14-33.png

    Shows that my PIC has no issues getting 40, so why are these two strings getting cut off at the 20 byte point?
     
  6. ElliotHC

    ElliotHC Active Member Licensed User

    That was just some stray 0's, I've now set my code only to output when it sees more than one byte coming in..
     
  7. ElliotHC

    ElliotHC Active Member Licensed User

  8. sorex

    sorex Expert Licensed User

    ok, then you need to use a send loop based on div & mod 20
     
    ElliotHC likes this.
  9. ElliotHC

    ElliotHC Active Member Licensed User

    Thanks sorex, is there an example posted?
     
  10. sorex

    sorex Expert Licensed User

    sorry my work day ended and I just got behind my laptop at home.

    I'll see if I can give you an example.
     
  11. ElliotHC

    ElliotHC Active Member Licensed User

    Thanks, I did it but it's messy.

    Code:
    Log(job.GetString)
            
            
            
            job.GetInputStream.ReadBytes(bytes,
    0,job.GetInputStream.BytesAvailable)
            
    Dim Bytes20(20As Byte
            
    Log("Data Length=" & (job.GetInputStream.BytesAvailable - 1))
            
            
    Dim Loop_Counter As Int
            
            
    For x = 0 To job.GetInputStream.BytesAvailable - 1



                
    For X2 = 0 To 19' X2_Top
                    Loop_Counter = Loop_Counter + 1
                    Bytes20(X2) = bytes(x + X2)

                
    Next
                    
                
    CallSub2(Starter, "SendMessage",Bytes20)
                
    ' Wait for the next send byte request
                For X3 = 0 To 2
                    
    If Packet_Requested = False Then   
                        X3 = 
    1
                        
    Else
                            
    Log("Packet Recieved")
                    
    End If
                
    Next
                Packet_Requested = 
    False
                
                x = x + 
    20
            
    Next
     
  12. sorex

    sorex Expert Licensed User

    ok, here my attempt but I couldn't verify if it's correct.

    Code:
    Public Sub SendMessage(msg() As Byte)
        
    Dim xv As Int
        
    For x=0 To msg.Length-1 Step 20
            xv=
    20
            
    If msg.Length-x<20 Then    xv=msg.Length Mod 20
            
    Dim mybytes(xv) As Byte
            
    For b=0 To xv-1
                mybytes(b)=msg(x+b)
            
    Next
            manager.WriteData(ServiceId2, WriteChar2, mybytes)
        
    Next
    End Sub
     
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