I have a B4R app that reads data from an RS232 device. I am sending the contents of the communications buffer in bytes to a B4J app using 'astream.write(buffer) in B4R.
in B4R I use this code to get the data to display a reading (data is a double)
B4X:
Sub astream_newData (Buffer() as byte)
Dim b(4) as byte
Dim bc as ByteConverter
bc.ArrayCopy2(Buffer, 2, b, 0, 4)
Dim d() as double = bc.DoubleFromBytes(b)
log("Reading = ",d(0))
End Sub
This works in B4R but not in B4J.
B4X:
Dim bc as ByteConverter
Dim s(4) As Byte
bc.ArrayCopy(Buffer,6,s,0,4)
Dim d() As Double = bc.DoublesFromBytes(s)
Log("d = "&d(0))
In B4J I get the following error - note: when the array is sent from B4R to B4J 4 extra bytes is added. All data after "0F000000" is correct so I use an offset of 6 instead of 2 in the array copy.
a = 0F000000AA103A86A73C0000000048006000FB len = 19
Error occurred on line: 72 (Main)
java.lang.ArrayIndexOutOfBoundsException: 0
at b4j.example.main._astream_newdata(main.java:142)
If I use B4RSerializator to convert the buffer how do I write it out in B4R?
B4X:
Dim ser as B4RSerializator
Dim be(15) As Object 'used as a storage buffer.
Dim objects() As Object = ser.ConvertBytesToArray(Buffer, be)
astream.Write = ????