Android Question ByteConverter not work in Android 9 and higher

Hello ,
I created an app that communicates via tcp with an instrument using also the byteconverter 1.1 library on the android 5 version.
The problem is that it doesn't work with android 9 or higher.
Can you help me please.
thank you
 

Attachments

  • error.jpg
    error.jpg
    75.4 KB · Views: 121

Star-Dust

Expert
Licensed User
Longtime User
Hello ,
I created an app that communicates via tcp with an instrument using also the byteconverter 1.1 library on the android 5 version.
The problem is that it doesn't work with android 9 or higher.
Can you help me please.
thank you
It does not indicate that the library is not working, rather there is an error in the code.
You use an empty string
 
Upvote 0
Thanks for the reply,
I tried simultaneously between android 6 and android 10, in the point where I put the ToastMessageShow to check the output value I get a different value between the two devices



Code:
Sub SendHRDmessage(messagee As String)
    
    Dim nSize,nSanity1, nSanity2,nChecksum, nZero, lngt,i As Int
    'StringToBytes (bc As String) As Byte()
    
    Dim bc As  ByteConverter
    Dim header(4) As Int
    Dim strMessage, S As String
    nZero = 0
    strMessage = messagee & " "
     bc.LittleEndian = True
    lngt=bc.StringToBytes(strMessage,"UNICODE").Length
    Dim bytData(lngt) As Byte
    bytData = bc.StringToBytes(strMessage,"UNICODE")
    lngt = 16 + bytData.Length - 2
    Dim byAll(lngt) As Byte
    header(0) = lngt
    header(1) = 0x1234ABCD
    header(2) = 0xABCD1234
    header(3) = nZero

    bc.ArrayCopy(bc.IntsToBytes(header),0,byAll,0,16)
    bc.ArrayCopy(bytData,2,byAll,16,bytData.Length-2)
    sHRDanswer = ""
    'bCmdDone = False
    AStreams3.Write(byAll)
    ToastMessageShow(bytData, True)
End Sub
 

Attachments

  • 6.jpg
    6.jpg
    323.2 KB · Views: 116
  • 10.jpg
    10.jpg
    226.3 KB · Views: 118
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I tried simultaneously between android 6 and android 10, in the point where I put the ToastMessageShow to check the output value I get a different value between the two devices
You forgot to post the requested full Errormessage from the log. Post it as Text.
 
Last edited:
Upvote 0
Thanks for the reply,
for the moment we do not consider the error message that occurs because I actually have an empty string.
The program through a timer sends some requests to the radio: get frequency, get smeter-main, this is the message and then adding a space becomes strMessage and then is converted into unicode.
At this point the radio responds by sending the frequency and the signal.
The point is that it seems that the conversion is wrong because the radio is not responding and in addition the ToastMessageShow you read on the photos are different.
What do you think?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0
I don't seem to have a communication problem between client and server but a language difference.
I converted the output bytes to string and there are differences between android 6 and 10, they are symbols in the middle 4 4 on android 10, instead on android 6 which works well the symbols are not there.
please look at the photos
 

Attachments

  • Immagine1.png
    Immagine1.png
    74.5 KB · Views: 96
Upvote 0
sorry, I understand now how to use the log.
I attach photos
there are 2 more symbols at the beginning of the sentence and two less at the end, I don't know why
thanks
 

Attachments

  • log.png
    log.png
    8.6 KB · Views: 106
Upvote 0
Good morning ,
I solved ,
in the line I posted in the android 6 version it works with 16 bytes while in the android 10 version I had to put 15 bytes.
I don't know if it depends on byteconverter or not.
Now I made a variable that controls the SDK version, if it is below 23 it will use 16 bytes, if it is above it will use 15 bytes.
Thanks for the help.
Regards

B4X:
 bc.ArrayCopy(bytData,2,byAll,16,bytData.Length-2)
Variable
B4X:
Sub GetSDK() As Int
    Dim p As Phone
    Return p.SdkVersion
    
End Sub
Sub Activity_Create(FirstTime As Boolean)
    GetSDK
    ver_phone=(GetSDK)
    If ver_phone <24 Then
        dimensione_riga=16
        
    Else
    End If
    If ver_phone >25 Then
        dimensione_riga=15
        
    Else
    End If

the final code

B4X:
bc.ArrayCopy(bytData,2,byAll,dimensione_riga,bytData.Length-2)
 
Upvote 0
Top