M Michael Sergio Member Licensed User Longtime User Jan 25, 2018 #1 Hi. Please help me i don`t understand how this works. I`m trying to send this data for example from one arduino to another via RF24L01 with rRF24 library. SERVER: Code: Dim b() As Byte = Array As Byte(14, 5500) raf.WriteBytes(b, 0, b.Length, 0) rf24.Write(buffer) CLIENT: Code: Sub rf24_NewData (Data() As Byte) raf2.Initialize(Data, True) Dim b() As Byte = raf2.ReadBytes2(2, raf2.CurrentPosition) Dim i() As Int=bc.IntsFromBytes(b) Log(i(0),i(1)) End Sub I`m having "Out of bounds error. Array length = 1, Index = 1" If i do "Log(b(0),b(1))" then it works but i have the result in bytes, so the second number since is that large, would be "124" or something like that ( don`t remember). Basically i have 2 numbers ( a number can be larger than 9999) i want to send that data via RF24L01 and receive the numbers and asign them to Int. I also tried via B4Rserializator( i dont know if this method is supported) SEND: Code: Dim obj() As Object=Array(22,8888) rf24.Write(ser.ConvertArrayToBytes(obj)) RECEIVE: Code: Sub rf24_NewData (Data() As Byte) Dim be(10) As Object Dim data() As Object = ser.ConvertBytesToArray(Data, be) If data.Length = 0 Then Return Dim nrOne As Object= data(0) Dim nrTwo As Object = data(1) Log(nrOne,NrTwo) End Sub I`m having "Out of bounds error. " I would like to know something that works even if i`m sending string or other types (HEX etc). Sorry but i`m not really good with bytes to X conversion and stuff. Thank you.
Hi. Please help me i don`t understand how this works. I`m trying to send this data for example from one arduino to another via RF24L01 with rRF24 library. SERVER: Code: Dim b() As Byte = Array As Byte(14, 5500) raf.WriteBytes(b, 0, b.Length, 0) rf24.Write(buffer) CLIENT: Code: Sub rf24_NewData (Data() As Byte) raf2.Initialize(Data, True) Dim b() As Byte = raf2.ReadBytes2(2, raf2.CurrentPosition) Dim i() As Int=bc.IntsFromBytes(b) Log(i(0),i(1)) End Sub I`m having "Out of bounds error. Array length = 1, Index = 1" If i do "Log(b(0),b(1))" then it works but i have the result in bytes, so the second number since is that large, would be "124" or something like that ( don`t remember). Basically i have 2 numbers ( a number can be larger than 9999) i want to send that data via RF24L01 and receive the numbers and asign them to Int. I also tried via B4Rserializator( i dont know if this method is supported) SEND: Code: Dim obj() As Object=Array(22,8888) rf24.Write(ser.ConvertArrayToBytes(obj)) RECEIVE: Code: Sub rf24_NewData (Data() As Byte) Dim be(10) As Object Dim data() As Object = ser.ConvertBytesToArray(Data, be) If data.Length = 0 Then Return Dim nrOne As Object= data(0) Dim nrTwo As Object = data(1) Log(nrOne,NrTwo) End Sub I`m having "Out of bounds error. " I would like to know something that works even if i`m sending string or other types (HEX etc). Sorry but i`m not really good with bytes to X conversion and stuff. Thank you.
Erel B4X founder Staff member Licensed User Longtime User Jan 25, 2018 #2 This line is wrong: Dim b() As Byte = Array As Byte(14, 5500) A byte cannot be larger than 255. Start with this code: Code: 'bc is a global ByteConverter Dim b() As Byte = bc.UIntsToBytes(Array As UInt(14, 5500)) Log(b.Length) 'should be 4 Receive: Code: Dim data() As Byte If data.Length >= 4 Then Dim numbers() As UInt = bc.UIntsFromBytes(bc.SubString2(data, 0, 4)) Else Log("Missing data") End If Upvote 0
This line is wrong: Dim b() As Byte = Array As Byte(14, 5500) A byte cannot be larger than 255. Start with this code: Code: 'bc is a global ByteConverter Dim b() As Byte = bc.UIntsToBytes(Array As UInt(14, 5500)) Log(b.Length) 'should be 4 Receive: Code: Dim data() As Byte If data.Length >= 4 Then Dim numbers() As UInt = bc.UIntsFromBytes(bc.SubString2(data, 0, 4)) Else Log("Missing data") End If
M Michael Sergio Member Licensed User Longtime User Jan 25, 2018 #3 Erel said: This line is wrong: Dim b() As Byte = Array As Byte(14, 5500) A byte cannot be larger than 255. Click to expand... Oh i tought all integer gets converted to bytes automatically.. Your solution is good for me, of course, thank you. Code: Dim b() As Byte = bc.UIntsToBytes(Array As UInt(13, 5123)) rf24.Write(b) Code: Sub rf24_NewData (Data() As Byte) If Data.Length >= 4 Then Dim numbers() As UInt = bc.UIntsFromBytes(bc.SubString2(Data, 0, 4)) Log("McNr: ",numbers(0)) Log("Counter: ",numbers(1)) Else Log("Missing data") End If End Sub Result : McNr:13,Counter:5123 Upvote 0
Erel said: This line is wrong: Dim b() As Byte = Array As Byte(14, 5500) A byte cannot be larger than 255. Click to expand... Oh i tought all integer gets converted to bytes automatically.. Your solution is good for me, of course, thank you. Code: Dim b() As Byte = bc.UIntsToBytes(Array As UInt(13, 5123)) rf24.Write(b) Code: Sub rf24_NewData (Data() As Byte) If Data.Length >= 4 Then Dim numbers() As UInt = bc.UIntsFromBytes(bc.SubString2(Data, 0, 4)) Log("McNr: ",numbers(0)) Log("Counter: ",numbers(1)) Else Log("Missing data") End If End Sub Result : McNr:13,Counter:5123