Hi Anders,
Okay, great, thank you for the clarification.
The Garbage Collector in .NET MF 4.1 had a few limitations--which were fixed in .NET MF 4.2. This is one of the reasons it is so important that all NETMF boards are upgraded to .NET MF 4.2. Incorrectly running out of memory--in production devices deployed in the field--is not a good scenario.
Chris
Agreed!
With .NET 4.2 came changes to how analog inputs (separate from digital pins and scaling) and serial output (Write no longer returns bytes sent) work. I resolved that, yet I get InvalidOperationException instead. I'm not sure on what, as it doesn't point to a specific line in my code. Hopefully I'll find a remedy.
This is how the code looks now. adapt() is somewhat redundant as I can do scaling via AnalogInput, yet I also do border detection there.
public static bool scan(out int X, out int Y)
{
analog1 = new AnalogInput(aX2);
analog2 = new AnalogInput(aX1);
digital1 = new OutputPort(dY1, false);
digital2 = new OutputPort(dY2, true);
int valueX = (int)(analog1.Read() * range);
X = adapt(valueX);
Debug.Print("1: " + valueX);
analog1.Dispose();
analog2.Dispose();
digital1.Dispose();
digital2.Dispose();
analog1 = new AnalogInput(aY1);
analog2 = new AnalogInput(aY2);
digital1 = new OutputPort(dX2, false);
digital2 = new OutputPort(dX1, true);
int valueY = (int)(analog2.Read() * range);
Y = adapt((range - 1) - valueY);
Debug.Print("2: " + valueY);
analog1.Dispose();
analog2.Dispose();
digital1.Dispose();
digital2.Dispose();
analog1 = null;
analog2 = null;
digital1 = null;
digital2 = null;
return valueX != range - 1 && valueY != range - 1;
}