I have to following function
public int[] PollAllDevices()
{
/* Polling commands */
const byte POLL_FRONT_RADAR = 0x00;
const byte POLL_REAR_RADAR = 0x01;
const byte POLL_DISP = 0x02;
const byte POLL_CTRL = 0x03;
const byte POLL_EXP1 = 0x04;
const byte POLL_EXP2 = 0x05;
byte[] buff = new byte[32];
int[] _ret = new int[32];// { 23, 24, 25, 26, 27, 28, 29, 30 };
int i = 0;
if(API.uart_write(devPtr, new byte[1] { POLL_FRONT_RADAR }, 0, 1))
{
if (API.uart_read(devPtr, buff, 0, 1, 1000) != 0)
{
_ret[i++] = (int)buff[1];
}
}
if (API.uart_write(devPtr, new byte[1] { POLL_REAR_RADAR }, 0, 1))
{
if (API.uart_read(devPtr, buff, 0, 1, 1000) != 0)
{
_ret[i++] = (int)buff[1];
}
}
return _ret;
}
I have _ret in the watch window. I can see it exists up until the point I call API.uart_read and then it turns grey in the watch window and I see
_ret Cannot obtain value of local or argument '_ret' as it is not available at this instruction pointer, possibly because it has been optimized away. int[]
(Just throwing that in there as extra information. It's not my question so I'm not sure why this was marked as a duplicate. All the solutions to that error seem to revolve around optimization and I don't have optimization turned on.)
When I try to write to it I get an array out of bounds exception. i=0 at that point but just for grins I have hardcoded it to _ret[0] and I still get the exception. If I change _ret to an int I can write to it again.
I have optimization turned off. Can anyone tell me what I am doing wrong here?