Reply To: Only SensorPort.In1 works? (solved)

HomeForumsMonoBrick EV3 FirmwareOnly SensorPort.In1 works? (solved)Reply To: Only SensorPort.In1 works? (solved)

#3911
Author Image
Rich Champeaux
Participant

I think I found the problem. I don’t really know the code, so I’m just tracing through and looking at how the Port number is used, but…

UARTSensor.InitUart() goes into a loop where it calls ClearPortChanged(), waits, and then reads the status and checks the status for the UartPortChanged bit.

GetStatus() is implemented as such:
private byte GetStatus()
{
return uartMemory.Read(UartStatusOffset, NumberOfSenosrPorts)[(int)port];
}

And basically reads the status byte from memory location “UartStatusOffset+port”

However, ClearPortChanged() has a bug I think. Its implemented as:
private void ClearPortChanged()
{
SensorManager.Instance.ClearUartPortChanged(this.port);
uartMemory.Write (UartStatusOffset, new byte[] { (byte)(uartMemory.Read ((int)port, 1) [0] & ~UartPortChanged) });
this.uartMode = UARTMode.Mode0;
}

The uartMemory.Write() call doesn’t look right. It reads one byte from memory location “port” (not “UartStatusOffset+port”, just “port”), clears the UartPortChanged bit in the byte, and then writes it to memory location “UartStatusOffset” (not “UartStatusOffset+port”)

So the first problem that I see, is that it is always writing one byte to memory location “UartStatusOffset” regardless of the port number (which means it always writes to the port 1 location). The second possible problem is that the value it reads before clearing the bit is from memory location “port”, not “UartStatusOffset+port” that it’s supposed to be writing to and that it reads from in GetStatus().

I hope this helps. I’m going to try it myself tonight.

Posted in

Make a donation