B4R Question Problem using B4RSerializator

Mike Parris

Member
Licensed User
Longtime User
Problem with B4RSerializator. My hardware is an Elegoo Uno R3

The problem is getting the data back from the Serializator.

I am sending a 4 byte number (B4A int) from a B4A app via Bluetooth using the B4R Serializator.
Logging the detail from the Array returned by the Serializator produces the correct data. However trying to store the number as a B4R long gives me a totally incorrect result.
If I get the number as a string this gives the correct result.
However, converting the String to a Long integer gives the correct number but always with an small error of 64.

Example code attached (Output from log shown in comments)

Something strange is going on here, can anyone point me to a solution? All the examples on the Internet end with a Log statement.

B4X:
  Sub AStream_NewData (Buffer() As Byte)
    
    Dim be(50) As Object 'used as a storage buffer. Can be a global variable
    Dim data() As Object = ser.ConvertBytesToArray(Buffer, be)
    If data.Length = 0 Then Return 'invalid message
    
            ' Sent from B4A                1618977600
    Log ("Data1 = ", data(1))            ' 1618977600
    Dim ObjectData1 As Object = data(1)
    Log(" Object Data1 = ", ObjectData1) ' 1618977600
    Dim LongData1 As Long = data(1)
    Log("Long Data1 = ", LongData1)      ' 1148
    Dim StringData1 As String = data(1)
    Log ("String Data1 = ", StringData1) ' 1618977600
    Dim StringToLongData1 As Long = StringData1
    Log("StringToLong data1 = ", StringToLongData1)   '  1618977536      - error of -64
 

rodmcm

Active Member
Licensed User
 
Upvote 0

Mike Parris

Member
Licensed User
Longtime User
Thanks for the reply. I am sending an Int (4 bytes) from B4A to B4R and receiving it as a B4R long (4 bytes). So your suggestion is not the issue.
Also, my code from B4R to B4A (not shown) works fine.
 
Upvote 0

Mike Parris

Member
Licensed User
Longtime User
OK,
I have to own up, this was due to a coding error in my B4A code, I was sending strings and not integers.
Sorry for the trouble caused. I should have had more confidence in B4R and checked my code more carefully before posting here.
 
Upvote 0
Top