Originally Posted by 2k1Toaster
this is the whole function that that handles send/receive. It runs in a .net timer every 2000ms.
i could set it at a higher interval but i didnt think it was needed because RR only updates the data once per second.
Public Shared Function FB_SendReceive()
For i = 0 To 11
OutputArray(i) = Convert.ToByte(0 & KeepAliveBit & DigOut(i))
'MsgBox("Output array made")
'MsgBox("data sent to fb")
'Now, get the info from the fusion brain
If (FUSB_Receive(pFusionUSB, InputArray)) Then
'It retured true, meaning it got data. Process it.
For i = 0 To 9
'The data coming in from the analog inputs is 10 bits long, so it has to come in two bytes.
'The first byte contains 8 bits, which are the most significant bits.
'The second byte contains only 2 bits, and they are the least significant bits. Personally, I ignore those two.
'AnalogIn(i) = CInt(InputArray(i * 2 + 12)) 'Uses only the first byte 0-255 (8 bits)
'Range of 0-255, so divide by 255 to get a percent, then multiply by 5 to get volts.
'AnalogIn(i) = (totalin / 255) * 5
AnalogIn(i) = (CInt(InputArray(i * 2 + 12)) * 4) + CInt(InputArray(i * 2 + 13) / 64) 'Uses both bytes 0-1023 (10 bits)
'Range of 0-1023, so divide by 1023 to get a percent, then multiply by 5 if you want to get volts.
'AnalogIn(i) = (totalin / 1023) * 5
'Toggle the keepalive bit for nexttime.
If KeepAliveBit = 0 Then
KeepAliveBit = 1
KeepAliveBit = 0