I'm having really strange results with the following. The result of an Infrared Receive contains a ULONG array of numbers. Along with that is the number of elements. I'm basically attempting to perform some simple math on each of the elements then copy that result to an object array. Ultimatley it's going to be seralized and sent over the network.
My code is something like this:
I'm doing it this way as I understand it, in order to serialize and send (my stream is in prefixmode) I can only serialize an array of objects and not the array of ulongs directly. hence I copy to a fixed array of objects (in this example max elements = 100). The print line in the loop:
It doesn't seem to match up. I don't understand how it seems correct initially and w/o any modification outside the first loop it's off. Some seem correct others are not. Whatever is displayed in the second loop gets sent over the network and received in my B4J test program.
Now if I send the following fixed array of objects:
I have no issues and it's received properly. Also I should mentioned, in the beginning of my code block I have to initialize the array of objects - if I don't I get total garbarge on the receiving end and it actually crashes.
What am I missing here with my type conversion and setup of my array of objects?
My code is something like this:
B4X:
Private USECPERTICK As ULong
Private MARK_EXCESS As ULong
USECPERTICK = 50
MARK_EXCESS = 100
Dim code_array(100) As Object
'init array of objects
For i = 0 To 99
code_array(i) = 0
Next
i = 0
code_array(0) = Result.RawBuffer.Length 'storing length of IR codes in first element
Dim code As ULong = 0
'For Each code As ULong In Result.RawBuffer
For i = 0 To Result.RawBuffer.Length - 1
If ((i Mod 2) = 0) Then 'even
'Space
code_array(i+1) = (Result.RawBuffer(i) * USECPERTICK) + MARK_EXCESS
'Log("space newcode: ", newcode)
Else 'odd
'Mark
code_array(i+1) = (Result.RawBuffer(i) * USECPERTICK) - MARK_EXCESS
'Log("mark newcode: ", newcode)
End If
'newcode = 4500
'code_array(i) = newcode
Log("First print: ", code_array(i+1))
Next
ir_recv.Disable
Log("Received raw code. Infrared Disabled.")
For i = 0 To 99
Log("Second print: ", code_array(i))
Next
I'm doing it this way as I understand it, in order to serialize and send (my stream is in prefixmode) I can only serialize an array of objects and not the array of ulongs directly. hence I copy to a fixed array of objects (in this example max elements = 100). The print line in the loop:
Appears to print the correct result. After I've looped through everything and I loop through again in the second loop here:Log("First print: ", code_array(i+1))
B4X:
For i = 0 To 99
Log("Second print: ", code_array(i))
Next
It doesn't seem to match up. I don't understand how it seems correct initially and w/o any modification outside the first loop it's off. Some seem correct others are not. Whatever is displayed in the second loop gets sent over the network and received in my B4J test program.
Now if I send the following fixed array of objects:
B4X:
dim my_array2() As Object = Array As Object(4450,4600,500,1800,500,1800,500,1800,500,700,500,700,500,700,500,700,500,650,550,1800,500,1800,500,1800,500,700,500,700,500,700,500,700,500,700,500,1800,500,1800,500,700,500)
I have no issues and it's received properly. Also I should mentioned, in the beginning of my code block I have to initialize the array of objects - if I don't I get total garbarge on the receiving end and it actually crashes.
What am I missing here with my type conversion and setup of my array of objects?
Last edited: