B4R Question Astream ser.ConvertBytes To Array Out of Bounds

rodmcm

Active Member
Licensed User
I am using prefix mode to send a test array to an ESP32 using code I have used before without issue and based on B4r tutorial

Send array
B4X:
Dim SendArray(8) As Byte  = Array As Byte(0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38)

The receiver code is
B4X:
    Log("From PAD")
    Log(Buffer(0),Buffer(1),Buffer(2),Buffer(3),Buffer(4),Buffer(5),Buffer(6),Buffer(7))
    Dim be(40) As Object 'used as a storage buffer. Can be a global variable
    Dim Data() As Object = ser.ConvertBytesToArray(Buffer,be)
    Log(Data(0),"   ", Data(1), "   ",Data(2),"   ",Data(3),"   ",Data(4),"   ",Data(5),"   ",Data(6),"   ",Data(7))


This is the only response

From PAD
4950515253545556
Out of bounds error. Array length = 40, Index = 65535


So the data is arriving, the problem seems to be in ConvertBytesToArray
I found someone else had this issue with Bluetooth resolved by Baud rates

I have also increased StackBufferSize =600

Any ideas please
 

rodmcm

Active Member
Licensed User
thetahsk
Thanks I had already tried that with no change

Erel
Yes Using B4rSerialization on both sides... I have used this technique lots without this issue


B4X:
  Log("From IPAD")
    Log(Buffer(0),Buffer(1),Buffer(2),Buffer(3),Buffer(4),Buffer(5),Buffer(6),Buffer(7))
    Dim be(20) As Object 'used as a storage buffer. Can be a global variable
    Dim bc As ByteConverter
    Log(bc.HexFromBytes(Buffer))
    Dim Data() As Object = ser.ConvertBytesToArray(Buffer,be)
    Log(Data(0),"   ", Data(1), "   ",Data(2),"   ",Data(3),"   ",Data(4),"   ",Data(5),"   ",Data(6),"   ",Data(7))

From IPAD
4950515253545556
3132333435363738
Out of bounds error. Array length = 20, Index = 65535
 
Upvote 0

kolbe

Active Member
Licensed User
I've just had this problem too and it's because I forgot that you need to use the class provided here (download and import code into a new project module) and not the B4XSerializator included with the jRandomAccessFile library. I guess it's confusing because B4RSerializer is included with rRandomAccessFile in the B4R IDE and you just assume what is in the JRandomAccessFile in the B4J IDE is compatible. I guess in your case it's B4i.

So... B4RSerializer is not compatible with B4XSerializer!
 
Upvote 0

rodmcm

Active Member
Licensed User
After two days I found that I had not initialized ser!!!!!!
That's what I get copying and pasting programs without looking at the detail.. Grrrrrrrrr!

Now all good
 
Upvote 0
Top