B4R Question Converting received bytes to array, data.Length always 0...

Csigabi Gaboca

New Member
The example found in the forum unfortunately does not work for me :-(
It displays the contents and size of the buffer correctly, but the length of the data is already 0, so of course I can't read the bytes one by one either.

B4X:
Sub AStream_NewData (buffer() As Byte )
   Dim be(10) As Object 'used as a storage buffer. Can be a global variable
   Dim data() As Object = ser.ConvertBytesToArray(buffer, be)

   Log("NewData: ", buffer)
   astream.Write("Echo from ESP32: ")
   astream.Write(buffer)
   bt.Stream.Flush

   a = buffer.Length
   Log(a)
  
   Log(data.Length)
   Log("-")
   Log(data(0))
   Log(data(1))
   Log(data(2))
   Log("---")

End Sub

Thanks or help....
 

OliverA

Expert
Licensed User
Longtime User
Dim data() As Object = ser.ConvertBytesToArray(buffer, be)
This line assumes that buffer contains serialized data. Is that so? Where is the code that serializes the data?
 
Upvote 0

Csigabi Gaboca

New Member
This line assumes that buffer contains serialized data. Is that so? Where is the code that serializes the data?
I misunderstood the serializer, I don't need it, since the buffer can also be read simply byte by byte.
Thanks for the help! :)

B4X:
Sub AStream_NewData (buffer() As Byte )
''  Dim be(10) As Object 'used as a storage buffer. Can be a global variable
''  Dim data() As Object = ser.ConvertBytesToArray(buffer, be)

   Log("NewData: ", buffer)
   astream.Write("Echo from ESP32: ")
   astream.Write(buffer)
   bt.Stream.Flush

   a = buffer.Length
   Log(a)
 
''  Log(data.Length)
   Log("-")
   Log(buffer(0))
   Log(buffer(1))
   Log(buffer(2))
   Log("---")

End Sub
 
Upvote 0
Top