@ Gene, Real unit testing would have an emulator running the netmf device + data that will mimic the functions of µC in the real envrionment. What you can do instead is to test your functions! C# has the [em]partial[/em] class declaration. Visual studio allow allows you to link existing c# files from one project into another. What this means is that you can write a class for NETMF but still create unit tests that verify your code.
E.g. Let’s say we wanted to call SPI.WriteRead. Well there is no Microsoft.SPOT.Hardware.SPI.WriteRead in Big DOT Net Framework, you can stub one out in a unit test. then based on what you call the method with; your test will respond accordingly. Then when you compile the MF code for the device, you can expect the same result that you did in the test.
#region Assembly Microsoft.SPOT.Hardware.dll, v4.3.1.0
// C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Assemblies\le\Microsoft.SPOT.Hardware.dll
#endregion
using System;
namespace Microsoft.SPOT.Hardware {
public sealed class SPI : IDisposable {
public SPI(SPI.Configuration config);
public SPI.Configuration Config { get; set; }
public void Dispose();
public void Write(byte[] writeBuffer);
public void Write(ushort[] writeBuffer);
public void WriteRead(byte[] writeBuffer, byte[] readBuffer); //implement method and do test logic
public void WriteRead(ushort[] writeBuffer, ushort[] readBuffer);
public void WriteRead(byte[] writeBuffer, byte[] readBuffer, int startReadOffset);
public void WriteRead(ushort[] writeBuffer, ushort[] readBuffer, int startReadOffset);
public void WriteRead(byte[] writeBuffer, int writeOffset, int writeCount, byte[] readBuffer, int readOffset, int readCount, int startReadOffset);
public void WriteRead(ushort[] writeBuffer, int writeOffset, int writeCount, ushort[] readBuffer, int readOffset, int readCount, int startReadOffset);
public enum SPI_module {
SPI1 = 0,
SPI2 = 1,
SPI3 = 2,
SPI4 = 3,
}
public class Configuration {
public readonly Cpu.Pin BusyPin;
public readonly bool BusyPin_ActiveState;
public readonly bool ChipSelect_ActiveState;
public readonly uint ChipSelect_HoldTime;
public readonly Cpu.Pin ChipSelect_Port;
public readonly uint ChipSelect_SetupTime;
public readonly bool Clock_Edge;
public readonly bool Clock_IdleState;
public readonly uint Clock_RateKHz;
public readonly SPI.SPI_module SPI_mod;
public Configuration(Cpu.Pin ChipSelect_Port, bool ChipSelect_ActiveState, uint ChipSelect_SetupTime, uint ChipSelect_HoldTime, bool Clock_IdleState, bool Clock_Edge, uint Clock_RateKHz, SPI.SPI_module SPI_mod);
public Configuration(Cpu.Pin ChipSelect_Port, bool ChipSelect_ActiveState, uint ChipSelect_SetupTime, uint ChipSelect_HoldTime, bool Clock_IdleState, bool Clock_Edge, uint Clock_RateKHz, SPI.SPI_module SPI_mod, Cpu.Pin BusyPin, bool BusyPin_ActiveState);
}
}
}
Method under UNIT test
public static void Initilize() {
dSpinConfig = new SPI.Configuration((Cpu.Pin)FEZCerbuino.Pin.Gadgeteer.Socket1.Pin4,
false, // Chip Select, active-low
0, // millisecond setup time
0, // millisecond hold time
true, // Clock low on idle
true, // Data valid on rising edge
5000, // 5000Khz
SPI.SPI_module.SPI1);
spiPort = new SPI(dSpinConfig);
while (true) {
byte[] _out = new byte[] { (byte)DateTime.Now.Millisecond, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 };
byte[] _in = new byte[_out.Length];
spiPort.WriteRead(_out, _in);
bool _isGood = false;
for (int i = 0; i < _in.Length; i++) {
if (_out[0] == _in[i]) {
_isGood = true;
break;
}
}
if (_isGood) {
Debug.Print("dSPIN SPI Communication is good.");
break; //TODO: Remove break if testing needed
}
else {
Debug.Print("ERROR: Value not found in input array.");
}
Thread.Sleep(1000);
}
}